ci: fix test_subagent strcasestr crash; llvm-mingw Windows zip
clang under strict C11 left strcasestr undeclared (returns int → pointer truncation → SIGSEGV). Parse Content-Length portably; keep -Werror on make check. Drop Nix for windows-cross (root /nix fails) and use pinned llvm-mingw UCRT instead; Alpine musl gets linux-headers for audit.h.
This commit is contained in:
+18
-3
@@ -18,6 +18,7 @@
|
||||
#define CST_TEST_SOCKETS
|
||||
#include "cst_test_util.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <curl/curl.h>
|
||||
#include <pthread.h>
|
||||
#include <stdatomic.h>
|
||||
@@ -52,6 +53,20 @@ static void send_all(test_sock_t fd, const char *s, size_t n) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Portable Content-Length lookup (avoid GNU strcasestr; undeclared under
|
||||
* strict C11 it is assumed to return int and the pointer truncates). */
|
||||
static const char *find_content_length(const char *hdrs) {
|
||||
static const char key[] = "content-length:";
|
||||
for (const char *p = hdrs; *p; p++) {
|
||||
size_t i = 0;
|
||||
while (key[i] && tolower((unsigned char)p[i]) == (unsigned char)key[i])
|
||||
i++;
|
||||
if (key[i] == '\0')
|
||||
return p + (sizeof(key) - 1);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void sse(test_sock_t fd, cJSON *delta, const char *finish) {
|
||||
cJSON *o = cJSON_CreateObject();
|
||||
cJSON *ch = cJSON_AddArrayToObject(o, "choices");
|
||||
@@ -205,7 +220,7 @@ static void handle(test_sock_t fd, const char *body_txt) {
|
||||
const char *rep = cJSON_IsString(c) ? strstr(c->valuestring,
|
||||
"child report ")
|
||||
: NULL;
|
||||
if (strcmp(r->valuestring, "tool") == 0 && rep)
|
||||
if (cJSON_IsString(r) && strcmp(r->valuestring, "tool") == 0 && rep)
|
||||
cst_buf_printf(&b, " [%.14s]", rep);
|
||||
}
|
||||
reply_text(fd, b.buf);
|
||||
@@ -230,8 +245,8 @@ static void *conn_main(void *p) {
|
||||
char *e = strstr(req.buf, "\r\n\r\n");
|
||||
if (e) {
|
||||
hdr_end = (size_t)(e - req.buf) + 4;
|
||||
char *cl = strcasestr(req.buf, "Content-Length:");
|
||||
need = cl ? atol(cl + 15) : 0;
|
||||
const char *cl = find_content_length(req.buf);
|
||||
need = cl ? atol(cl) : 0;
|
||||
}
|
||||
}
|
||||
if (hdr_end && (long)(req.len - hdr_end) >= need)
|
||||
|
||||
Reference in New Issue
Block a user