]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/commitdiff
rtnl fd check
authorStephen Hemminger <shemminger@osdl.org>
Tue, 26 Sep 2006 17:41:57 +0000 (10:41 -0700)
committerStephen Hemminger <shemminger@osdl.org>
Tue, 26 Sep 2006 17:41:57 +0000 (10:41 -0700)
Prevent accidental damage from rtnl library if fd is uninitialized.

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
ip/ip.c
lib/libnetlink.c

diff --git a/ip/ip.c b/ip/ip.c
index c29d2f31f94184590e11fda3d60ae9b64855b825..091e9ef208cc35f556b9e13a20fcc99f88c6d235 100644 (file)
--- a/ip/ip.c
+++ b/ip/ip.c
@@ -36,7 +36,7 @@ int timestamp = 0;
 char * _SL_ = NULL;
 char *batch_file = NULL;
 int force = 0;
-struct rtnl_handle rth;
+struct rtnl_handle rth = { .fd = -1 };
 
 static void usage(void) __attribute__((noreturn));
 
index 67951fe7d768398bee7d7c283e90e96d2b7f7ce5..5c6a4dc4b193e7b6da426993809f32eea47a3e0b 100644 (file)
 
 void rtnl_close(struct rtnl_handle *rth)
 {
-       close(rth->fd);
+       if (rth->fd >= 0) {
+               close(rth->fd);
+               rth->fd = -1;
+       }
 }
 
 int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions,