return -1;
}
- from_s = json_object_get_string(jfrom);
+ from_s = json_object_get_type(jfrom) == json_type_string ? json_object_get_string(jfrom) : NULL;
if (from_s == NULL) {
_set_err(EINVAL, "Patch object 'from' field is not a string");
return -1;
_set_err(EINVAL, "Patch object does not contain 'op' field");
return -1;
}
- op = json_object_get_string(jop);
+ op = json_object_get_type(jop) == json_type_string ? json_object_get_string(jop) : NULL;
if (op == NULL) {
_set_err(EINVAL, "Patch object 'op' field is not a string");
return -1;
_set_err(EINVAL, "Patch object does not contain 'path' field");
return -1;
}
- path = json_object_get_string(jpath); // Note: empty string is ok!
+ // Note: empty string is ok!
+ path = json_object_get_type(jpath) == json_type_string ? json_object_get_string(jpath)
+ : NULL;
if (path == NULL) {
_set_err(EINVAL, "Patch object 'path' field is not a string");
return -1;
"doc": {"foo": "bar"},
"patch": [{"op": "move", "from": null, "path": "/foo"}],
"error": "a null from field should fail rather than crash"
+ },
+
+ { "comment": "null path field must be rejected, not dereferenced",
+ "doc": {"foo": "bar"},
+ "patch": [{"op": "remove", "path": null}],
+ "error": "a null path field should fail rather than crash"
}
]
=> json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Patch object 'op' field is not a string
Testing 'null from field must be rejected, not dereferenced', doc '{ "foo": "bar" }' patch '[ { "op": "move", "from": null, "path": "\/foo" } ]' : OK
=> json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Patch object 'from' field is not a string
+Testing 'null path field must be rejected, not dereferenced', doc '{ "foo": "bar" }' patch '[ { "op": "remove", "path": null } ]' : OK
+ => json_patch_apply failed as expected: ERRNO=EINVAL at patch idx 0: Patch object 'path' field is not a string