aboutsummaryrefslogtreecommitdiff
path: root/lib/libdevinfo
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2018-05-31 02:58:03 +0000
committerWarner Losh <imp@FreeBSD.org>2018-05-31 02:58:03 +0000
commitcf72c10fd250ae282e14458ed528642fb724a837 (patch)
tree5c51677c0a2e0cc5323f1c4fed4ced72a6980772 /lib/libdevinfo
parentc580ca4cf4a4df702d3cde59ce9bb899c6cdab6e (diff)
downloadsrc-cf72c10fd250ae282e14458ed528642fb724a837.tar.gz
src-cf72c10fd250ae282e14458ed528642fb724a837.zip
Notes
Diffstat (limited to 'lib/libdevinfo')
-rw-r--r--lib/libdevinfo/devinfo.c42
-rw-r--r--lib/libdevinfo/devinfo_var.h10
2 files changed, 33 insertions, 19 deletions
diff --git a/lib/libdevinfo/devinfo.c b/lib/libdevinfo/devinfo.c
index 49f7f0fbe5a4..c4cd8d78ba94 100644
--- a/lib/libdevinfo/devinfo.c
+++ b/lib/libdevinfo/devinfo.c
@@ -175,7 +175,7 @@ devinfo_init_devices(int generation)
int name2oid[2];
int oid[CTL_MAXNAME + 12];
size_t oidlen, rlen;
- char *name;
+ char *name, *walker, *ep;
int error;
/*
@@ -229,22 +229,31 @@ devinfo_init_devices(int generation)
return(ENOMEM);
dd->dd_dev.dd_handle = udev.dv_handle;
dd->dd_dev.dd_parent = udev.dv_parent;
- snprintf(dd->dd_name, sizeof(dd->dd_name), "%s", udev.dv_name);
- dd->dd_dev.dd_name = &dd->dd_name[0];
- snprintf(dd->dd_desc, sizeof(dd->dd_desc), "%s", udev.dv_desc);
- dd->dd_dev.dd_desc = &dd->dd_desc[0];
- snprintf(dd->dd_drivername, sizeof(dd->dd_drivername), "%s",
- udev.dv_drivername);
- dd->dd_dev.dd_drivername = &dd->dd_drivername[0];
- snprintf(dd->dd_pnpinfo, sizeof(dd->dd_pnpinfo), "%s",
- udev.dv_pnpinfo);
- dd->dd_dev.dd_pnpinfo = &dd->dd_pnpinfo[0];
- snprintf(dd->dd_location, sizeof(dd->dd_location), "%s",
- udev.dv_location);
- dd->dd_dev.dd_location = &dd->dd_location[0];
dd->dd_dev.dd_devflags = udev.dv_devflags;
dd->dd_dev.dd_flags = udev.dv_flags;
dd->dd_dev.dd_state = udev.dv_state;
+
+ walker = udev.dv_fields;
+ ep = walker + sizeof(udev.dv_fields);
+ dd->dd_name = NULL;
+ dd->dd_desc = NULL;
+ dd->dd_drivername = NULL;
+ dd->dd_pnpinfo = NULL;
+ dd->dd_location = NULL;
+#define UNPACK(x) \
+ dd->dd_dev.x = dd->x = strdup(walker); \
+ if (dd->x == NULL) \
+ return(ENOMEM); \
+ if (walker + strnlen(walker, ep - walker) >= ep) \
+ return(EINVAL); \
+ walker += strlen(walker) + 1;
+
+ UNPACK(dd_name);
+ UNPACK(dd_desc);
+ UNPACK(dd_drivername);
+ UNPACK(dd_pnpinfo);
+ UNPACK(dd_location);
+#undef UNPACK
TAILQ_INSERT_TAIL(&devinfo_dev, dd, dd_link);
}
debug("fetched %d devices", dev_idx);
@@ -367,6 +376,11 @@ devinfo_free(void)
while ((dd = TAILQ_FIRST(&devinfo_dev)) != NULL) {
TAILQ_REMOVE(&devinfo_dev, dd, dd_link);
+ free(dd->dd_name);
+ free(dd->dd_desc);
+ free(dd->dd_drivername);
+ free(dd->dd_pnpinfo);
+ free(dd->dd_location);
free(dd);
}
while ((dm = TAILQ_FIRST(&devinfo_rman)) != NULL) {
diff --git a/lib/libdevinfo/devinfo_var.h b/lib/libdevinfo/devinfo_var.h
index 5b14341f3841..c282642e812b 100644
--- a/lib/libdevinfo/devinfo_var.h
+++ b/lib/libdevinfo/devinfo_var.h
@@ -45,11 +45,11 @@
*/
struct devinfo_i_dev {
struct devinfo_dev dd_dev;
- char dd_name[DEVINFO_STRLEN];
- char dd_desc[DEVINFO_STRLEN];
- char dd_drivername[DEVINFO_STRLEN];
- char dd_pnpinfo[DEVINFO_STRLEN * 4];
- char dd_location[DEVINFO_STRLEN * 4];
+ char *dd_name;
+ char *dd_desc;
+ char *dd_drivername;
+ char *dd_pnpinfo;
+ char *dd_location;
uint32_t dd_devflags;
uint16_t dd_flags;
device_state_t dd_state;