| 21099 | } |
| 21100 | |
| 21101 | static bool parse_content_length(const char *line, size_t *out) { |
| 21102 | if (!line || !out || strncmp(line, "Content-Length:", SLEN("Content-Length:")) != 0) { |
| 21103 | return false; |
| 21104 | } |
| 21105 | |
| 21106 | const char *cursor = line + MCP_CONTENT_PREFIX; |
| 21107 | while (*cursor == ' ' || *cursor == '\t') { |
| 21108 | cursor++; |
| 21109 | } |
| 21110 | if (!isdigit((unsigned char)*cursor)) { |
| 21111 | return false; |
| 21112 | } |
| 21113 | |
| 21114 | errno = 0; |
| 21115 | char *end = NULL; |
| 21116 | unsigned long long parsed = strtoull(cursor, &end, CBM_DECIMAL_BASE); |
| 21117 | if (errno == ERANGE || end == cursor) { |
| 21118 | return false; |
| 21119 | } |
| 21120 | while (*end == ' ' || *end == '\t') { |
| 21121 | end++; |
| 21122 | } |
| 21123 | if (*end != '\0' || parsed == 0 || parsed > MCP_MAX_MESSAGE_SIZE) { |
| 21124 | return false; |
| 21125 | } |
| 21126 | *out = (size_t)parsed; |
| 21127 | return true; |
| 21128 | } |
| 21129 | |
| 21130 | int cbm_mcp_read_message(FILE *in, char **message, bool *content_length_framed) { |
| 21131 | if (!in || !message || !content_length_framed) { |
no outgoing calls
no test coverage detected