From e964c2c05d3d6e2bdb21b3461ed7a4e85315cbc1 Mon Sep 17 00:00:00 2001 From: "kay.sievers@vrfy.org" Date: Thu, 26 Feb 2004 19:40:32 -0800 Subject: [PATCH] udev - safer string handling - part three Here we truncate our input strings from the environment to our defined limit. It's a bit theroretical but better check for it. It cleans up some magic length definitions and removes the code duplication in udev, udevtest and udevsend. udevd needs to be killed after installation, cause the message size is changed with this patch. Should we do this with the 'make install', like we do with the '.udevdb'? --- udev.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'udev.h') diff --git a/udev.h b/udev.h index 0ce010f3c4..fa56c36691 100644 --- a/udev.h +++ b/udev.h @@ -23,6 +23,8 @@ #ifndef UDEV_H #define UDEV_H +#include +#include #include #include #include @@ -34,6 +36,10 @@ #define GROUP_SIZE 30 #define MODE_SIZE 8 +#define ACTION_SIZE 30 +#define DEVPATH_SIZE 255 +#define SUBSYSTEM_SIZE 30 + /* length of public data */ #define UDEVICE_LEN (offsetof(struct udevice, bus_id)) @@ -79,6 +85,45 @@ do { \ strncat(to, from, maxsize - strlen(to)-1); \ } while (0) +static inline char *get_action(void) +{ + char *action; + + action = getenv("ACTION"); + if (strlen(action) > ACTION_SIZE) + action[ACTION_SIZE-1] = '\0'; + + return action; +} + +static inline char *get_devpath(void) +{ + char *devpath; + + devpath = getenv("DEVPATH"); + if (strlen(devpath) > DEVPATH_SIZE) + devpath[DEVPATH_SIZE-1] = '\0'; + + return devpath; +} + +static inline char *get_seqnum(void) +{ + char *seqnum; + + seqnum = getenv("SEQNUM"); + + return seqnum; +} + +static inline char *get_subsystem(char *subsystem) +{ + if (strlen(subsystem) > SUBSYSTEM_SIZE) + subsystem[SUBSYSTEM_SIZE-1] = '\0'; + + return subsystem; +} + extern int udev_add_device(char *path, char *subsystem, int fake); extern int udev_remove_device(char *path, char *subsystem); extern void udev_init_config(void); -- cgit v1.2.3-54-g00ecf