Skip to content

Commit 8819dc2

Browse files
committed
libfwup: set_up_boot_next(): make sure we check if our file paths are NULL.
Coverity's clang scan believes we can sometimes alloca(0) if fwup_esp_path is NULL, though I don't think this can happen because if it is NULL get_paths() should have returned error. Nevertheless, just check both things. Additionally, this adds a check to make sure utf8_to_ucs2() and ucs2len() didn't fail. Signed-off-by: Peter Jones <pjones@redhat.com>
1 parent 3ce2065 commit 8819dc2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

linux/libfwup.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,9 +1215,9 @@ set_up_boot_next(void)
12151215
uint32_t attributes = LOAD_OPTION_ACTIVE;
12161216

12171217
rc = get_paths(&shim_fs_path, &fwup_fs_path, &fwup_esp_path);
1218-
if (rc < 0) {
1218+
if (rc < 0 || (!shim_fs_path && (!fwup_fs_path || !fwup_esp_path))) {
12191219
efi_error("could not find paths for shim and fwup");
1220-
return -1;
1220+
goto out;
12211221
}
12221222

12231223
if (!shim_fs_path)
@@ -1242,9 +1242,17 @@ set_up_boot_next(void)
12421242

12431243
if (!use_fwup_path) {
12441244
loader_str = utf8_to_ucs2((uint8_t *)fwup_esp_path, -1);
1245+
if (loader_str == NULL) {
1246+
efi_error("utf8_to_ucs2() failed");
1247+
goto out;
1248+
}
12451249
loader_sz = ucs2len(loader_str, -1) * 2;
1246-
if (loader_sz)
1247-
loader_sz += 2;
1250+
if (loader_sz < 2) {
1251+
efi_error("ucs2len(fwup_esp_path) returned %zu",
1252+
loader_sz);
1253+
goto out;
1254+
}
1255+
loader_sz += 2;
12481256
loader_str = onstack(loader_str, loader_sz);
12491257
}
12501258

0 commit comments

Comments
 (0)