Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverity: Several Overflowed integer argument fixes #11879

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/proxy/logging/Log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/traffic_logcat/logcat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions src/tscore/MatcherUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down