os: avoid potential out-of-bounds access at logVHdrMessageVerb

The LogVHdrMessageVerb function may access an array out of bounds in a
specific edge case. Specifically, the line:

newline = (buf[len - 1] == '\n');

can result in accessing buf[-1] if len == 0, which is undefined behavior.

Commit adds check to avoid access out of bounds at pointed line.

Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1841
Signed-off-by: Mikhail Dmitrichenko <m.dmitrichenko222@gmail.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2061>
This commit is contained in:
Mikhail Dmitrichenko 2025-09-17 17:29:49 +03:00 committed by Marge Bot
parent b096785df4
commit 8d25a89143

View file

@ -801,7 +801,7 @@ LogVHdrMessageVerb(MessageType type, int verb, const char *msg_format,
if (size - len == 1)
buf[len - 1] = '\n';
newline = (buf[len - 1] == '\n');
newline = (len > 0 && buf[len - 1] == '\n');
LogSWrite(verb, buf, len, newline);
}