sockets: avoid formatting buffer that may not be NULL terminated
PATCH 1/1 sockets: avoid formatting buffer that may not be NULL terminated
The 'sun_path' field in the sockaddr_un struct is not required to be NULL 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
@@ -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
Quoted 2 lines · Daniel P. Berrange
The '
sun_path' field in thesockaddr_unstruct is not required to be NULL termianted, so when reporting an error, we must use
s/NULL/NUL/
NULL is a pointer, NUL is the '\0' character.
Quoted 20 lines
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 +0100sockets: improve error reporting if UNIX socket path is too long
Signed-off-by Daniel P. Berrange <[email protected]>--- util/qemu-sockets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)util/qemu-sockets.c +0
-0
util/qemu-sockets.c static int unix_listen_saddr(UnixSocketAddress *saddr, · line 936
Quoted 8 lines
util/qemu-sockets.c +1
-1@@ -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 ) {
Apart from the nit in the comment, the patch looks right to me:
Quoted 7 lines · Thomas Huth
Quoted 2 lines · Daniel P. Berrange
The '
sun_path' field in thesockaddr_unstruct is not required to be NULL termianted, so when reporting an error, we must uses/NULL/NUL/
NULL is a pointer, NUL is the '\0' character.
I wanted to point out the same thing to someone recently, so I chased up a reference to the NUL character in RFC 20 "ASCII format for Network Interchange". After all, no one can argue with an RFC.
What I found shocked me! There must be a typo in the ASCII RFC:
https://tools.ietf.org/html/rfc20#section-5.2
I closed my browser tab quickly and headed to Wikipedia instead. If the primary source didn't support my argument, I could always count on good old Wikipedia...
But do you know what I found? Someone had conflated nul and null on the Wikipedia entry:
https://en.wikipedia.org/wiki/Null_character
Amateurs! The Wikipedia editors probably didn't have the intellectual calibre to question the correctness of the RFC text the way I did.
But to cut a long story short, as my search continued the evidence became overwhelming. It is acceptable to refer to the nul character as the null character.
Coming back to the patch in question, although we can't complain about the "NULL" it's with considerable joy that I'd like to highlight:
s/termianted/terminated/
:)
Stefan
Quoted 24 lines · Stefan Hajnoczi
Quoted 7 lines · Thomas Huth
Quoted 2 lines · Daniel P. Berrange
The '
sun_path' field in thesockaddr_unstruct is not required to be NULL termianted, so when reporting an error, we must uses/NULL/NUL/
NULL is a pointer, NUL is the '\0' character.
I wanted to point out the same thing to someone recently, so I chased up a reference to the NUL character in RFC 20 "ASCII format for Network Interchange". After all, no one can argue with an RFC.
What I found shocked me! There must be a typo in the ASCII RFC:
https://tools.ietf.org/html/rfc20#section-5.2I closed my browser tab quickly and headed to Wikipedia instead. If the primary source didn't support my argument, I could always count on good old Wikipedia...
But do you know what I found? Someone had conflated nul and null on the Wikipedia entry:
https://en.wikipedia.org/wiki/Null_character
Quoted 6 lines
Amateurs! The Wikipedia editors probably didn't have the intellectual calibre to question the correctness of the RFC text the way I did.
But to cut a long story short, as my search continued the evidence became overwhelming. It is acceptable to refer to the nul character as the null character.
Well, I don't see a real problem here - as long as you write "null" with lowercase letters. "NULL" with uppercase letters is the pointer. "NUL" with uppercase letters is the character. And "null" with lowercase letters is just a context-sensitive word :-)
Thomas
Quoted 31 lines · Stefan Hajnoczi
Quoted 7 lines · Thomas Huth
Quoted 2 lines · Daniel P. Berrange
The '
sun_path' field in thesockaddr_unstruct is not required to be NULL termianted, so when reporting an error, we must uses/NULL/NUL/
NULL is a pointer, NUL is the '\0' character.
I wanted to point out the same thing to someone recently, so I chased up a reference to the NUL character in RFC 20 "ASCII format for Network Interchange". After all, no one can argue with an RFC.
What I found shocked me! There must be a typo in the ASCII RFC:
https://tools.ietf.org/html/rfc20#section-5.2I closed my browser tab quickly and headed to Wikipedia instead. If the primary source didn't support my argument, I could always count on good old Wikipedia...
But do you know what I found? Someone had conflated nul and null on the Wikipedia entry:
https://en.wikipedia.org/wiki/Null_characterAmateurs! The Wikipedia editors probably didn't have the intellectual calibre to question the correctness of the RFC text the way I did.
But to cut a long story short, as my search continued the evidence became overwhelming. It is acceptable to refer to the nul character as the null character.
Quoted 7 lines
Coming back to the patch in question, although we can't complain about the "NULL" it's with considerable joy that I'd like to highlight:
s/termianted/terminated/
:)
Stefan
Despite this shocking, shocking precedence, I formally object to the use of NULL in the context of C for anything other than "one particular null pointer". C's confusing enough without overloading identifiers.
Quoted 10 lines · Daniel P. Berrange
The '
sun_path' field in thesockaddr_unstruct is not required to be NULL 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
Quoted 6 lines
sockets: improve error reporting if UNIX socket path is too long
Signed-off-by Daniel P. Berrange <[email protected]>--- util/qemu-sockets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)