summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-02-23 16:55:53 -0800
committerBen Longbons <b.r.longbons@gmail.com>2013-02-23 16:55:53 -0800
commit2d226bd3e09417d8f2cf60d92c92b0dd437e4230 (patch)
tree0ae872d55f95d33ce8fe795cbdb3674d0a522302
parent1e77f5dc8d95bbf912205c85274d294a80ea65c9 (diff)
downloadtmwa-2d226bd3e09417d8f2cf60d92c92b0dd437e4230.tar.gz
tmwa-2d226bd3e09417d8f2cf60d92c92b0dd437e4230.tar.bz2
tmwa-2d226bd3e09417d8f2cf60d92c92b0dd437e4230.tar.xz
tmwa-2d226bd3e09417d8f2cf60d92c92b0dd437e4230.zip
Fix buffer overflow due to off-by-one error
-rw-r--r--src/common/utils.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/common/utils.cpp b/src/common/utils.cpp
index bd82180..33a96b4 100644
--- a/src/common/utils.cpp
+++ b/src/common/utils.cpp
@@ -122,17 +122,20 @@ bool split_key_value(const std::string& line, std::string *w1, std::string *w2)
return true;
}
+static_assert(sizeof(timestamp_seconds_buffer) == 20, "seconds buffer");
+static_assert(sizeof(timestamp_milliseconds_buffer) == 24, "millis buffer");
+
void stamp_time(timestamp_seconds_buffer& out, time_t *t)
{
time_t when = t ? *t : time(NULL);
- strftime(out, sizeof(out), "%Y-%m-%d %H:%M:%S", gmtime(&when));
+ strftime(out, 20, "%Y-%m-%d %H:%M:%S", gmtime(&when));
}
void stamp_time(timestamp_milliseconds_buffer& out)
{
struct timeval tv;
gettimeofday(&tv, NULL);
- strftime(out, sizeof(out), "%Y-%m-%d %H:%M:%S", gmtime(&tv.tv_sec));
- sprintf(out + 20, ".%03d", int(tv.tv_usec / 1000));
+ strftime(out, 20, "%Y-%m-%d %H:%M:%S", gmtime(&tv.tv_sec));
+ sprintf(out + 19, ".%03d", int(tv.tv_usec / 1000));
}
void log_with_timestamp(FILE *out, const_string line)