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

bnolsen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 66a3405072 system_stats: fix buffer overflow caught by asan (#9723)
66a3405072 is described below

commit 66a3405072107a266582a764ad4b2b89c3dbee53
Author: Brian Olsen <[email protected]>
AuthorDate: Mon May 22 06:49:56 2023 -0600

    system_stats: fix buffer overflow caught by asan (#9723)
    
    Co-authored-by: Brian Olsen <[email protected]>
---
 plugins/experimental/system_stats/system_stats.cc | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/plugins/experimental/system_stats/system_stats.cc 
b/plugins/experimental/system_stats/system_stats.cc
index 8f5ea9ff74..a424bcce8e 100644
--- a/plugins/experimental/system_stats/system_stats.cc
+++ b/plugins/experimental/system_stats/system_stats.cc
@@ -116,20 +116,17 @@ statAdd(const char *name, TSRecordDataType record_type, 
TSMutex create_mutex)
   return stat_id;
 }
 
-static int
-getFile(const char *filename, char *buffer, int bufferSize)
+static ssize_t
+getFile(const char *filename, char *buffer, size_t bufferSize)
 {
-  TSFile f = 0;
-  size_t s = 0;
-
-  f = TSfopen(filename, "r");
+  TSFile f = TSfopen(filename, "r");
   if (!f) {
     buffer[0] = 0;
     // Return -1 to indicate read err
     return -1;
   }
 
-  s = TSfread(f, buffer, bufferSize);
+  ssize_t s = TSfread(f, buffer, bufferSize - 1);
   if (s > 0) {
     buffer[s] = 0;
   } else {

Reply via email to