SYS-REQ-115
(config Config, data []byte, keys ...string)
| 1193 | |
| 1194 | // SYS-REQ-115 |
| 1195 | func deleteFoundConfig(config Config, data []byte, keys ...string) (result []byte, found bool) { |
| 1196 | lk := len(keys) |
| 1197 | if lk == 0 { |
| 1198 | // Deleting the root produces an empty document whose backing array |
| 1199 | // must not alias the caller's input. |
| 1200 | return make([]byte, 0), true |
| 1201 | } |
| 1202 | |
| 1203 | array := false |
| 1204 | if len(keys[lk-1]) > 0 && string(keys[lk-1][0]) == "[" { |
| 1205 | array = true |
| 1206 | } |
| 1207 | |
| 1208 | var startOffset, keyOffset int |
| 1209 | endOffset := len(data) |
| 1210 | var err error |
| 1211 | if !array { |
| 1212 | if len(keys) > 1 { |
| 1213 | _, _, startOffset, endOffset, err = internalGetConfig(config, data, keys[:lk-1]...) |
| 1214 | if err != nil { |
| 1215 | // problem parsing the data |
| 1216 | return data, false |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | keyOffset, err = findKeyStartConfig(config, data[startOffset:endOffset], keys[lk-1]) |
| 1221 | if err == KeyPathNotFoundError { |
| 1222 | // problem parsing the data |
| 1223 | return data, false |
| 1224 | } |
| 1225 | keyOffset += startOffset |
| 1226 | var subEndOffset int |
| 1227 | _, _, _, subEndOffset, err = internalGetConfig(config, data[startOffset:endOffset], keys[lk-1]) |
| 1228 | if err != nil { |
| 1229 | return data, false |
| 1230 | } |
| 1231 | endOffset = startOffset + subEndOffset |
| 1232 | tokEnd := tokenEnd(data[endOffset:]) |
| 1233 | tokStart := findTokenStart(data[:keyOffset], ","[0]) |
| 1234 | |
| 1235 | if endOffset+tokEnd >= len(data) { |
| 1236 | // tokenEnd sentinel: no delimiter found, input is truncated |
| 1237 | return data, false |
| 1238 | } |
| 1239 | |
| 1240 | // guard: tokenEnd sentinel may return -1 on truncated input; bounds-check before deref. |
| 1241 | idx := endOffset + tokEnd |
| 1242 | // Scan forward from idx through any JSON whitespace to find the next |
| 1243 | // real token. The original check only matched a single ' ' byte |
| 1244 | // before the comma, so inputs like '{"a":1,\n"b":2}' or '[0,0 ,0]' |
| 1245 | // (multiple whitespace bytes) bypassed the cleanup and left a |
| 1246 | // dangling comma sequence. Found by FuzzPathMutation. |
| 1247 | nextTokIdx := idx |
| 1248 | for nextTokIdx < len(data) && isJSONWhitespace(data[nextTokIdx]) { |
| 1249 | nextTokIdx++ |
| 1250 | } |
| 1251 | if len(data) > idx && data[idx] == ',' { |
| 1252 | endOffset += tokEnd + 1 |
no test coverage detected