From: Stephen Hemminger Date: Tue, 26 Sep 2006 17:41:57 +0000 (-0700) Subject: rtnl fd check X-Git-Tag: v2.6.19-061214~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3bfa73ff99291d872f6d0e0284ee416e880088b6;p=thirdparty%2Fiproute2.git rtnl fd check Prevent accidental damage from rtnl library if fd is uninitialized. Signed-off-by: Stephen Hemminger --- diff --git a/ip/ip.c b/ip/ip.c index c29d2f31f..091e9ef20 100644 --- 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)); diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 67951fe7d..5c6a4dc4b 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -27,7 +27,10 @@ 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,