INN commit: trunk/tests (Makefile lib/date-t.c)
INN Commit
rra at isc.org
Thu Dec 24 21:56:07 UTC 2020
Date: Thursday, December 24, 2020 @ 13:56:06
Author: eagle
Revision: 10463
Fix GCC warnings in tests/lib/date-t.c
GCC 10.2.1 rightfully complains that the snprintf invocations
in this test may overflow the buffer length and truncate. Use
basprintf instead to avoid having to size buffers.
Modified:
trunk/tests/Makefile
trunk/tests/lib/date-t.c
--------------+
Makefile | 4 ++--
lib/date-t.c | 26 +++++++++++++++-----------
2 files changed, 17 insertions(+), 13 deletions(-)
Modified: Makefile
===================================================================
--- Makefile 2020-12-23 22:45:44 UTC (rev 10462)
+++ Makefile 2020-12-24 21:56:06 UTC (rev 10463)
@@ -108,8 +108,8 @@
$(LINK) $(LIBM_LDFLAGS) lib/confparse-t.o tap/basic.o tap/float.o \
tap/messages.o tap/string.o $(LIBINN)
-lib/date.t: lib/date-t.o tap/basic.o $(LIBINN)
- $(LINK) lib/date-t.o tap/basic.o $(LIBINN)
+lib/date.t: lib/date-t.o tap/basic.o tap/string.o $(LIBINN)
+ $(LINK) lib/date-t.o tap/basic.o tap/string.o $(LIBINN)
lib/dispatch.t: lib/dispatch-t.o tap/basic.o $(LIBINN)
$(LINK) lib/dispatch-t.o tap/basic.o $(LIBINN)
Modified: lib/date-t.c
===================================================================
--- lib/date-t.c 2020-12-23 22:45:44 UTC (rev 10462)
+++ lib/date-t.c 2020-12-24 21:56:06 UTC (rev 10463)
@@ -7,6 +7,7 @@
#include "inn/libinn.h"
#include "tap/basic.h"
+#include "tap/string.h"
static const time_t test_times[] = {
28800UL, /* Thu, 1 Jan 1970 00:00:00 -0800 (PST) */
@@ -100,26 +101,29 @@
static void
check_nntp(int *n, time_t timestamp)
{
- char date[9], hour[7];
+ char *date, *hour;
struct tm *tmp_tm, tm;
tmp_tm = localtime(×tamp);
tm = *tmp_tm;
- snprintf(date, sizeof(date), "%02d%02d%02d",
- tm.tm_year % 100, tm.tm_mon + 1, tm.tm_mday);
- snprintf(hour, sizeof(hour), "%02d%02d%02d",
- tm.tm_hour, tm.tm_min, tm.tm_sec);
+ basprintf(&date, "%02d%02d%02d",
+ tm.tm_year % 100, tm.tm_mon + 1, tm.tm_mday);
+ basprintf(&hour, "%02d%02d%02d", tm.tm_hour, tm.tm_min, tm.tm_sec);
ok_nntp((*n)++, timestamp, date, hour, true);
- snprintf(date, sizeof(date), "%04d%02d%02d",
- tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
+ free(date);
+ basprintf(&date, "%04d%02d%02d",
+ tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
ok_nntp((*n)++, timestamp, date, hour, true);
+ free(date);
+ free(hour);
tmp_tm = gmtime(×tamp);
tm = *tmp_tm;
- snprintf(date, sizeof(date), "%04d%02d%02d",
- tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
- snprintf(hour, sizeof(hour), "%02d%02d%02d",
- tm.tm_hour, tm.tm_min, tm.tm_sec);
+ basprintf(&date, "%04d%02d%02d",
+ tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
+ basprintf(&hour, "%02d%02d%02d", tm.tm_hour, tm.tm_min, tm.tm_sec);
ok_nntp((*n)++, timestamp, date, hour, false);
+ free(date);
+ free(hour);
}
static void
More information about the inn-committers
mailing list