| 883 | } |
| 884 | |
| 885 | static bool agent_json_key_equals(const char *data, size_t start, size_t end, const char *key) { |
| 886 | if (end < start) { |
| 887 | return false; |
| 888 | } |
| 889 | size_t key_offset = 0U; |
| 890 | size_t key_len = strlen(key); |
| 891 | for (size_t cursor = start; cursor < end;) { |
| 892 | unsigned value = (unsigned char)data[cursor++]; |
| 893 | if (value == '\\') { |
| 894 | if (cursor >= end) { |
| 895 | return false; |
| 896 | } |
| 897 | char escape = data[cursor++]; |
| 898 | if (escape == 'u' || escape == 'x') { |
| 899 | size_t digits = escape == 'u' ? 4U : 2U; |
| 900 | if (end - cursor < digits) { |
| 901 | return false; |
| 902 | } |
| 903 | value = 0U; |
| 904 | for (size_t i = 0U; i < digits; i++) { |
| 905 | unsigned char digit = (unsigned char)data[cursor++]; |
| 906 | if (digit >= '0' && digit <= '9') { |
| 907 | value = value * 16U + (unsigned)(digit - '0'); |
| 908 | } else if (digit >= 'a' && digit <= 'f') { |
| 909 | value = value * 16U + (unsigned)(digit - 'a' + 10U); |
| 910 | } else if (digit >= 'A' && digit <= 'F') { |
| 911 | value = value * 16U + (unsigned)(digit - 'A' + 10U); |
| 912 | } else { |
| 913 | return false; |
| 914 | } |
| 915 | } |
| 916 | } else if (strchr("\\/\"'", escape)) { |
| 917 | value = (unsigned char)escape; |
| 918 | } else { |
| 919 | return false; |
| 920 | } |
| 921 | } |
| 922 | if (value > 0x7fU || key_offset >= key_len || (unsigned char)key[key_offset++] != value) { |
| 923 | return false; |
| 924 | } |
| 925 | } |
| 926 | return key_offset == key_len; |
| 927 | } |
| 928 | |
| 929 | /* Returns 0 found, 1 absent, -1 malformed/ambiguous/not-an-object. */ |
| 930 | static int agent_json_find_member(const char *data, size_t object_start, size_t object_end, |
no outgoing calls
no test coverage detected