Fixing boolean value output for Netlink reported values in JSON format
Subsystems (2)
PATCH 1/1 Fixing boolean value output for Netlink reported values in JSON format
Current implementation of show_bool_val() passes "val" parameter of pointer type as a last parameter to print_bool():
https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/tree/netlink/netlink.h#n131
...
static inline void show_bool_val(const char *key, const char *fmt, uint8_t *val)
{
if (is_json_context()) {
if (val)Quoted 1 line
print_bool(PRINT_JSON, key, NULL, val);
} else {...print_bool() expects the last parameter to be bool:
https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/tree/json_print.c#n153
...
void print_bool(enum output_type type,
const char *key,
const char *fmt,
bool value)
{
...
Current show_bool_val() implementation converts "val" pointer to bool while calling show_bool_val(). As a result show_bool_val() always prints the value as "true" as long as it gets a non-null pointer to the boolean value, even if the referred boolean value is false.
--- netlink/netlink.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
netlink/netlink.h +1 -1
@@ -128,7 +128,7 @@ static inline void show_bool_val(const char *key, const char *fmt, uint8_t *val) {if (is_json_context ()) {if (val) -print_bool (PRINT_JSON , key,NULL , val); +print_bool (PRINT_JSON , key,NULL , *val); }else {print_string (PRINT_FP ,NULL , fmt,u8_to_bool (val)); }
Signature · 1 line
2.38.1
Quoted 25 lines · Maxim Georgiev
Current implementation of
show_bool_val()passes "val" parameter of pointer type as a last parameter toprint_bool():
https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/tree/netlink/netlink.h#n131
...
static inline voidshow_bool_val(const char *key, const char *fmt, uint8_t *val){ if (is_json_context()) { if (val)Quoted 1 line
print_bool(PRINT_JSON, key, NULL, val);} else {...
print_bool()expects the last parameter to be bool:
https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/tree/json_print.c#n153
...
void print_bool(enumoutput_typetype,
const char *key,
const char *fmt,
bool value)
{
...
Currentshow_bool_val()implementation converts "val" pointer to bool while callingshow_bool_val(). As a resultshow_bool_val()always prints the value as "true" as long as it gets a non-null pointer to the boolean value, even if the referred boolean value is false.
Quoted 2 lines
Fixes 7e5c1ddbe67d ("pause: add --json support")Signed-off-by Maxim Georgiev <[email protected]>
I'm assuming that val is never NULL :)
Quoted 20 lines
--- netlink/netlink.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)netlink/netlink.h +1
-1@@ -128,7 +128,7 @@ static inline void show_bool_val(const char *key, const char *fmt, uint8_t *val) {if (is_json_context ()) {if (val) -print_bool (PRINT_JSON , key,NULL , val); +print_bool (PRINT_JSON , key,NULL , *val); }else {print_string (PRINT_FP ,NULL , fmt,u8_to_bool (val)); }Signature · 1 line
2.38.1
Quoted 27 lines · Simon Horman
Quoted 25 lines · Maxim Georgiev
Current implementation of
show_bool_val()passes "val" parameter of pointer type as a last parameter toprint_bool():
https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/tree/netlink/netlink.h#n131
...
static inline voidshow_bool_val(const char *key, const char *fmt, uint8_t *val){ if (is_json_context()) { if (val)Quoted 1 line
print_bool(PRINT_JSON, key, NULL, val);} else {...
print_bool()expects the last parameter to be bool:
https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/tree/json_print.c#n153
...
void print_bool(enumoutput_typetype,
const char *key,
const char *fmt,
bool value)
{
...
Currentshow_bool_val()implementation converts "val" pointer to bool while callingshow_bool_val(). As a resultshow_bool_val()always prints the value as "true" as long as it gets a non-null pointer to the boolean value, even if the referred boolean value is false.
Quoted 6 lines
Quoted 2 lines
Fixes 7e5c1ddbe67d ("pause: add --json support")Signed-off-by Maxim Georgiev <[email protected]>Reviewed-by Simon Horman <[email protected]>I'm assuming that val is never NULL :)
Simon, thank you for taking a look!
Yes, the "if (val)" check on line 130 guarantees that "print_bool()" on line 131 is called only if val is not null.
Quoted 21 lines
Quoted 21 lines
--- netlink/netlink.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)netlink/netlink.h +1
-2@@ -128,7 +128,7 @@ static inline void show_bool_val(const char *key, const char *fmt, uint8_t *val) {if (is_json_context ()) {if (val) -print_bool (PRINT_JSON , key,NULL , val); +print_bool (PRINT_JSON , key,NULL , *val); }else {print_string (PRINT_FP ,NULL , fmt,u8_to_bool (val)); } --2.38.1
Quoted 31 lines · Max Georgiev
Quoted 30 lines · Simon Horman
Quoted 27 lines · Maxim Georgiev
Current implementation of
show_bool_val()passes "val" parameter of pointer type as a last parameter toprint_bool():
https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/tree/netlink/netlink.h#n131
...
static inline voidshow_bool_val(const char *key, const char *fmt, uint8_t *val){ if (is_json_context()) { if (val)Quoted 1 line
print_bool(PRINT_JSON, key, NULL, val);} else {...
print_bool()expects the last parameter to be bool:
https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/tree/json_print.c#n153
...
void print_bool(enumoutput_typetype,
const char *key,
const char *fmt,
bool value)
{
...
Currentshow_bool_val()implementation converts "val" pointer to bool while callingshow_bool_val(). As a resultshow_bool_val()always prints the value as "true" as long as it gets a non-null pointer to the boolean value, even if the referred boolean value is false.Fixes 7e5c1ddbe67d ("pause: add --json support")Signed-off-by Maxim Georgiev <[email protected]>
Quoted 7 lines
Quoted 3 lines
Reviewed-by Simon Horman <[email protected]>I'm assuming that val is never NULL :)
Simon, thank you for taking a look!
Yes, the "if (val)" check on line 130 guarantees that "print_bool()" on line 131 is called only if val is not null.
Thanks, that is pretty obvious now you point it out. Looks good to me :)
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
--- netlink/netlink.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)netlink/netlink.h +1
-2@@ -128,7 +128,7 @@ static inline void show_bool_val(const char *key, const char *fmt, uint8_t *val) {if (is_json_context ()) {if (val) -print_bool (PRINT_JSON , key,NULL , val); +print_bool (PRINT_JSON , key,NULL , *val); }else {print_string (PRINT_FP ,NULL , fmt,u8_to_bool (val)); } --2.38.1