summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Arpit Jain2026-07-29 14:25:18 +0900
committerGravatar Nikias Bassen2026-09-29 16:43:02 +0200
commitbd68e726e45c10fd223814eaf6129e1bb2f7b022 (patch)
tree139a2eba6ddd6d555fbd89bcbe75aadaaa3d0d01 /src
parentbe3a7ff2862868b4612d4c56edbd42e1d7dd7fdb (diff)
downloadlibplist-bd68e726e45c10fd223814eaf6129e1bb2f7b022.tar.gz
libplist-bd68e726e45c10fd223814eaf6129e1bb2f7b022.tar.bz2
plist: fix inverted strcmp in string to boolean conversion
plist_dict_get_bool() compared the string value with strcmp() but treated a non-zero return as a match. strcmp() returns 0 on equality, so the conditions were inverted: "true" produced 0, "false" produced 1, and any other string also produced 1. The error branch could never be reached, since it required both comparisons to return 0 at once. The result is that the API returns the opposite of the stored value for both valid boolean strings, and returns true for strings that are not booleans at all, instead of reporting the conversion error. Compare == 0 in both conditions: input before after true 0 1 false 1 0 not-a-bool 1 error TRUE 1 error (empty) 1 error Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/plist.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/plist.c b/src/plist.c
index 5ea6c12..bcd212c 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -1495,9 +1495,9 @@ uint8_t plist_dict_get_bool(plist_t dict, const char *key)
case PLIST_STRING:
strval = plist_get_string_ptr(node, NULL);
if (strval) {
- if (strcmp(strval, "true")) {
+ if (strcmp(strval, "true") == 0) {
bval = 1;
- } else if (strcmp(strval, "false")) {
+ } else if (strcmp(strval, "false") == 0) {
bval = 0;
} else {
PLIST_ERR("%s: invalid string '%s' for string to boolean conversion\n", __func__, strval);