You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by "bneradt (via GitHub)" <gi...@apache.org> on 2023/02/07 00:09:04 UTC

[GitHub] [trafficserver] bneradt commented on a diff in pull request #9382: Use snprintf

bneradt commented on code in PR #9382:
URL: https://github.com/apache/trafficserver/pull/9382#discussion_r1098044774


##########
iocore/cache/test/main.cc:
##########
@@ -116,11 +116,11 @@ build_hdrs(HTTPInfo &info, const char *url, const char *content_type)
 
   REQUIRE(url != nullptr);
 
-  p += sprintf(p, "GET %s HTTP/1.1\n", url);
-  p += sprintf(p, "User-Agent: curl/7.47.0\n");
-  p += sprintf(p, "Accept: %s\n", content_type);
-  p += sprintf(p, "Vary: Content-type\n");
-  p += sprintf(p, "Proxy-Connection: Keep-Alive\n\n");
+  p += snprintf(p, sizeof(buf), "GET %s HTTP/1.1\n", url);
+  p += snprintf(p, sizeof(buf), "User-Agent: curl/7.47.0\n");

Review Comment:
   Actually, I suppose we need to decrement the size of the buffer passed to snprintf with each write. Maybe something like:
   
   ```
     p += snprintf(p, sizeof(buf) - strnlen(p, sizeof(buf)), "User-Agent: curl/7.47.0\n");
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org