You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by GitBox <gi...@apache.org> on 2022/11/11 20:18:46 UTC

[GitHub] [trafficserver] moonchen commented on a diff in pull request #9189: Removed most sprintf and ignore sprintf warnings in bind code

moonchen commented on code in PR #9189:
URL: https://github.com/apache/trafficserver/pull/9189#discussion_r1020516102


##########
plugins/experimental/access_control/utils.cc:
##########
@@ -124,7 +124,7 @@ urlEncode(const char *in, size_t inLen, char *out, size_t outLen)
       *dst++ = '+';
     } else {
       *dst++ = '%';
-      sprintf(dst, "%02x", static_cast<unsigned char>(*src));

Review Comment:
   I think this should be `snprintf(dst, out + outLen - dst, "%02x", static_cast<unsigned char>(*src));`.



##########
plugins/prefetch/plugin.cc:
##########
@@ -584,8 +584,9 @@ contHandleFetch(const TSCont contp, TSEvent event, void *edata)
         TSHttpHdrReasonSet(bufp, hdrLoc, reason, reasonLen);
         PrefetchDebug("set response: %d %.*s '%s'", data->_status, reasonLen, reason, data->_body.c_str());
 
-        char *buf = static_cast<char *>(TSmalloc(data->_body.length() + 1));
-        sprintf(buf, "%s", data->_body.c_str());
+        size_t bufsize = data->_body.length() + 1;
+        char *buf      = static_cast<char *>(TSmalloc(bufsize));

Review Comment:
   I think that `memcpy(buf, data->_body.c_str(), bufsize)` would be faster and simpler here.



##########
proxy/http/remap/unit-tests/plugin_testing_common.cc:
##########
@@ -46,7 +46,7 @@ getTemporaryDir()
   tmpDir /= "sandbox_XXXXXX";
 
   char dirNameTemplate[tmpDir.string().length() + 1];
-  sprintf(dirNameTemplate, "%s", tmpDir.c_str());
+  snprintf(dirNameTemplate, sizeof(dirNameTemplate), "%s", tmpDir.c_str());

Review Comment:
   Likewise, I think this should be `memcpy(dirNameTemplate, tmpDir.c_str(), sizeof(dirNameTemplate));`



-- 
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