This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Fix undefined behavior when generating error message at rename with an invalid name
ClosedPublic

Authored by ArcsinX on Dec 17 2021, 11:38 AM.

Details

Summary

Message() lambda uses Reason.Details as an input parameter for llvm::formatv(), but Reason in Message() is a local object.
Return value of llvm::formatv() contains references to its input arguments, thus Message() returns an object which contains a reference to Details field of the local object Reason.
This patch fixes this behavior by passing Reason as a reference to Message() to ensure that return value of Message() contains references to alive object and also prevents copying of InvalidName structure at passing it to makeError().

Provided test passes on Linux+GCC with or without this patch, but fails on Windows+VisualStudio without this patch.

Diff Detail

Event Timeline

ArcsinX created this revision.Dec 17 2021, 11:38 AM
ArcsinX requested review of this revision.Dec 17 2021, 11:38 AM
sammccall accepted this revision.Dec 19 2021, 5:11 AM

Yikes, thank you!

This revision is now accepted and ready to land.Dec 19 2021, 5:11 AM