An smbios object with no variable part is a special case, it's just
suffixed with two NUL btes. handle that properly.
This is inspired by a similar fix from https://github.com/systemd/systemd/pull/29726
size -= header->length;
p += header->length;
- /* Skip over string table. */
+ /* Special case: if there are no strings appended, we'll see two NUL bytes, skip over them */
+ if (size >= 2 && p[0] == 0 && p[1] == 0) {
+ size -= 2;
+ p += 2;
+ continue;
+ }
+
+ /* Skip over a populated string table. */
+ bool first = true;
for (;;) {
const uint8_t *e = memchr(p, 0, size);
if (!e)
return NULL;
- if (e == p) {/* Double NUL byte means we've reached the end of the string table. */
+ if (!first && e == p) {/* Double NUL byte means we've reached the end of the string table. */
p++;
size--;
break;
size -= e + 1 - p;
p = e + 1;
+ first = false;
}
}