You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2019/11/05 23:55:42 UTC

[trafficserver] 02/03: gcc9: sprintf and strncat fixes in plugins

This is an automated email from the ASF dual-hosted git repository.

bcall pushed a commit to branch 8.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 9c6706c73245718d83fdf1a951c945e96c11d9ce
Author: Bryan Call <bc...@apache.org>
AuthorDate: Tue May 14 10:25:22 2019 -0700

    gcc9: sprintf and strncat fixes in plugins
    
    (cherry picked from commit fcebeae51454d45c608b1a105b8df8cca70cbbe9)
---
 example/thread_pool/psi.c  | 4 ++--
 plugins/s3_auth/s3_auth.cc | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/example/thread_pool/psi.c b/example/thread_pool/psi.c
index fa465b2..e770960 100644
--- a/example/thread_pool/psi.c
+++ b/example/thread_pool/psi.c
@@ -466,7 +466,7 @@ psi_include(TSCont contp, void *edata ATS_UNUSED)
   /* For security reason, we do not allow to include files that are
      not in the directory <plugin_path>/include.
      Also include file cannot contain any path. */
-  sprintf(inc_file, "%s/%s", psi_directory, _basename(data->psi_filename));
+  snprintf(inc_file, sizeof(inc_file), "%s/%s", psi_directory, _basename(data->psi_filename));
 
   /* Read the include file and copy content into iobuffer */
   if ((filep = TSfopen(inc_file, "r")) != NULL) {
@@ -971,7 +971,7 @@ TSPluginInit(int argc ATS_UNUSED, const char *argv[] ATS_UNUSED)
   }
 
   /* Initialize the psi directory = <plugin_path>/include */
-  sprintf(psi_directory, "%s/%s", TSPluginDirGet(), PSI_PATH);
+  snprintf(psi_directory, sizeof(psi_directory), "%s/%s", TSPluginDirGet(), PSI_PATH);
 
   /* create an TSTextLogObject to log any psi include */
   retval = TSTextLogObjectCreate("psi", TS_LOG_MODE_ADD_TIMESTAMP, &log);
diff --git a/plugins/s3_auth/s3_auth.cc b/plugins/s3_auth/s3_auth.cc
index 1d95405..6814859 100644
--- a/plugins/s3_auth/s3_auth.cc
+++ b/plugins/s3_auth/s3_auth.cc
@@ -620,10 +620,10 @@ S3Request::set_header(const char *header, int header_len, const char *val, int v
 static size_t
 str_concat(char *dst, size_t dst_len, const char *src, size_t src_len)
 {
-  size_t to_copy = (src_len < dst_len) ? src_len : dst_len;
+  size_t to_copy = std::min(dst_len, src_len);
 
   if (to_copy > 0) {
-    (void)strncat(dst, src, to_copy);
+    strncat(dst, src, to_copy);
   }
 
   return to_copy;