]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl_fnmatch, servers: drop local macros in favour of `sizeof()`
authorViktor Szakats <commit@vsz.me>
Fri, 11 Jul 2025 11:48:13 +0000 (13:48 +0200)
committerViktor Szakats <commit@vsz.me>
Mon, 21 Jul 2025 14:14:14 +0000 (16:14 +0200)
Closes #17898

lib/curl_fnmatch.c
tests/server/rtspd.c
tests/server/sws.c

index 21eca4ceda54e6de977ec765daa6b4508108fbd9..66b9739f3c035c6f8da97f4c3f28ffbceb2595d2 100644 (file)
@@ -74,14 +74,13 @@ typedef enum {
 static int parsekeyword(const unsigned char **pattern, unsigned char *charset)
 {
   parsekey_state state = CURLFNM_PKW_INIT;
-#define KEYLEN 10
-  char keyword[KEYLEN] = { 0 };
-  int i;
+  char keyword[10] = { 0 };
+  size_t i;
   const unsigned char *p = *pattern;
   bool found = FALSE;
   for(i = 0; !found; i++) {
     char c = (char)*p++;
-    if(i >= KEYLEN)
+    if(i >= sizeof(keyword))
       return SETCHARSET_FAIL;
     switch(state) {
     case CURLFNM_PKW_INIT:
index d4baa3ff1a90e6640349bdbfbc34b053e636c862..77301878750f87f350b26723c69c7e8456122db6 100644 (file)
@@ -33,9 +33,6 @@
 #include <netinet/tcp.h> /* for TCP_NODELAY */
 #endif
 
-#undef REQBUFSIZ
-#define REQBUFSIZ 150000
-
 static long rtspd_prevtestno = -1;    /* previous test number we served */
 static long rtspd_prevpartno = -1;    /* previous part number we served */
 static bool rtspd_prevbounce = FALSE; /* instructs the server to override the
@@ -59,7 +56,7 @@ typedef enum {
                               ((p)[3] = (char)((l) & 0xFF)))
 
 struct rtspd_httprequest {
-  char reqbuf[REQBUFSIZ]; /* buffer area for the incoming request */
+  char reqbuf[150000]; /* buffer area for the incoming request */
   size_t checkindex; /* where to start checking of the request */
   size_t offset;     /* size of the incoming request */
   long testno;       /* test number found in the request */
@@ -621,7 +618,7 @@ static int rtspd_get_request(curl_socket_t sock, struct rtspd_httprequest *req)
 
   /*** end of httprequest init ***/
 
-  while(!done_processing && (req->offset < REQBUFSIZ-1)) {
+  while(!done_processing && (req->offset < sizeof(req->reqbuf)-1)) {
     if(pipereq_length && pipereq) {
       memmove(reqbuf, pipereq, pipereq_length);
       got = curlx_uztosz(pipereq_length);
@@ -634,7 +631,8 @@ static int rtspd_get_request(curl_socket_t sock, struct rtspd_httprequest *req)
            client wants to send! */
         got = sread(sock, reqbuf + req->offset, req->cl);
       else
-        got = sread(sock, reqbuf + req->offset, REQBUFSIZ-1 - req->offset);
+        got = sread(sock, reqbuf + req->offset,
+                    sizeof(req->reqbuf)-1 - req->offset);
     }
     if(got_exit_signal)
       return 1;
@@ -669,16 +667,16 @@ static int rtspd_get_request(curl_socket_t sock, struct rtspd_httprequest *req)
     }
   }
 
-  if((req->offset == REQBUFSIZ-1) && (got > 0)) {
+  if((req->offset == sizeof(req->reqbuf)-1) && (got > 0)) {
     logmsg("Request would overflow buffer, closing connection");
     /* dump request received so far to external file anyway */
-    reqbuf[REQBUFSIZ-1] = '\0';
+    reqbuf[sizeof(req->reqbuf)-1] = '\0';
     fail = 1;
   }
-  else if(req->offset > REQBUFSIZ-1) {
+  else if(req->offset > sizeof(req->reqbuf)-1) {
     logmsg("Request buffer overflow, closing connection");
     /* dump request received so far to external file anyway */
-    reqbuf[REQBUFSIZ-1] = '\0';
+    reqbuf[sizeof(req->reqbuf)-1] = '\0';
     fail = 1;
   }
   else
index 7b90e510b4f64c5983c822f515c40fb93d1528e1..871248b4d0aeeb76d5b2c38d116bf197ada2f614 100644 (file)
@@ -37,9 +37,6 @@
 static bool use_gopher = FALSE;
 static bool is_proxy = FALSE;
 
-#undef REQBUFSIZ
-#define REQBUFSIZ (2*1024*1024)
-
 #define MAX_SLEEP_TIME_MS 250
 
 static long sws_prevtestno = -1;    /* previous test number we served */
@@ -54,7 +51,7 @@ static bool sws_prevbounce = FALSE; /* instructs the server to override the
 #define RCMD_STREAM    2 /* told to stream */
 
 struct sws_httprequest {
-  char reqbuf[REQBUFSIZ]; /* buffer area for the incoming request */
+  char reqbuf[2*1024*1024]; /* buffer area for the incoming request */
   bool connect_request; /* if a CONNECT */
   unsigned short connect_port; /* the port number CONNECT used */
   size_t checkindex; /* where to start checking of the request */
@@ -815,7 +812,8 @@ static int sws_get_request(curl_socket_t sock, struct sws_httprequest *req)
     if(req->open) {
       logmsg("wait for websocket traffic");
       do {
-        got = sread(sock, reqbuf + req->offset, REQBUFSIZ - req->offset);
+        got = sread(sock, reqbuf + req->offset,
+                    sizeof(req->reqbuf) - req->offset);
         if(got > 0) {
           req->offset += got;
           logmsg("Got %zu bytes from client", got);
@@ -866,7 +864,7 @@ static int sws_get_request(curl_socket_t sock, struct sws_httprequest *req)
     return -1;
   }
 
-  if(req->offset >= REQBUFSIZ-1) {
+  if(req->offset >= sizeof(req->reqbuf)-1) {
     /* buffer is already full; do nothing */
     overflow = 1;
   }
@@ -877,7 +875,8 @@ static int sws_get_request(curl_socket_t sock, struct sws_httprequest *req)
          client wants to send! */
       got = sread(sock, reqbuf + req->offset, req->cl);
     else
-      got = sread(sock, reqbuf + req->offset, REQBUFSIZ-1 - req->offset);
+      got = sread(sock, reqbuf + req->offset,
+                  sizeof(req->reqbuf)-1 - req->offset);
 
     if(got_exit_signal)
       return -1;
@@ -911,16 +910,16 @@ static int sws_get_request(curl_socket_t sock, struct sws_httprequest *req)
       return -1;
   }
 
-  if(overflow || (req->offset == REQBUFSIZ-1 && got > 0)) {
+  if(overflow || (req->offset == sizeof(req->reqbuf)-1 && got > 0)) {
     logmsg("Request would overflow buffer, closing connection");
     /* dump request received so far to external file anyway */
-    reqbuf[REQBUFSIZ-1] = '\0';
+    reqbuf[sizeof(req->reqbuf)-1] = '\0';
     fail = 1;
   }
-  else if(req->offset > REQBUFSIZ-1) {
+  else if(req->offset > sizeof(req->reqbuf)-1) {
     logmsg("Request buffer overflow, closing connection");
     /* dump request received so far to external file anyway */
-    reqbuf[REQBUFSIZ-1] = '\0';
+    reqbuf[sizeof(req->reqbuf)-1] = '\0';
     fail = 1;
   }
   else