diff options
author | kay.sievers@vrfy.org <kay.sievers@vrfy.org> | 2004-02-26 19:40:32 -0800 |
---|---|---|
committer | Greg KH <gregkh@suse.de> | 2005-04-26 21:32:30 -0700 |
commit | e964c2c05d3d6e2bdb21b3461ed7a4e85315cbc1 (patch) | |
tree | 942e0b9c0bdd90ec7d0f0c98abf94ba7c75159af /udev.h | |
parent | 831f800da34ddb449aecae925cd1f154f20b1eed (diff) |
[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'?
Diffstat (limited to 'udev.h')
-rw-r--r-- | udev.h | 45 |
1 files changed, 45 insertions, 0 deletions
@@ -23,6 +23,8 @@ #ifndef UDEV_H #define UDEV_H +#include <stdlib.h> +#include <string.h> #include <sysfs/libsysfs.h> #include <stddef.h> #include <sys/param.h> @@ -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); |