Fix segfault while patching dtb

This commit is contained in:
topjohnwu 2017-12-31 19:30:56 +08:00
parent d8bb3af06b
commit 2f79d0c3b3
2 changed files with 15 additions and 4 deletions

View File

@ -78,8 +78,17 @@ static void dtb_patch(const char *file, int patch) {
fdt_for_each_subnode(block, fdt, fstab) {
fprintf(stderr, "Found block [%s] in fstab\n", fdt_get_name(fdt, block, NULL));
uint32_t value_size;
void *value = (char *) fdt_getprop(fdt, block, "fsmgr_flags", &value_size);
found |= patch_verity(&value, &value_size, patch);
void *value = (void *) fdt_getprop(fdt, block, "fsmgr_flags", &value_size);
if (patch) {
void *dup = xmalloc(value_size);
memcpy(dup, value, value_size);
memset(value, 0, value_size);
found |= patch_verity(&dup, &value_size, 1);
memcpy(value, dup, value_size);
free(dup);
} else {
found |= patch_verity(&value, &value_size, 0);
}
}
}
}

View File

@ -72,8 +72,10 @@ int patch_verity(void **buf, uint32_t *size, int patch) {
if (patch)
patched[write] = src[read];
}
free(*buf);
*buf = patched;
if (patch) {
free(*buf);
*buf = patched;
}
return 0;
}