# HG changeset patch # User Luke Mewburn # Date 1582780764 -39600 # Node ID 915450ee91c7a1858e61a680504d6820503bcded # Parent 6029afe9bacbd9e10c4f2561c0fb38f6982ea956 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. diff -r 6029afe9bacb -r 915450ee91c7 extensions/app_diameap/diameap_server.c --- 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) { diff -r 6029afe9bacb -r 915450ee91c7 extensions/app_radgw/rgw_clients.c --- 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) diff -r 6029afe9bacb -r 915450ee91c7 libfdproto/messages.c --- 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;