cJSON
[Ported from github.com/DaveGamble/cJSON] Fix: heap-use-after-free in merge_patch when patch is subtree of target (#1065)
Brought by drakestapleton
cJSON / tests / json-patch-tests / spec_tests.json
| 1 | [ |
| 2 | { |
| 3 | "comment": "4.1. add with missing object", |
| 4 | "doc": { "q": { "bar": 2 } }, |
| 5 | "patch": [ {"op": "add", "path": "/a/b", "value": 1} ], |
| 6 | "error": |
| 7 | "path /a does not exist -- missing objects are not created recursively" |
| 8 | }, |
| 9 | |
| 10 | { |
| 11 | "comment": "A.1. Adding an Object Member", |
| 12 | "doc": { |
| 13 | "foo": "bar" |
| 14 | }, |
| 15 | "patch": [ |
| 16 | { "op": "add", "path": "/baz", "value": "qux" } |
| 17 | ], |
| 18 | "expected": { |
| 19 | "baz": "qux", |
| 20 | "foo": "bar" |
| 21 | } |
| 22 | }, |
| 23 | |
| 24 | { |
| 25 | "comment": "A.2. Adding an Array Element", |
| 26 | "doc": { |
| 27 | "foo": [ "bar", "baz" ] |
| 28 | }, |
| 29 | "patch": [ |
| 30 | { "op": "add", "path": "/foo/1", "value": "qux" } |
| 31 | ], |
| 32 | "expected": { |
| 33 | "foo": [ "bar", "qux", "baz" ] |
| 34 | } |
| 35 | }, |
| 36 | |
| 37 | { |
| 38 | "comment": "A.3. Removing an Object Member", |
| 39 | "doc": { |
| 40 | "baz": "qux", |
| 41 | "foo": "bar" |
| 42 | }, |
| 43 | "patch": [ |
| 44 | { "op": "remove", "path": "/baz" } |
| 45 | ], |
| 46 | "expected": { |
| 47 | "foo": "bar" |
| 48 | } |
| 49 | }, |
| 50 | |
| 51 | { |
| 52 | "comment": "A.4. Removing an Array Element", |
| 53 | "doc": { |
| 54 | "foo": [ "bar", "qux", "baz" ] |
| 55 | }, |
| 56 | "patch": [ |
| 57 | { "op": "remove", "path": "/foo/1" } |
| 58 | ], |
| 59 | "expected": { |
| 60 | "foo": [ "bar", "baz" ] |
| 61 | } |
| 62 | }, |
| 63 | |
| 64 | { |
| 65 | "comment": "A.5. Replacing a Value", |
| 66 | "doc": { |
| 67 | "baz": "qux", |
| 68 | "foo": "bar" |
| 69 | }, |
| 70 | "patch": [ |
| 71 | { "op": "replace", "path": "/baz", "value": "boo" } |
| 72 | ], |
| 73 | "expected": { |
| 74 | "baz": "boo", |
| 75 | "foo": "bar" |
| 76 | } |
| 77 | }, |
| 78 | |
| 79 | { |
| 80 | "comment": "A.6. Moving a Value", |
| 81 | "doc": { |
| 82 | "foo": { |
| 83 | "bar": "baz", |
| 84 | "waldo": "fred" |
| 85 | }, |
| 86 | "qux": { |
| 87 | "corge": "grault" |
| 88 | } |
| 89 | }, |
| 90 | "patch": [ |
| 91 | { "op": "move", "from": "/foo/waldo", "path": "/qux/thud" } |
| 92 | ], |
| 93 | "expected": { |
| 94 | "foo": { |
| 95 | "bar": "baz" |
| 96 | }, |
| 97 | "qux": { |
| 98 | "corge": "grault", |
| 99 | "thud": "fred" |
| 100 | } |
| 101 | } |
| 102 | }, |
| 103 | |
| 104 | { |
| 105 | "comment": "A.7. Moving an Array Element", |
| 106 | "doc": { |
| 107 | "foo": [ "all", "grass", "cows", "eat" ] |
| 108 | }, |
| 109 | "patch": [ |
| 110 | { "op": "move", "from": "/foo/1", "path": "/foo/3" } |
| 111 | ], |
| 112 | "expected": { |
| 113 | "foo": [ "all", "cows", "eat", "grass" ] |
| 114 | } |
| 115 | |
| 116 | }, |
| 117 | |
| 118 | { |
| 119 | "comment": "A.8. Testing a Value: Success", |
| 120 | "doc": { |
| 121 | "baz": "qux", |
| 122 | "foo": [ "a", 2, "c" ] |
| 123 | }, |
| 124 | "patch": [ |
| 125 | { "op": "test", "path": "/baz", "value": "qux" }, |
| 126 | { "op": "test", "path": "/foo/1", "value": 2 } |
| 127 | ], |
| 128 | "expected": { |
| 129 | "baz": "qux", |
| 130 | "foo": [ "a", 2, "c" ] |
| 131 | } |
| 132 | }, |
| 133 | |
| 134 | { |
| 135 | "comment": "A.9. Testing a Value: Error", |
| 136 | "doc": { |
| 137 | "baz": "qux" |
| 138 | }, |
| 139 | "patch": [ |
| 140 | { "op": "test", "path": "/baz", "value": "bar" } |
| 141 | ], |
| 142 | "error": "string not equivalent" |
| 143 | }, |
| 144 | |
| 145 | { |
| 146 | "comment": "A.10. Adding a nested Member Object", |
| 147 | "doc": { |
| 148 | "foo": "bar" |
| 149 | }, |
| 150 | "patch": [ |
| 151 | { "op": "add", "path": "/child", "value": { "grandchild": { } } } |
| 152 | ], |
| 153 | "expected": { |
| 154 | "foo": "bar", |
| 155 | "child": { |
| 156 | "grandchild": { |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | }, |
| 161 | |
| 162 | { |
| 163 | "comment": "A.11. Ignoring Unrecognized Elements", |
| 164 | "doc": { |
| 165 | "foo":"bar" |
| 166 | }, |
| 167 | "patch": [ |
| 168 | { "op": "add", "path": "/baz", "value": "qux", "xyz": 123 } |
| 169 | ], |
| 170 | "expected": { |
| 171 | "foo":"bar", |
| 172 | "baz":"qux" |
| 173 | } |
| 174 | }, |
| 175 | |
| 176 | { |
| 177 | "comment": "A.12. Adding to a Non-existent Target", |
| 178 | "doc": { |
| 179 | "foo": "bar" |
| 180 | }, |
| 181 | "patch": [ |
| 182 | { "op": "add", "path": "/baz/bat", "value": "qux" } |
| 183 | ], |
| 184 | "error": "add to a non-existent target" |
| 185 | }, |
| 186 | |
| 187 | { |
| 188 | "comment": "A.13 Invalid JSON Patch Document", |
| 189 | "doc": { |
| 190 | "foo": "bar" |
| 191 | }, |
| 192 | "patch": [ |
| 193 | { "op": "add", "path": "/baz", "value": "qux", "op": "remove" } |
| 194 | ], |
| 195 | "error": "operation has two 'op' members", |
| 196 | "disabled": true |
| 197 | }, |
| 198 | |
| 199 | { |
| 200 | "comment": "A.14. ~ Escape Ordering", |
| 201 | "doc": { |
| 202 | "/": 9, |
| 203 | "~1": 10 |
| 204 | }, |
| 205 | "patch": [{"op": "test", "path": "/~01", "value": 10}], |
| 206 | "expected": { |
| 207 | "/": 9, |
| 208 | "~1": 10 |
| 209 | } |
| 210 | }, |
| 211 | |
| 212 | { |
| 213 | "comment": "A.15. Comparing Strings and Numbers", |
| 214 | "doc": { |
| 215 | "/": 9, |
| 216 | "~1": 10 |
| 217 | }, |
| 218 | "patch": [{"op": "test", "path": "/~01", "value": "10"}], |
| 219 | "error": "number is not equal to string" |
| 220 | }, |
| 221 | |
| 222 | { |
| 223 | "comment": "A.16. Adding an Array Value", |
| 224 | "doc": { |
| 225 | "foo": ["bar"] |
| 226 | }, |
| 227 | "patch": [{ "op": "add", "path": "/foo/-", "value": ["abc", "def"] }], |
| 228 | "expected": { |
| 229 | "foo": ["bar", ["abc", "def"]] |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | ] |