diff options
author | Felix Weinrank <weinrank@fh-muenster.de> | 2020-05-12 13:44:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-12 13:44:29 +0200 |
commit | a5f8b654ecda961e013b29695814dd1f2a9ae13b (patch) | |
tree | ad51d68a85622958a426c59779afd444384a0db8 | |
parent | d893e474165167ae47bf993c83327d22a1b2f4e7 (diff) | |
download | usrsctp-a5f8b654ecda961e013b29695814dd1f2a9ae13b.tar.gz |
fix truncated writing warning (#464)
-rwxr-xr-x | usrsctplib/user_socket.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/usrsctplib/user_socket.c b/usrsctplib/user_socket.c index 146a6d9f..b9e87ec2 100755 --- a/usrsctplib/user_socket.c +++ b/usrsctplib/user_socket.c @@ -3405,21 +3405,30 @@ usrsctp_dumppacket(const void *buf, size_t len, int outbound) ftime(&tb); localtime_s(&t, &tb.time); #if defined(__MINGW32__) - snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT, - outbound ? 'O' : 'I', - t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm)); + if (snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT, + outbound ? 'O' : 'I', + t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm)) < 0) { + free(dump_buf); + return (NULL); + } #else - _snprintf_s(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_LENGTH, PREAMBLE_FORMAT, - outbound ? 'O' : 'I', - t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm)); + if (_snprintf_s(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_LENGTH, PREAMBLE_FORMAT, + outbound ? 'O' : 'I', + t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm)) < 0) { + free(dump_buf); + return (NULL); + } #endif #else gettimeofday(&tv, NULL); sec = (time_t)tv.tv_sec; localtime_r((const time_t *)&sec, &t); - snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT, - outbound ? 'O' : 'I', - t.tm_hour, t.tm_min, t.tm_sec, (long)tv.tv_usec); + if (snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT, + outbound ? 'O' : 'I', + t.tm_hour, t.tm_min, t.tm_sec, (long)tv.tv_usec) < 0) { + free(dump_buf); + return (NULL); + } #endif pos += PREAMBLE_LENGTH; #if defined(_WIN32) && !defined(__MINGW32__) |