Skip to content

Commit

Permalink
Fix max length of node description (ibnetdiscover and smpquery)
Browse files Browse the repository at this point in the history
Both utilities truncate node description up to 63 bytes instead 64 bytes.
Node description fields declared as char array of IB_SMP_DATA_SIZE bytes.
Last character for compatibility with c-string set to zero.
In this case node description will be truncated from 64 bytes to 63 bytes.
Size of node description fields was enlarged to the IB_SMP_DATA_SIZE + 1 bytes for using last character for zero char without truncated node description

Signed-off-by: Gregory Linschitz <[email protected]>
  • Loading branch information
gregoryl-mlnx committed Oct 19, 2022
1 parent 20380d3 commit d974c4e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion infiniband-diags/smpquery.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static const char *node_desc(ib_portid_t *dest, char **argv, int argc)
{
int node_type, l;
uint64_t node_guid;
char nd[IB_SMP_DATA_SIZE] = { 0 };
char nd[IB_SMP_DATA_SIZE + 1] = { 0 };
uint8_t data[IB_SMP_DATA_SIZE] = { 0 };
char dots[128];
char *nodename = NULL;
Expand Down
2 changes: 1 addition & 1 deletion libibnetdisc/ibnetdisc.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ typedef struct ibnd_node {
/* use libibmad decoder functions for info */
uint8_t info[IB_SMP_DATA_SIZE];

char nodedesc[IB_SMP_DATA_SIZE];
char nodedesc[IB_SMP_DATA_SIZE + 1];

struct ibnd_port **ports; /* array of ports, indexed by port number
ports[1] == port 1,
Expand Down
4 changes: 3 additions & 1 deletion util/node_name_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include <ctype.h>
#include <errno.h>

#include <infiniband/mad.h>

#include <ccan/minmax.h>

#include <util/node_name_map.h>
Expand Down Expand Up @@ -115,7 +117,7 @@ char *clean_nodedesc(char *nodedesc)
{
int i = 0;

nodedesc[63] = '\0';
nodedesc[IB_SMP_DATA_SIZE] = '\0';
while (nodedesc[i]) {
if (!isprint(nodedesc[i]))
nodedesc[i] = ' ';
Expand Down

0 comments on commit d974c4e

Please sign in to comment.