Skip to content

Commit 27f6c28

Browse files
poetteringbluca
authored andcommitted
vmm: make sure we can handle smbios objects without variable part
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 systemd/systemd#29726 (cherry picked from commit 44ec704) (cherry picked from commit 9a2f16e) (cherry picked from commit 4c5c7c6)
1 parent 8b79504 commit 27f6c28

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/boot/efi/vmm.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -241,20 +241,29 @@ static const SmbiosHeader *get_smbios_table(uint8_t type, uint64_t *ret_size_lef
241241
size -= header->length;
242242
p += header->length;
243243

244-
/* Skip over string table. */
244+
/* Special case: if there are no strings appended, we'll see two NUL bytes, skip over them */
245+
if (size >= 2 && p[0] == 0 && p[1] == 0) {
246+
size -= 2;
247+
p += 2;
248+
continue;
249+
}
250+
251+
/* Skip over a populated string table. */
252+
bool first = true;
245253
for (;;) {
246254
const uint8_t *e = memchr(p, 0, size);
247255
if (!e)
248256
return NULL;
249257

250-
if (e == p) {/* Double NUL byte means we've reached the end of the string table. */
258+
if (!first && e == p) {/* Double NUL byte means we've reached the end of the string table. */
251259
p++;
252260
size--;
253261
break;
254262
}
255263

256264
size -= e + 1 - p;
257265
p = e + 1;
266+
first = false;
258267
}
259268
}
260269

0 commit comments

Comments
 (0)