This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Remove lldbassert from CommandInterpreter::PrintCommandOutput
ClosedPublic

Authored by JDevlieghere on Mar 18 2022, 11:56 AM.

Details

Summary

The assertion checks that the command output doesn't contain any null
bytes. I'm not sure if the intention was to make sure the string wasn't
shorter than the reported length or if this was a way to catch us
accidentally writing an (unformatted) null byte.

Regardless, the command output can be based on user input, so an
assertion doesn't make sense. For example, you should be totally allowed
to call print("\0") from Python. The latter doesn't trigger this bug
because it writes directly to the output stream and therefore bypasses
PrintCommandOutput but that's just an implementation detail.

Diff Detail

Event Timeline

JDevlieghere created this revision.Mar 18 2022, 11:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 18 2022, 11:56 AM
JDevlieghere requested review of this revision.Mar 18 2022, 11:56 AM

I think it makes sense to require that the CommandResultObject's command output is UTF-8 string with no embedded '\0'-s. We wouldn't do smart things with rendering command output with nulls in it, and I don't see any reason to support such a thing.

OTOH, this seems like the wrong place to check that, since it's pretty far removed from whoever would have added the null's. If we wanted to do this right, we would sanitize when you write to the CommandResultObject.

labath accepted this revision.Mar 22 2022, 3:00 AM

Agreed we generally don't want to have embedded nuls in the command output, but I don't think we have to go to such great lengths to enforce it.

The latter doesn't trigger this bug because it writes directly to the output stream and therefore bypasses PrintCommandOutput but that's just an implementation detail.

I guess this would be triggered by sb_command_return_object.PutOutput("\0")

lldb/source/Interpreter/CommandInterpreter.cpp
2986–2989

I guess this could now be something like std::tie(line, str) = str.split('\n');

This revision is now accepted and ready to land.Mar 22 2022, 3:00 AM

Use StringRef::split

Herald added a project: Restricted Project. · View Herald TranscriptMar 23 2022, 4:20 PM