Skip to content

Commit

Permalink
ibacm: Ensure strings are NULL terminated
Browse files Browse the repository at this point in the history
The 'data' and 'string_buf' string is often used in debugging prints,
ensure it is always NULL terminated.

Fixes gcc 10 warnings:

 In function 'strncpy',
     inlined from 'acm_format_ep_addr' at ../ibacm/src/libacm.c:205:3:
 /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error: '__builtin_strncpy' specified bound 64 equals destination size [-Werror=stringop-truncation]

In function 'strncpy',
    inlined from '__acm_ep_insert_addr' at ../ibacm/src/acm.c:2119:2,
    inlined from 'acm_ep_insert_addr' at ../ibacm/src/acm.c:2140:9:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: error: '__builtin_strncpy' specified bound 64 equals destination size [-Werror=stringop-truncation]

Signed-off-by: Jason Gunthorpe <[email protected]>
  • Loading branch information
jgunthorpe committed May 5, 2020
1 parent 457b345 commit 224b03c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion ibacm/src/acm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,9 @@ __acm_ep_insert_addr(struct acmc_ep *ep, const char *name, uint8_t *addr,
}
}
ep->addr_info[i].addr.type = addr_type;
strncpy(ep->addr_info[i].string_buf, name, ACM_MAX_ADDRESS);
if (!check_snprintf(ep->addr_info[i].string_buf,
sizeof(ep->addr_info[i].string_buf), "%s", name))
return EINVAL;
memcpy(ep->addr_info[i].addr.info.addr, tmp, ACM_MAX_ADDRESS);
ret = ep->port->prov->add_address(&ep->addr_info[i].addr,
ep->prov_ep_context,
Expand Down
6 changes: 5 additions & 1 deletion ibacm/src/libacm.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <sys/socket.h>
#include <sys/un.h>

#include <util/util.h>

static pthread_mutex_t acm_lock = PTHREAD_MUTEX_INITIALIZER;
static int sock = -1;
static short server_port = 6125;
Expand Down Expand Up @@ -202,7 +204,9 @@ static int acm_format_ep_addr(struct acm_ep_addr_data *data, uint8_t *addr,

switch (type) {
case ACM_EP_INFO_NAME:
strncpy((char *) data->info.name, (char *) addr, ACM_MAX_ADDRESS);
if (!check_snprintf((char *)data->info.name,
sizeof(data->info.name), "%s", (char *)addr))
return -1;
break;
case ACM_EP_INFO_ADDRESS_IP:
memcpy(data->info.addr, &((struct sockaddr_in *) addr)->sin_addr, 4);
Expand Down

0 comments on commit 224b03c

Please sign in to comment.