mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 17:35:06 -05:00
util: indicate truncated Unix socket path in UTI_SockaddrToString()
Specify the maximum length of the path in the snprintf() format to avoid a new gcc warning (-Wformat-truncation). If the path doesn't fit in the buffer, indicate with the '>' symbol that it was truncated. The function is used only for debug messages.
This commit is contained in:
8
util.c
8
util.c
@@ -558,7 +558,7 @@ char *UTI_SockaddrToString(struct sockaddr *sa)
|
||||
{
|
||||
unsigned short port;
|
||||
IPAddr ip;
|
||||
char *result;
|
||||
char *result, *sun_path;
|
||||
|
||||
result = NEXT_BUFFER;
|
||||
|
||||
@@ -571,7 +571,11 @@ char *UTI_SockaddrToString(struct sockaddr *sa)
|
||||
snprintf(result, BUFFER_LENGTH, "%s:%hu", UTI_IPToString(&ip), port);
|
||||
break;
|
||||
case AF_UNIX:
|
||||
snprintf(result, BUFFER_LENGTH, "%s", ((struct sockaddr_un *)sa)->sun_path);
|
||||
sun_path = ((struct sockaddr_un *)sa)->sun_path;
|
||||
snprintf(result, BUFFER_LENGTH, "%.*s", BUFFER_LENGTH - 1, sun_path);
|
||||
/* Indicate truncated path */
|
||||
if (strlen(sun_path) >= BUFFER_LENGTH)
|
||||
result[BUFFER_LENGTH - 2] = '>';
|
||||
break;
|
||||
default:
|
||||
snprintf(result, BUFFER_LENGTH, "[UNKNOWN]");
|
||||
|
||||
Reference in New Issue
Block a user