* [Qemu-devel] [PATCH 1/2] hw: fw_cfg: ensure reboot_time is nonegative
@ 2018-11-01 6:09 Li Qiang
2018-11-05 8:26 ` Gerd Hoffmann
0 siblings, 1 reply; 3+ messages in thread
From: Li Qiang @ 2018-11-01 6:09 UTC (permalink / raw)
To: pbonzini, armbru, philmd, lersek, kraxel; +Cc: qemu-devel, Li Qiang
This can avoid setting a negative value to
etc/boot-fail-wait.
Signed-off-by: Li Qiang <liq3ea@gmail.com>
---
hw/nvram/fw_cfg.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 3fcfa35..dff6e06 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -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)
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH 1/2] hw: fw_cfg: ensure reboot_time is nonegative
2018-11-01 6:09 [Qemu-devel] [PATCH 1/2] hw: fw_cfg: ensure reboot_time is nonegative Li Qiang
@ 2018-11-05 8:26 ` Gerd Hoffmann
2018-11-05 15:50 ` Markus Armbruster
0 siblings, 1 reply; 3+ messages in thread
From: Gerd Hoffmann @ 2018-11-05 8:26 UTC (permalink / raw)
To: Li Qiang; +Cc: pbonzini, armbru, philmd, lersek, qemu-devel
> - /* 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);
> }
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH 1/2] hw: fw_cfg: ensure reboot_time is nonegative
2018-11-05 8:26 ` Gerd Hoffmann
@ 2018-11-05 15:50 ` Markus Armbruster
0 siblings, 0 replies; 3+ messages in thread
From: Markus Armbruster @ 2018-11-05 15:50 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: Li Qiang, qemu-devel, pbonzini, philmd, lersek
Gerd Hoffmann <kraxel@redhat.com> writes:
>> - /* 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);
>> }
>
> 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,
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.
> 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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-11-05 15:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-01 6:09 [Qemu-devel] [PATCH 1/2] hw: fw_cfg: ensure reboot_time is nonegative Li Qiang
2018-11-05 8:26 ` Gerd Hoffmann
2018-11-05 15:50 ` Markus Armbruster
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.