Mercurial > hg > freeDiameter
changeset 1442:915450ee91c7
fix gcc 9.1.1 compile warnings
Use snprintf instead of strncpy to ensure NUL termination.
Simplify attribute copying to calloc/memcpy instead
of malloc/memset/strncpy/assignment.
Appeases gcc 9.1.1 warnings about strncpy bounds.
author | Luke Mewburn <luke@mewburn.net> |
---|---|
date | Thu, 27 Feb 2020 16:19:24 +1100 |
parents | 6029afe9bacb |
children | ca7ca55e2488 |
files | extensions/app_diameap/diameap_server.c extensions/app_radgw/rgw_clients.c libfdproto/messages.c |
diffstat | 3 files changed, 8 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/extensions/app_diameap/diameap_server.c Tue Feb 25 10:42:08 2020 +1100 +++ b/extensions/app_diameap/diameap_server.c Thu Feb 27 16:19:24 2020 +1100 @@ -1960,22 +1960,16 @@ switch (*toadd) { case 1: - attribute_op = malloc(strlen(op)); - memset(attribute_op, 0, strlen(op)); - strncpy(attribute_op, op + 1, strlen(op) - 1); - attribute_op[strlen(op)] = '\0'; + attribute_op = calloc(strlen(op), sizeof(char *)); + memcpy(attribute_op, op + 1, strlen(op) - 1); break; case 2: - attribute_op = malloc(strlen(op)); - memset(attribute_op, 0, strlen(op)); - strncpy(attribute_op, op, strlen(op) - 1); - attribute_op[strlen(op)] = '\0'; + attribute_op = calloc(strlen(op), sizeof(char *)); + memcpy(attribute_op, op, strlen(op) - 1); break; default: - attribute_op = malloc(strlen(op) + 1); - memset(attribute_op, 0, strlen(op) + 1); - strcpy(attribute_op, op); - attribute_op[strlen(op) + 1] = '\0'; + attribute_op = calloc(strlen(op) + 1, sizeof(char *)); + memcpy(attribute_op, op, strlen(op)); } if (strcmp(attribute_op, "=") == 0) {
--- a/extensions/app_radgw/rgw_clients.c Tue Feb 25 10:42:08 2020 +1100 +++ b/extensions/app_radgw/rgw_clients.c Thu Feb 27 16:19:24 2020 +1100 @@ -763,7 +763,7 @@ hint.ai_flags = AI_CANONNAME; ret = getaddrinfo(buf, NULL, &hint, &res); if (ret == 0) { - strncpy(buf, res->ai_canonname, sizeof(buf)); + snprintf(buf, sizeof(buf), "%s", res->ai_canonname); /* The name was resolved correctly, does it match the IP of the client? */ for (ptr = res; ptr != NULL; ptr = ptr->ai_next) { if (cli->sa->sa_family != ptr->ai_family)
--- a/libfdproto/messages.c Tue Feb 25 10:42:08 2020 +1100 +++ b/libfdproto/messages.c Thu Feb 27 16:19:24 2020 +1100 @@ -2234,7 +2234,7 @@ if (error_info) { error_info->pei_errcode = "DIAMETER_INVALID_AVP_VALUE"; error_info->pei_avp = avp; - strncpy(error_message, err, sizeof(error_message)); + snprintf(error_message, sizeof(error_message), "%s", err); error_info->pei_message = error_message; } else { char * buf = NULL;