firewall: options: fix parsing of boolean attributes
[librecmc/librecmc.git] / package / network / config / firewall / patches / 0002-options-fix-parsing-of-boolean-attributes.patch
1 From 78d52a28c66ad0fd2af250038fdcf4239ad37bf2 Mon Sep 17 00:00:00 2001
2 From: Remi NGUYEN VAN <remi.nguyenvan+openwrt@gmail.com>
3 Date: Sat, 15 Aug 2020 13:50:27 +0900
4 Subject: [PATCH] options: fix parsing of boolean attributes
5
6 Boolean attributes were parsed the same way as string attributes,
7 so a value of { "bool_attr": "true" } would be parsed correctly, but
8 { "bool_attr": true } (without quotes) was parsed as false.
9
10 Fixes FS#3284
11
12 Signed-off-by: Remi NGUYEN VAN <remi.nguyenvan+openwrt@gmail.com>
13 ---
14  options.c | 6 ++++++
15  1 file changed, 6 insertions(+)
16
17 --- a/options.c
18 +++ b/options.c
19 @@ -1170,6 +1170,9 @@ fw3_parse_blob_options(void *s, const st
20                                                 if (blobmsg_type(e) == BLOBMSG_TYPE_INT32) {
21                                                         snprintf(buf, sizeof(buf), "%d", blobmsg_get_u32(e));
22                                                         v = buf;
23 +                                               } else if (blobmsg_type(o) == BLOBMSG_TYPE_BOOL) {
24 +                                                       snprintf(buf, sizeof(buf), "%d", blobmsg_get_bool(o));
25 +                                                       v = buf;
26                                                 } else {
27                                                         v = blobmsg_get_string(e);
28                                                 }
29 @@ -1189,6 +1192,9 @@ fw3_parse_blob_options(void *s, const st
30                                 if (blobmsg_type(o) == BLOBMSG_TYPE_INT32) {
31                                         snprintf(buf, sizeof(buf), "%d", blobmsg_get_u32(o));
32                                         v = buf;
33 +                               } else if (blobmsg_type(o) == BLOBMSG_TYPE_BOOL) {
34 +                                       snprintf(buf, sizeof(buf), "%d", blobmsg_get_bool(o));
35 +                                       v = buf;
36                                 } else {
37                                         v = blobmsg_get_string(o);
38                                 }