util/qemu-option: Document the get_opt_value() function
PATCH 1/1 util/qemu-option: Document the get_opt_value() function
Coverity noticed commit 950c4e6c94 introduced a dereference before null check in get_opt_value (CID1391003):
In get_opt_value: All paths that lead to this null pointer comparison already dereference the pointer earlier (CWE-476)
We fixed this in commit 6e3ad3f0e31, but relaxed the check in commit 0c2f6e7ee99 because "No callers of get_opt_value() pass in a NULL for the 'value' parameter".
Since this function is publicly exposed, it risks new users to do the same error again. Avoid that documenting the 'value' argument must not be NULL.
--- include/qemu/option.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/qemu/option.h +12 -0
@@ -28,6 +28,18 @@#include "qemu/queue.h" +/** +* get_opt_value +* @p: a pointer to the option name, delimited by commas +* @value: a non-NULL pointer that will received the delimited options +* +* The @value char pointer will be allocated and filled with +* the delimited options. +* It is an error to pass a non-NULL @value parameter. +* +* Returns the position of the comma delimiter/zero byte after the +* option name in @p. +*/ const char *get_opt_value (const char *p,char **value); void parse_option_size(const char *name, const char *value,
Signature · 1 line
2.20.1
Hi Philippe,
Quoted 25 lines · Philippe Mathieu-Daudé
Coverity noticed commit
950c4e6c94introduced a dereference before null check inget_opt_value(CID1391003):In
get_opt_value: All paths that lead to this null pointer comparison already dereference the pointer earlier (CWE-476)We fixed this in commit
6e3ad3f0e31, but relaxed the check in commit0c2f6e7ee99because "No callers ofget_opt_value()pass in a NULL for the 'value' parameter".Since this function is publicly exposed, it risks new users to do the same error again. Avoid that documenting the 'value' argument must not be NULL.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/qemu/option.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)include/qemu/option.h +0
-0@@ -28,6 +28,18 @@
include/qemu/option.h line 38
Quoted 10 lines
include/qemu/option.h +8
-0#include "qemu/queue.h" +/** +* get_opt_value +* @p: a pointer to the option name, delimited by commas +* @value: a non-NULL pointer that will received the delimited options +* +* The @value char pointer will be allocated and filled with +* the delimited options. +* It is an error to pass a non-NULL @value parameter.
You mean "a NULL @value" I suppose (not a non-NULL).
include/qemu/option.h line 45
Quoted 8 lines
include/qemu/option.h +4
-0+* +* Returns the position of the comma delimiter/zero byte after the +* option name in @p. +*/ const char *get_opt_value (const char *p,char **value); void parse_option_size(const char *name, const char *value,
--
Damien
Quoted 30 lines · Damien Hedde
Hi Philippe,
Quoted 27 lines · Philippe Mathieu-Daudé
Coverity noticed commit
950c4e6c94introduced a dereference before null check inget_opt_value(CID1391003):In
get_opt_value: All paths that lead to this null pointer comparison already dereference the pointer earlier (CWE-476)We fixed this in commit
6e3ad3f0e31, but relaxed the check in commit0c2f6e7ee99because "No callers ofget_opt_value()pass in a NULL for the 'value' parameter".Since this function is publicly exposed, it risks new users to do the same error again. Avoid that documenting the 'value' argument must not be NULL.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/qemu/option.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)include/qemu/option.h +0
-0@@ -28,6 +28,18 @@#include "qemu/queue.h"
Quoted 10 lines
include/qemu/option.h line 38
Quoted 8 lines
include/qemu/option.h +8
-0+/** +* get_opt_value +* @p: a pointer to the option name, delimited by commas +* @value: a non-NULL pointer that will received the delimited options +* +* The @value char pointer will be allocated and filled with +* the delimited options. +* It is an error to pass a non-NULL @value parameter. You mean "a NULL @value" I suppose (not a non-NULL).
Oops... Thanks :)
Quoted 12 lines
include/qemu/option.h line 45
Quoted 8 lines
include/qemu/option.h +4
-0+* +* Returns the position of the comma delimiter/zero byte after the +* option name in @p. +*/ const char *get_opt_value (const char *p,char **value); void parse_option_size(const char *name, const char *value,--
Damien