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

dmeden 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 aa4e77c52a Coverity: Several Overflowed integer argument fixes (#11879)
aa4e77c52a is described below

commit aa4e77c52a56c8bdf7bc3e576a18844f2a8cca8e
Author: Damian Meden <[email protected]>
AuthorDate: Tue Nov 26 13:28:37 2024 +0100

    Coverity: Several Overflowed integer argument fixes (#11879)
    
    * Coverity: Fixes for CID-1550434, CID-1550423, CID-1550429
---
 src/proxy/logging/Log.cc     | 10 +++++-----
 src/traffic_logcat/logcat.cc |  6 +++---
 src/tscore/MatcherUtils.cc   |  6 +++---
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/proxy/logging/Log.cc b/src/proxy/logging/Log.cc
index 73675a5b2c..c94a246702 100644
--- a/src/proxy/logging/Log.cc
+++ b/src/proxy/logging/Log.cc
@@ -1306,7 +1306,7 @@ Log::flush_thread_main(void * /* args ATS_UNUSED */)
   LogBuffer                                 *logbuffer;
   LogFlushData                              *fdata;
   ink_hrtime                                 now, last_time = 0;
-  int                                        len, total_bytes;
+  ssize_t                                    len, total_bytes;
   SLL<LogFlushData, LogFlushData::Link_link> link, invert_link;
 
   Log::flush_notify->lock();
@@ -1328,7 +1328,7 @@ Log::flush_thread_main(void * /* args ATS_UNUSED */)
     //
     while ((fdata = invert_link.pop())) {
       char    *buf           = nullptr;
-      int      bytes_written = 0;
+      ssize_t  bytes_written = 0;
       LogFile *logfile       = fdata->m_logfile.get();
 
       if (logfile->m_file_format == LOG_FILE_BINARY) {
@@ -1349,7 +1349,7 @@ Log::flush_thread_main(void * /* args ATS_UNUSED */)
       // make sure we're open & ready to write
       logfile->check_fd();
       if (!logfile->is_open()) {
-        SiteThrottledWarning("File:%s was closed, have dropped (%d) bytes.", 
logfile->get_name(), total_bytes);
+        SiteThrottledWarning("File:%s was closed, have dropped (%ld) bytes.", 
logfile->get_name(), total_bytes);
 
         Metrics::Counter::increment(log_rsb.bytes_lost_before_written_to_disk, 
total_bytes);
         delete fdata;
@@ -1364,7 +1364,7 @@ Log::flush_thread_main(void * /* args ATS_UNUSED */)
       //
       while (total_bytes - bytes_written) {
         if (Log::config->logging_space_exhausted) {
-          Dbg(dbg_ctl_log, "logging space exhausted, failed to write file:%s, 
have dropped (%d) bytes.", logfile->get_name(),
+          Dbg(dbg_ctl_log, "logging space exhausted, failed to write file:%s, 
have dropped (%ld) bytes.", logfile->get_name(),
               (total_bytes - bytes_written));
 
           
Metrics::Counter::increment(log_rsb.bytes_lost_before_written_to_disk, 
total_bytes - bytes_written);
@@ -1374,7 +1374,7 @@ Log::flush_thread_main(void * /* args ATS_UNUSED */)
         len = ::write(logfilefd, &buf[bytes_written], total_bytes - 
bytes_written);
 
         if (len < 0) {
-          SiteThrottledError("Failed to write log to %s: [tried %d, wrote %d, 
%s]", logfile->get_name(),
+          SiteThrottledError("Failed to write log to %s: [tried %ld, wrote 
%ld, %s]", logfile->get_name(),
                              total_bytes - bytes_written, bytes_written, 
strerror(errno));
 
           
Metrics::Counter::increment(log_rsb.bytes_lost_before_written_to_disk, 
total_bytes - bytes_written);
diff --git a/src/traffic_logcat/logcat.cc b/src/traffic_logcat/logcat.cc
index 550c0c95a9..7cabeb96ed 100644
--- a/src/traffic_logcat/logcat.cc
+++ b/src/traffic_logcat/logcat.cc
@@ -123,8 +123,8 @@ follow_rotate(const char *input_file, ino_t old_inode_num)
 int
 process_file(int in_fd, int out_fd)
 {
-  char buffer[MAX_LOGBUFFER_SIZE];
-  int  nread, buffer_bytes;
+  char    buffer[MAX_LOGBUFFER_SIZE];
+  ssize_t nread, buffer_bytes;
 
   while (true) {
     // read the next buffer from file descriptor
@@ -182,7 +182,7 @@ process_file(int in_fd, int out_fd)
     // Read the next full buffer (allowing for "partial" reads)
     nread = 0;
     while (nread < buffer_bytes) {
-      int rc = read(in_fd, &buffer[header_size] + nread, buffer_bytes - nread);
+      auto rc = read(in_fd, &buffer[header_size] + nread, buffer_bytes - 
nread);
 
       if ((rc == EOF) && (!follow_flag)) {
         fprintf(stderr, "Bad LogBuffer read!\n");
diff --git a/src/tscore/MatcherUtils.cc b/src/tscore/MatcherUtils.cc
index 84353adf7a..813e11a937 100644
--- a/src/tscore/MatcherUtils.cc
+++ b/src/tscore/MatcherUtils.cc
@@ -52,8 +52,8 @@ readIntoBuffer(const char *file_path, const char 
*module_name, int *read_size_pt
   int         fd;
   struct stat file_info;
   char       *file_buf, *buf;
-  int         read_size = 0;
-  int         file_size;
+  ssize_t     read_size = 0;
+  ssize_t     file_size;
 
   if (read_size_ptr != nullptr) {
     *read_size_ptr = 0;
@@ -113,7 +113,7 @@ readIntoBuffer(const char *file_path, const char 
*module_name, int *read_size_pt
     // Didn't get the whole file, drop everything. We don't want to return
     //   something partially read because, ie. with configs, the behaviour
     //   is undefined.
-    Error("%s Only able to read %d bytes out %d for %s file", module_name, 
read_size, file_size, file_path);
+    Error("%s Only able to read %ld bytes out %ld for %s file", module_name, 
read_size, file_size, file_path);
     ats_free(file_buf);
     file_buf = nullptr;
   }

Reply via email to