fw_cfg: prohibit insertion of duplicate fw_cfg file names
Exit with an error (instead of simply logging a trace event) whenever the same fw_cfg file name is added multiple times via one of the fw_cfg_add_file[_callback]() host-side API calls. Signed-off-by: Gabriel Somlo <somlo@cmu.edu> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
0f9b214139
commit
0eb973f915
@ -515,18 +515,19 @@ void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
|
|||||||
index = be32_to_cpu(s->files->count);
|
index = be32_to_cpu(s->files->count);
|
||||||
assert(index < FW_CFG_FILE_SLOTS);
|
assert(index < FW_CFG_FILE_SLOTS);
|
||||||
|
|
||||||
fw_cfg_add_bytes_read_callback(s, FW_CFG_FILE_FIRST + index,
|
|
||||||
callback, callback_opaque, data, len);
|
|
||||||
|
|
||||||
pstrcpy(s->files->f[index].name, sizeof(s->files->f[index].name),
|
pstrcpy(s->files->f[index].name, sizeof(s->files->f[index].name),
|
||||||
filename);
|
filename);
|
||||||
for (i = 0; i < index; i++) {
|
for (i = 0; i < index; i++) {
|
||||||
if (strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {
|
if (strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {
|
||||||
trace_fw_cfg_add_file_dupe(s, s->files->f[index].name);
|
error_report("duplicate fw_cfg file name: %s",
|
||||||
return;
|
s->files->f[index].name);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fw_cfg_add_bytes_read_callback(s, FW_CFG_FILE_FIRST + index,
|
||||||
|
callback, callback_opaque, data, len);
|
||||||
|
|
||||||
s->files->f[index].size = cpu_to_be32(len);
|
s->files->f[index].size = cpu_to_be32(len);
|
||||||
s->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);
|
s->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);
|
||||||
trace_fw_cfg_add_file(s, index, s->files->f[index].name, len);
|
trace_fw_cfg_add_file(s, index, s->files->f[index].name, len);
|
||||||
|
@ -195,7 +195,6 @@ ecc_diag_mem_readb(uint64_t addr, uint32_t ret) "Read diagnostic %"PRId64"= %02x
|
|||||||
# hw/nvram/fw_cfg.c
|
# hw/nvram/fw_cfg.c
|
||||||
fw_cfg_select(void *s, uint16_t key, int ret) "%p key %d = %d"
|
fw_cfg_select(void *s, uint16_t key, int ret) "%p key %d = %d"
|
||||||
fw_cfg_read(void *s, uint8_t ret) "%p = %d"
|
fw_cfg_read(void *s, uint8_t ret) "%p = %d"
|
||||||
fw_cfg_add_file_dupe(void *s, char *name) "%p %s"
|
|
||||||
fw_cfg_add_file(void *s, int index, char *name, size_t len) "%p #%d: %s (%zd bytes)"
|
fw_cfg_add_file(void *s, int index, char *name, size_t len) "%p #%d: %s (%zd bytes)"
|
||||||
|
|
||||||
# hw/block/hd-geometry.c
|
# hw/block/hd-geometry.c
|
||||||
|
Loading…
Reference in New Issue
Block a user