hw: fw_cfg: ensure reboot_time is nonegative
PATCH 1/2 hw: fw_cfg: ensure reboot_time is nonegative
This can avoid setting a negative value to
etc/boot-fail-wait.
--- hw/nvram/fw_cfg.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
hw/nvram/fw_cfg.c +10 -5
@@ -199,12 +199,17 @@ static void fw_cfg_reboot(FWCfgState *s) reboot_timeout =strtol (p, &p,10 ); } } -/* validate the input */ -if (reboot_timeout >0xffff ) { -error_report ("reboot timeout is larger than 65535, force it to 65535." ); - reboot_timeout =0xffff ; + +if (reboot_timeout >=0 ) { +/* validate the input */ +if (reboot_timeout >0xffff ) { +error_report ("reboot timeout is larger than 65535," +"force it to 65535." ); + reboot_timeout =0xffff ; + } +fw_cfg_add_file (s,"etc/boot-fail-wait" , +g_memdup (&reboot_timeout,4 ),4 ); } -fw_cfg_add_file (s,"etc/boot-fail-wait" ,g_memdup (&reboot_timeout,4 ),4 ); }static void fw_cfg_write (FWCfgState *s,uint8_t value)
Signature · 1 line
1.8.3.1
Quoted 5 lines
hw/nvram/fw_cfg.c +1
-4-/* validate the input */ -if (reboot_timeout >0xffff ) { -error_report ("reboot timeout is larger than 65535, force it to 65535." ); - reboot_timeout =0xffff ; +
hw/nvram/fw_cfg.c static void fw_cfg_reboot(FWCfgState *s) · line 212
Quoted 10 lines
hw/nvram/fw_cfg.c +9
-0+if (reboot_timeout >=0 ) { +/* validate the input */ +if (reboot_timeout >0xffff ) { +error_report ("reboot timeout is larger than 65535," +"force it to 65535." ); + reboot_timeout =0xffff ; + } +fw_cfg_add_file (s,"etc/boot-fail-wait" , +g_memdup (&reboot_timeout,4 ),4 ); }
Hmm, values > 0xffff are reported and values < 0 are silently ignored. I think we should be consistent here.
I'd suggest report and exit in both cases,
i.e. use error_setg(..., &error_fatal);
cheers,
Gerd
Quoted 16 lines · Gerd Hoffmann
Quoted 5 lines
hw/nvram/fw_cfg.c +1
-4-/* validate the input */ -if (reboot_timeout >0xffff ) { -error_report ("reboot timeout is larger than 65535, force it to 65535." ); - reboot_timeout =0xffff ; +hw/nvram/fw_cfg.c static void fw_cfg_reboot(FWCfgState *s) · line 212
Quoted 10 lines
hw/nvram/fw_cfg.c +9
-0+if (reboot_timeout >=0 ) { +/* validate the input */ +if (reboot_timeout >0xffff ) { +error_report ("reboot timeout is larger than 65535," +"force it to 65535." ); + reboot_timeout =0xffff ; + } +fw_cfg_add_file (s,"etc/boot-fail-wait" , +g_memdup (&reboot_timeout,4 ),4 ); }
Quoted 3 lines
Hmm, values >
0xffffare reported and values < 0 are silently ignored. I think we should be consistent here.
I'd suggest report and exit in both cases,
Agreed. If the user specifies a value outside acceptable limits, rejecting it is simpler than "correcting" it. "Corrections" may look convenient, but they're not worth the additional interface complexity.
Quoted 1 line
i.e. use
error_setg(..., &error_fatal);
In case you mean something like
error_setg(&error_fatal, "reboot timeout is larger than 65535");
I'd like to point to error.h:
* Please don't error_setg(&error_fatal, ...), use error_report() and
* exit(), because that's more obvious.