[PATCH] options: fix parsing of boolean attributes

Rémi NGUYEN VAN remi.nguyenvan at gmail.com
Wed Aug 19 20:34:45 EDT 2020


I see this is getting mixed with other patches, so to be clear this is
a patch for firewall3 (see
https://bugs.openwrt.org/index.php?do=details&task_id=3284).
Let me know if there is a better place to post this.


Le sam. 15 août 2020 à 13:50, <remi.nguyenvan at gmail.com> a écrit :
>
> From: Remi NGUYEN VAN <remi.nguyenvan+openwrt at gmail.com>
>
> Boolean attributes were parsed the same way as string attributes,
> so a value of { "bool_attr": "true" } would be parsed correctly, but
> { "bool_attr": true } (without quotes) was parsed as false.
>
> Fixes FS#3284
>
> Signed-off-by: Remi NGUYEN VAN <remi.nguyenvan+openwrt at gmail.com>
> ---
>  options.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/options.c b/options.c
> index aed0cfb..6131786 100644
> --- a/options.c
> +++ b/options.c
> @@ -1170,6 +1170,9 @@ fw3_parse_blob_options(void *s, const struct fw3_option *opts,
>                                                 if (blobmsg_type(e) == BLOBMSG_TYPE_INT32) {
>                                                         snprintf(buf, sizeof(buf), "%d", blobmsg_get_u32(e));
>                                                         v = buf;
> +                                               } else if (blobmsg_type(o) == BLOBMSG_TYPE_BOOL) {
> +                                                       snprintf(buf, sizeof(buf), "%d", blobmsg_get_bool(o));
> +                                                       v = buf;
>                                                 } else {
>                                                         v = blobmsg_get_string(e);
>                                                 }
> @@ -1189,6 +1192,9 @@ fw3_parse_blob_options(void *s, const struct fw3_option *opts,
>                                 if (blobmsg_type(o) == BLOBMSG_TYPE_INT32) {
>                                         snprintf(buf, sizeof(buf), "%d", blobmsg_get_u32(o));
>                                         v = buf;
> +                               } else if (blobmsg_type(o) == BLOBMSG_TYPE_BOOL) {
> +                                       snprintf(buf, sizeof(buf), "%d", blobmsg_get_bool(o));
> +                                       v = buf;
>                                 } else {
>                                         v = blobmsg_get_string(o);
>                                 }
> --
> 2.28.0.220.ged08abb693-goog
>



More information about the openwrt-devel mailing list