- Do not segfault if the ipv6 kernel module is not loaded (#486097)

This commit is contained in:
David Cantrell 2009-02-18 21:24:21 +00:00
parent 0adb5fbf9e
commit f81c3f9d11

View File

@ -1,21 +1,36 @@
diff -up dhcp-4.1.0/common/discover.c.noipv6 dhcp-4.1.0/common/discover.c diff -up dhcp-4.1.0/common/discover.c.noipv6 dhcp-4.1.0/common/discover.c
--- dhcp-4.1.0/common/discover.c.noipv6 2009-02-18 09:40:45.000000000 -1000 --- dhcp-4.1.0/common/discover.c.noipv6 2009-02-18 10:44:20.000000000 -1000
+++ dhcp-4.1.0/common/discover.c 2009-02-18 09:43:53.000000000 -1000 +++ dhcp-4.1.0/common/discover.c 2009-02-18 10:48:27.000000000 -1000
@@ -447,9 +447,11 @@ begin_iface_scan(struct iface_conf_list @@ -443,15 +443,19 @@ begin_iface_scan(struct iface_conf_list
if (ifaces->fp6 == NULL) {
log_error("Error opening '/proc/net/if_inet6' to "
"list IPv6 interfaces; %m");
- close(ifaces->sock);
+ if (ifaces->sock)
+ close(ifaces->sock);
ifaces->sock = -1;
- fclose(ifaces->fp);
+ if (ifaces->fp)
+ fclose(ifaces->fp);
ifaces->fp = NULL;
return 0;
} }
@@ -719,7 +721,7 @@ next_iface(struct iface_info *info, int
#ifdef DHCPv6
- ifaces->fp6 = fopen("/proc/net/if_inet6", "re");
- if (ifaces->fp6 == NULL) {
- log_error("Error opening '/proc/net/if_inet6' to "
- "list IPv6 interfaces; %m");
- close(ifaces->sock);
- ifaces->sock = -1;
- fclose(ifaces->fp);
- ifaces->fp = NULL;
- return 0;
+ if (!access("/proc/net/if_inet6", R_OK)) {
+ ifaces->fp6 = fopen("/proc/net/if_inet6", "re");
+ if (ifaces->fp6 == NULL) {
+ log_error("Error opening '/proc/net/if_inet6' to "
+ "list IPv6 interfaces; %m");
+ close(ifaces->sock);
+ ifaces->sock = -1;
+ fclose(ifaces->fp);
+ ifaces->fp = NULL;
+ return 0;
+ }
+ } else {
+ ifaces->fp6 = NULL;
}
#endif
@@ -719,7 +723,7 @@ next_iface(struct iface_info *info, int
return 1; return 1;
} }
#ifdef DHCPv6 #ifdef DHCPv6
@ -24,7 +39,7 @@ diff -up dhcp-4.1.0/common/discover.c.noipv6 dhcp-4.1.0/common/discover.c
return next_iface6(info, err, ifaces); return next_iface6(info, err, ifaces);
} }
#endif #endif
@@ -736,7 +738,8 @@ end_iface_scan(struct iface_conf_list *i @@ -736,7 +740,8 @@ end_iface_scan(struct iface_conf_list *i
close(ifaces->sock); close(ifaces->sock);
ifaces->sock = -1; ifaces->sock = -1;
#ifdef DHCPv6 #ifdef DHCPv6