Skip to contentSkip to conversation

statd: Teach nfs_compare_sockaddr() to handle NULL arguments.

PATCH In review Steve Dickson 2 participants 4 messages Jan 25, 2010 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 statd: Teach nfs_compare_sockaddr() to handle NULL arguments.

It seems the list of interfaces returned by getifaddrs() can contain a null address pointer (ifa->ifa_addr) even though the interface is marked UP (this happens with the tun0 interface).

So this patch makes nfs_compare_sockaddr() return false if either one of its arguments is null..

Author: Steve Dickson <[email protected]>
Date:   Mon Jan 25 11:42:36 2010 -0500

Teach nfs_compare_sockaddr() to handle NULL arguments.

support/include/sockaddr.h +4 -0
index 732514b..9af2543 100644
@@ -20,6 +20,7 @@
 #ifndef NFS_UTILS_SOCKADDR_H
 #define NFS_UTILS_SOCKADDR_H
 
+#include <libio.h>
 #include <stdbool.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -223,6 +224,9 @@ compare_sockaddr6(__attribute__ ((unused)) const struct sockaddr *sa1,
 static inline _Bool
 nfs_compare_sockaddr(const struct sockaddr *sa1, const struct sockaddr *sa2)
 {
+	if (sa1 == NULL || sa2 == NULL)
+		return false;
+
 	if (sa1->sa_family == sa2->sa_family)
 		switch (sa1->sa_family) {
 		case AF_INET:
Reviewed-by
#2 lore raw
In reply to a message not in the archive
Quoted 3 lines · Steve Dickson

It seems the list of interfaces returned by getifaddrs() can contain a null address pointer (ifa->ifa_addr) even though the interface is marked UP (this happens with the tun0 interface).

It might be nice to document this quirk in from_local.c.

Quoted 9 lines

So this patch makes nfs_compare_sockaddr() return false if either one of its arguments is null..

Author: Steve Dickson <[email protected]>
Date:   Mon Jan 25 11:42:36 2010 -0500

Teach nfs_compare_sockaddr() to handle NULL arguments.

Quoted 27 lines
support/include/sockaddr.h +1 -0
index 732514b..9af2543 100644
@@ -20,6 +20,7 @@
 #ifndef NFS_UTILS_SOCKADDR_H
 #define NFS_UTILS_SOCKADDR_H
 
+#include <libio.h>
 #include <stdbool.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -223,6 +224,9 @@ compare_sockaddr6(__attribute__ ((unused)) const  
 struct sockaddr *sa1,

static inline _Bool
nfs_compare_sockaddr(const struct sockaddr *sa1, const struct sockaddr *sa2) {

support/include/sockaddr.h +3 -0
+	if (sa1 == NULL || sa2 == NULL)
+		return false;
+
	if (sa1->sa_family == sa2->sa_family)
		switch (sa1->sa_family) {
		case AF_INET:

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
#4 lore raw
In reply to a message not in the archive
Quoted 7 lines · Steve Dickson

It seems the list of interfaces returned by getifaddrs() can contain a null address pointer (ifa->ifa_addr) even though the interface is marked UP (this happens with the tun0 interface).

So this patch makes nfs_compare_sockaddr() return false if either one of its arguments is null..

Committed...

steved.

#3 lore raw
In reply to Chuck Lever
Quoted 10 lines · Chuck Lever
Quoted 3 lines · Steve Dickson

It seems the list of interfaces returned by getifaddrs() can contain a null address pointer (ifa->ifa_addr) even though the interface is marked UP (this happens with the tun0 interface).

It might be nice to document this quirk in from_local.c.

Quoted 3 lines

So this patch makes nfs_compare_sockaddr() return false if either one of its arguments is null..

Quoted 8 lines
Quoted 6 lines
Author: Steve Dickson <[email protected]>
Date:   Mon Jan 25 11:42:36 2010 -0500

Teach nfs_compare_sockaddr() to handle NULL arguments.

Hrm. On second thought....

Catching these in nfs_compare_sockaddr() will make it harder to find NULL pointer bugs in other parts of the code, I would think. Instead, maybe you should trap these in from_local.c. That way you document the quirk (as above) as well.

Quoted 39 lines
Quoted 27 lines
support/include/sockaddr.h +1 -0
index 732514b..9af2543 100644
@@ -20,6 +20,7 @@
 #ifndef NFS_UTILS_SOCKADDR_H
 #define NFS_UTILS_SOCKADDR_H
 
+#include <libio.h>
 #include <stdbool.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -223,6 +224,9 @@ compare_sockaddr6(__attribute__ ((unused))  
 const struct sockaddr *sa1,

static inline _Bool
nfs_compare_sockaddr(const struct sockaddr *sa1, const struct sockaddr *sa2) {

support/include/sockaddr.h +3 -0
+	if (sa1 == NULL || sa2 == NULL)
+		return false;
+
	if (sa1->sa_family == sa2->sa_family)
		switch (sa1->sa_family) {
		case AF_INET:

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 10 lines
Chuck Lever
chuck[dot]lever[at]oracle[dot]com




--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Chuck Lever
chuck[dot]lever[at]oracle[dot]com