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