]> granicus.if.org Git - curl/commitdiff
fix compiler warning: conversion from "long" to "size_t" may lose sign
authorYang Tse <yangsita@gmail.com>
Mon, 15 Feb 2010 17:40:35 +0000 (17:40 +0000)
committerYang Tse <yangsita@gmail.com>
Mon, 15 Feb 2010 17:40:35 +0000 (17:40 +0000)
tests/server/rtspd.c
tests/server/sws.c

index efa0e0b4e09a21547b47aaec66eba76efa648960..c10b829aa16a7eaab7a6aae80c5298fc63e5b6ba 100644 (file)
@@ -578,10 +578,21 @@ static int ProcessRequest(struct httprequest *req)
          request including the body before we return. If we've been told to
          ignore the content-length, we will return as soon as all headers
          have been received */
-      size_t cl = strtol(line+15, &line, 10);
-      req->cl = cl - req->skip;
+      char *endptr;
+      char *ptr = line + 15;
+      unsigned long clen = 0;
+      while(*ptr && (' ' == *ptr))
+        ptr++;
+      clen = strtoul(ptr, &endptr, 10);
+      if((ptr == endptr) || ERRNO) {
+        /* this assumes that a zero Content-Length is valid */
+        logmsg("Found invalid Content-Length: (%s) in the request", ptr);
+        req->open = FALSE; /* closes connection */
+        return 1; /* done */
+      }
+      req->cl = clen - req->skip;
 
-      logmsg("Found Content-Length: %zu in the request", cl);
+      logmsg("Found Content-Length: %lu in the request", clen);
       if(req->skip)
         logmsg("... but will abort after %zu bytes", req->cl);
       break;
index e1dfe45d84bbcf977443e1726182e3a2a12caa70..b12b670b574b739a6cc23c6b92235aa4d3c9af1a 100644 (file)
@@ -497,10 +497,21 @@ static int ProcessRequest(struct httprequest *req)
          request including the body before we return. If we've been told to
          ignore the content-length, we will return as soon as all headers
          have been received */
-      size_t cl = strtol(line+15, &line, 10);
-      req->cl = cl - req->skip;
+      char *endptr;
+      char *ptr = line + 15;
+      unsigned long clen = 0;
+      while(*ptr && (' ' == *ptr))
+        ptr++;
+      clen = strtoul(ptr, &endptr, 10);
+      if((ptr == endptr) || ERRNO) {
+        /* this assumes that a zero Content-Length is valid */
+        logmsg("Found invalid Content-Length: (%s) in the request", ptr);
+        req->open = FALSE; /* closes connection */
+        return 1; /* done */
+      }
+      req->cl = clen - req->skip;
 
-      logmsg("Found Content-Length: %zu in the request", cl);
+      logmsg("Found Content-Length: %lu in the request", clen);
       if(req->skip)
         logmsg("... but will abort after %zu bytes", req->cl);
       break;