Skip to contentSkip to conversation

iputils: minor ninfod and ping6 fixes

PATCH In review Jan Synacek 2 participants 6 messages Dec 7, 2012 – Dec 19, 2012

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

cover iputils: minor ninfod and ping6 fixes

Hello,

When calling ping6 with the flowlabel (e.g. `ping6 -F 123 ::1'), it exited with an error. For some reason, the errno was set when it should not have been. Maybe it shouldn't be checked at all, maybe just checking flowlabel for values below zero would be enough. I wanted to be on the safer side so I left the errno check in there.

Also, I fixed the rest of the unused variables in ninfod.

Jan Synacek (2):
ninfod: Fix more unused variables.
ping6: Fix -F switch.

 ninfod/ni_ifaddrs.c | 8 +-------
 ping6.c             | 3 ++-
 2 files changed, 3 insertions(+), 8 deletions(-)
Signature · 1 line
1.8.0.1
#1 lore raw

PATCH 1/2 ninfod: Fix more unused variables.

| ni_ifaddrs.c: In function ‘ni_ifaddrs’:
| ni_ifaddrs.c:389:14: warning: variable ‘nlm_scope’ set but not used [-Wunused-but-set-variable]
| ni_ifaddrs.c:353:13: warning: variable ‘ifflist’ set but not used [-Wunused-but-set-variable]
| ni_ifaddrs.c:322:6: warning: variable ‘result’ set but not used [-Wunused-but-set-variable]
---
 ninfod/ni_ifaddrs.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
ninfod/ni_ifaddrs.c +1 -7
index 4225a5a..0820497 100644
@@ -319,7 +319,6 @@ int ni_ifaddrs(struct ni_ifaddrs **ifap, sa_family_t family)
 
 	pid_t pid = getpid();
 	int seq = 0;
-	int result;
 	int build;		/* 0 or 1 */
 
 /* ---------------------------------- */
@@ -350,7 +349,6 @@ int ni_ifaddrs(struct ni_ifaddrs **ifap, sa_family_t family)
 		struct ni_ifaddrs *ifl = NULL, *ifa = NULL;
 		struct nlmsghdr *nlh, *nlh0;
 		void *data = NULL, *xdata = NULL;
-		uint16_t *ifflist = NULL;
 #ifndef IFA_LOCAL
 		struct rtmaddr_ifamap ifamap;
 #endif
@@ -362,18 +360,15 @@ int ni_ifaddrs(struct ni_ifaddrs **ifap, sa_family_t family)
 				*ifap = ifa;
 			else {
 				free_data(data);
-				result = 0;
 				break;
 			}
 			if (data == NULL) {
 				free_data(data);
-				result = -1;
 				break;
 			}
 			ifl = NULL;
 			data += NLMSG_ALIGN(sizeof(struct ni_ifaddrs)) * icnt;
 			xdata = data + dlen;
-			ifflist = xdata + xlen;
 		}
 
 		for (nlm = nlmsg_list; nlm; nlm = nlm->nlm_next) {
@@ -386,7 +381,7 @@ int ni_ifaddrs(struct ni_ifaddrs **ifap, sa_family_t family)
 
 				size_t nlm_struct_size = 0;
 				sa_family_t nlm_family = 0;
-				uint32_t nlm_scope = 0, nlm_index = 0;
+				uint32_t nlm_index = 0;
 				unsigned int nlm_flags;
 				size_t rtasize;
 
@@ -405,7 +400,6 @@ int ni_ifaddrs(struct ni_ifaddrs **ifap, sa_family_t family)
 					ifam = (struct ifaddrmsg *) NLMSG_DATA(nlh);
 					nlm_struct_size = sizeof(*ifam);
 					nlm_family = ifam->ifa_family;
-					nlm_scope = ifam->ifa_scope;
 					nlm_index = ifam->ifa_index;
 					nlm_flags = ifam->ifa_flags;
 					if (family && nlm_family != family)
Signature · 1 line
1.8.0.1
#2 lore raw

PATCH 2/2 ping6: Fix -F switch.

In reply to Jan Synacek

Even when the flowlabel is set correctly, ping6 exits with a warning. For some reason, the errno is set when it should not be.

---
 ping6.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ping6.c +2 -1
index 358a035..85d3782 100644
@@ -725,7 +725,8 @@ int main(int argc, char *argv[])
 		switch(ch) {
 		case 'F':
 			flowlabel = hextoui(optarg);
-			if (errno || (flowlabel & ~IPV6_FLOWINFO_FLOWLABEL)) {
+			if ((flowlabel < 0 && errno) ||
+			    (flowlabel & ~IPV6_FLOWINFO_FLOWLABEL)) {
 				fprintf(stderr, "ping: Invalid flowinfo %s\n", optarg);
 				exit(2);
 			}
Signature · 1 line
1.8.0.1
#3 lore raw

Re: [PATCH 2/2] ping6: Fix -F switch.

Quoted 14 lines · Jan Synacek

Even when the flowlabel is set correctly, ping6 exits with a warning. For some reason, the errno is set when it should not be.

---
 ping6.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ping6.c +0 -0
index 358a035..85d3782 100644

ping6.c int main(int argc, char *argv[]) · line 732

Quoted 9 lines
ping6.c +2 -1
@@ -725,7 +725,8 @@ int main(int argc, char *argv[])
 		switch(ch) {
 		case 'F':
 			flowlabel = hextoui(optarg);
-			if (errno || (flowlabel & ~IPV6_FLOWINFO_FLOWLABEL)) {
+			if ((flowlabel < 0 && errno) ||
+			    (flowlabel & ~IPV6_FLOWINFO_FLOWLABEL)) {
 				fprintf(stderr, "ping: Invalid flowinfo %s\n", optarg);
 				exit(2);
 			}

This was well meant, but it doesn't work, because flowlabel is declared as __u32, therefore it can never be negative. I'm going to post a fixed version soon.

Signature · 2 lines
Jan Synacek
Software Engineer, BaseOS team Brno, Red Hat
#4 lore raw

Re: [PATCH 2/2 fixed] ping6: Fix -F switch.

Even when the flowlabel is set correctly, ping6 exits with a warning. The errno should be checked only if the previous call returned a negative value. In this case, there is no need to check errno, checking for a negative value is enough.

---
 ping6.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
ping6.c +3 -2
index 358a035..94a24b0 100644
@@ -724,8 +724,9 @@ int main(int argc, char *argv[])
 	while ((ch = getopt(argc, argv, COMMON_OPTSTR "F:N:")) != EOF) {
 		switch(ch) {
 		case 'F':
-			flowlabel = hextoui(optarg);
-			if (errno || (flowlabel & ~IPV6_FLOWINFO_FLOWLABEL)) {
+			err = hextoui(optarg);
+			flowlabel = (__u32)err;
+			if (err < 0 || (flowlabel & ~IPV6_FLOWINFO_FLOWLABEL)) {
 				fprintf(stderr, "ping: Invalid flowinfo %s\n", optarg);
 				exit(2);
 			}
Signature · 1 line
1.8.0.1
#5 lore raw
In reply to Jan Synacek
Quoted 8 lines · Jan Synacek

When calling ping6 with the flowlabel (e.g. `ping6 -F 123 ::1'), it exited with an error. For some reason, the errno was set when it should not have been. Maybe it shouldn't be checked at all, maybe just checking flowlabel for values below zero would be enough. I wanted to be on the safer side so I left the errno check in there.

Also, I fixed the rest of the unused variables in ninfod.

Quoted 8 lines

Jan Synacek (2):
ninfod: Fix more unused variables.
ping6: Fix -F switch.

 ninfod/ni_ifaddrs.c | 8 +-------
 ping6.c             | 3 ++-
 2 files changed, 3 insertions(+), 8 deletions(-)

Fixes committed. Thank you!

--yoshfuji