Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions os/Xtranssock.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ set_sun_path(const char *port, const char *upath, char *path, int abstract)
struct sockaddr_un s;
ssize_t maxlen = sizeof(s.sun_path) - 1;
const char *at = "";

char * buf;
if (!port || !*port || !path)
return -1;

Expand All @@ -638,7 +638,11 @@ set_sun_path(const char *port, const char *upath, char *path, int abstract)

if ((ssize_t)(strlen(at) + strlen(upath) + strlen(port)) > maxlen)
return -1;
snprintf(path, sizeof(s.sun_path), "%s%s%s", at, upath, port);

asprintf(&buf, "%s%s%s", at, upath, port);
strncpy(path, buf, sizeof(s.sun_path)-1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is doing needless copies and filling the buffer with extra 0 bytes.

s.sun_path[sizeof(s.sun_path)-1] = '\0';
free(buf);
return 0;
}
#endif
Expand Down