summaryrefslogtreecommitdiff
path: root/contrib/ofed
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2018-07-18 10:20:39 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2018-07-18 10:20:39 +0000
commit76001684534b408d4b43fd0f92b0d87df991a313 (patch)
tree6a63d6bd8b5cbb7ea6fa27b8250b849f3cb032e8 /contrib/ofed
parent7b9b93a8dd6fa762d6cfbe296b68b41f6db5b675 (diff)
downloadsrc-test2-76001684534b408d4b43fd0f92b0d87df991a313.tar.gz
src-test2-76001684534b408d4b43fd0f92b0d87df991a313.zip
Notes
Diffstat (limited to 'contrib/ofed')
-rw-r--r--contrib/ofed/libibumad/sysfs.c15
-rw-r--r--contrib/ofed/libibumad/sysfs.h35
-rw-r--r--contrib/ofed/libibumad/umad.c8
3 files changed, 43 insertions, 15 deletions
diff --git a/contrib/ofed/libibumad/sysfs.c b/contrib/ofed/libibumad/sysfs.c
index dfdcadfa567b..8ff1681f78fb 100644
--- a/contrib/ofed/libibumad/sysfs.c
+++ b/contrib/ofed/libibumad/sysfs.c
@@ -62,12 +62,8 @@ int sys_read_string(const char *dir_name, const char *file_name, char *str, int
snprintf(path, sizeof(path), "%s/%s", dir_name, file_name);
- for (s = &path[0]; *s != '\0'; s++)
- if (*s == '/')
- *s = '.';
-
len = max_len;
- if (sysctlbyname(&path[1], str, &len, NULL, 0) == -1)
+ if (sysctlbyname(PATH_TO_SYS(path), str, &len, NULL, 0) == -1)
return ret_code();
str[(len < max_len) ? len : max_len - 1] = 0;
@@ -170,11 +166,8 @@ sys_scandir(const char *dirname, struct dirent ***namelist,
int i;
*namelist = NULL;
- /* Skip the leading / */
- strncpy(name, &dirname[1], sizeof(name));
- for (s = &name[0]; *s != '\0'; s++)
- if (*s == '/')
- *s = '.';
+ if (strlcpy(name, PATH_TO_SYS(dirname), sizeof(name)) >= sizeof(name))
+ return (-EINVAL);
/*
* Resolve the path.
*/
@@ -259,7 +252,7 @@ out:
if (cnt && compar)
qsort(names, cnt, sizeof(struct dirent *),
(int (*)(const void *, const void *))compar);
-
+
*namelist = names;
return (cnt);
diff --git a/contrib/ofed/libibumad/sysfs.h b/contrib/ofed/libibumad/sysfs.h
index 414a122fa368..e0234c22f24d 100644
--- a/contrib/ofed/libibumad/sysfs.h
+++ b/contrib/ofed/libibumad/sysfs.h
@@ -34,6 +34,8 @@
#define _UMAD_SYSFS_H
#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
#include <infiniband/types.h>
#include <infiniband/umad.h>
@@ -49,4 +51,37 @@ extern int sys_scandir(const char *dirname, struct dirent ***namelist,
int (*select)(const struct dirent *),
int (*compar)(const struct dirent **, const struct dirent **));
+#ifdef __FreeBSD__
+static inline const char *
+path_to_sysctl(const char *path, int out_len, char *out)
+{
+ const char *retval = out;
+
+ /* Validate that out is at least as long as the original path */
+ if (out_len < (strlen(path) + 1))
+ return NULL;
+
+ while (*path == '/')
+ path++;
+
+ while (*path) {
+ if (*path == '/') {
+ if (*(path + 1) == '/')
+ *out = '.';
+ else
+ *out++ = '.';
+ } else
+ *out++ = *path;
+ path++;
+ }
+ *out = 0;
+ return (retval);
+}
+
+#define PATH_TO_SYS(str) \
+ path_to_sysctl(str, strlen(str) + 1, alloca(strlen(str) + 1))
+#else
+#define PATH_TO_SYS(str) str
+#endif
+
#endif /* _UMAD_SYSFS_H */
diff --git a/contrib/ofed/libibumad/umad.c b/contrib/ofed/libibumad/umad.c
index af0a28eeea28..5eb403b6133d 100644
--- a/contrib/ofed/libibumad/umad.c
+++ b/contrib/ofed/libibumad/umad.c
@@ -509,14 +509,14 @@ int umad_init(void)
TRACE("umad_init");
if (sys_read_uint(IB_UMAD_ABI_DIR, IB_UMAD_ABI_FILE, &abi_version) < 0) {
IBWARN
- ("can't read ABI version from %s/%s (%m): is ib_umad module loaded?",
- IB_UMAD_ABI_DIR, IB_UMAD_ABI_FILE);
+ ("can't read ABI version from %s (%m): is ibcore module loaded?",
+ PATH_TO_SYS(IB_UMAD_ABI_DIR "/" IB_UMAD_ABI_FILE));
return -1;
}
if (abi_version < IB_UMAD_ABI_VERSION) {
IBWARN
- ("wrong ABI version: %s/%s is %d but library minimal ABI is %d",
- IB_UMAD_ABI_DIR, IB_UMAD_ABI_FILE, abi_version,
+ ("wrong ABI version: %s is %d but library minimal ABI is %d",
+ PATH_TO_SYS(IB_UMAD_ABI_DIR "/" IB_UMAD_ABI_FILE), abi_version,
IB_UMAD_ABI_VERSION);
return -1;
}