Skip to content

Commit 6552543

Browse files
authored
Merge pull request #4961 from jsquyres/pr/cid-1430413-fix
util/fd: fix CID 1430413
2 parents 871e5c7 + 06ec93a commit 6552543

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

opal/util/fd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ bool opal_fd_is_blkdev(int fd)
138138
const char *opal_fd_get_peer_name(int fd)
139139
{
140140
char *str;
141-
const char *ret;
141+
const char *ret = NULL;
142142
struct sockaddr sa;
143143
socklen_t slt = (socklen_t) sizeof(sa);
144144

@@ -152,7 +152,7 @@ const char *opal_fd_get_peer_name(int fd)
152152
#if OPAL_ENABLE_IPV6
153153
len = INET6_ADDRSTRLEN;
154154
#endif
155-
str = malloc(len);
155+
str = calloc(1, len);
156156
if (NULL == str) {
157157
return NULL;
158158
}
@@ -176,7 +176,9 @@ const char *opal_fd_get_peer_name(int fd)
176176
}
177177
#endif
178178
else {
179+
// This string is guaranteed to be <= INET_ADDRSTRLEN
179180
strncpy(str, "Unknown", len);
181+
ret = str;
180182
}
181183

182184
return ret;

0 commit comments

Comments
 (0)