fix potential unterminated buffer and leak on failure

This commit is contained in:
Richard Frith-Macdonald 2018-01-30 07:43:58 +00:00
parent b76089f0cd
commit 65ac0eca15
2 changed files with 2 additions and 1 deletions

View file

@ -1282,7 +1282,7 @@ typedef struct {
memset(&sockAddr, '\0', sizeof(sockAddr));
sockAddr.sun_family = AF_LOCAL;
strncpy(sockAddr.sun_path, (char*)socketName,
sizeof(sockAddr.sun_path));
sizeof(sockAddr.sun_path) - 1);
if ((desc = socket(PF_LOCAL, SOCK_STREAM, PF_UNSPEC)) < 0)
{
NSLog(@"unable to create socket - %@", [NSError _last]);

View file

@ -375,6 +375,7 @@ static NSMapTable *portToNamesMap;
}
if (connect(desc, (struct sockaddr*)&sockAddr, SUN_LEN(&sockAddr)) < 0)
{
close(desc);
unlink([path fileSystemRepresentation]);
unlink(socket_path);
NSDebugLLog(@"NSMessagePort", @"not live, can't connect (%m)");