On Thu, Feb 23, 2012 at 10:58:01AM +0100, Jan Zelený wrote:
> > I found this bug when I was looking at the libnl intergration code
> > to triage a different issue.
> 
> Nack,
> you should copare ret with SYSFS_TYPE_PATH_MAX, not SYSFS_SUBDIR_PATH_MAX. 
> Also, please add newline to the debug statement "snprintf failed".
> 
> Jan

Thanks, new patch is attached.
From 5a695f1901b75c61d64e43eaeb03cd8d9dfdfe5a Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhro...@redhat.com>
Date: Tue, 21 Feb 2012 19:43:35 +0100
Subject: [PATCH] libnl: fix the path to phy80211 subdirectory

---
 src/monitor/monitor_netlink.c |   24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/monitor/monitor_netlink.c b/src/monitor/monitor_netlink.c
index 
b8c396723ec703107d2c8ed07c027b4143e09c33..8455f6889ecf330fde697680390cf30d37c11b3e
 100644
--- a/src/monitor/monitor_netlink.c
+++ b/src/monitor/monitor_netlink.c
@@ -60,13 +60,17 @@
 #define nlw_object_match nl_object_match_filter
 #define NLW_OK NL_OK
 
-#define SYSFS_IFACE_TEMPLATE "/sys/class/net/%s/type"
-#define SYSFS_IFACE_PATH_MAX (21+IFNAMSIZ)
+#define SYSFS_IFACE_TEMPLATE "/sys/class/net/%s"
+#define SYSFS_IFACE_PATH_MAX (16+IFNAMSIZ)
 
 #define PHY_80211_SUBDIR   "phy80211"
 /* 9 = strlen(PHY_80211_SUBDIR)+1, 1 = path delimeter */
 #define SYSFS_SUBDIR_PATH_MAX (SYSFS_IFACE_PATH_MAX+9+1)
 
+#define TYPE_FILE "type"
+/* 5 = strlen(TYPE_FILE)+1, 1 = path delimeter */
+#define SYSFS_TYPE_PATH_MAX (SYSFS_IFACE_PATH_MAX+5+1)
+
 #define BUFSIZE 8
 
 enum nlw_msg_type {
@@ -123,15 +127,27 @@ static bool has_wireless_extension(const char *ifname)
 
 static bool has_ethernet_encapsulation(const char *sysfs_path)
 {
+    char type_path[SYSFS_TYPE_PATH_MAX];
     errno_t ret;
     int fd = -1;
     char buf[BUFSIZE];
 
-    fd = open(sysfs_path, O_RDONLY);
+    ret = snprintf(type_path, SYSFS_TYPE_PATH_MAX,
+                   "%s/%s", sysfs_path, TYPE_FILE);
+    if (ret < 0) {
+        DEBUG(SSSDBG_OP_FAILURE, ("snprintf failed\n"));
+        return false;
+    } else if (ret >= SYSFS_TYPE_PATH_MAX) {
+        DEBUG(SSSDBG_OP_FAILURE, ("path too long?!?!\n"));
+        return false;
+    }
+
+    errno = 0;
+    fd = open(type_path, O_RDONLY);
     if (fd == -1) {
         ret = errno;
         DEBUG(SSSDBG_OP_FAILURE, ("Could not open sysfs file %s: [%d] %s\n",
-              sysfs_path, ret, strerror(ret)));
+              type_path, ret, strerror(ret)));
         return false;
     }
 
-- 
1.7.7.6

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to