Skip to contentSkip to conversation

sockets: avoid formatting buffer that may not be NUL terminated

PATCH Applied Daniel P. Berrange 3 participants 3 messages Jun 26, 2017 – Jun 27, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sockets: avoid formatting buffer that may not be NUL terminated

The 'sun_path' field in the sockaddr_un struct is not required to be NUL termianted, so when reporting an error, we must use the separate 'path' variable which is guaranteed terminated.

Fixes a bug spotted by coverity that was introduced in

commit ad9579aaa16d5b385922d49edac2c96c79bcfb62
Author: Daniel P. Berrange <[email protected]>
Date: Thu May 25 16:53:00 2017 +0100

sockets: improve error reporting if UNIX socket path is too long

---
 util/qemu-sockets.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
util/qemu-sockets.c +1 -1
index 51bf279..37d386f 100644
@@ -930,7 +930,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
     strncpy(un.sun_path, path, sizeof(un.sun_path));
 
     if (bind(sock, (struct sockaddr*) &un, sizeof(un)) < 0) {
-        error_setg_errno(errp, errno, "Failed to bind socket to %s", un.sun_path);
+        error_setg_errno(errp, errno, "Failed to bind socket to %s", path);
         goto err;
     }
     if (listen(sock, 1) < 0) {
Signature · 1 line
2.9.3
Reviewed-by on v2 1/1
#1 lore raw
Quoted 2 lines · Daniel P. Berrange

The 'sun_path' field in the sockaddr_un struct is not required to be NUL termianted, so when reporting an error, we must use

"terminated", but hopefully whoever applies the patch can fix the typo?

Quoted 4 lines

the separate 'path' variable which is guaranteed terminated.

Fixes a bug spotted by coverity that was introduced in

Quoted 8 lines

commit ad9579aaa16d5b385922d49edac2c96c79bcfb62
Author: Daniel P. Berrange <[email protected]>
Date: Thu May 25 16:53:00 2017 +0100

sockets: improve error reporting if UNIX socket path is too long

thanks
-- PMM