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'?
int fds[2];
pid_t pid;
int value_set = 0;
int fds[2];
pid_t pid;
int value_set = 0;
char *pos;
char *args[PROGRAM_MAXARG];
int i;
char *pos;
char *args[PROGRAM_MAXARG];
int i;
unsigned char logname[42];
void log_message (int level, const char *format, ...)
{
unsigned char logname[42];
void log_message (int level, const char *format, ...)
{
-static inline char *get_action(void)
-{
- char *action;
-
- action = getenv("ACTION");
- return action;
-}
-
-static inline char *get_devpath(void)
-{
- char *devpath;
-
- devpath = getenv("DEVPATH");
- return devpath;
-}
-
-static inline char *get_seqnum(void)
-{
- char *seqnum;
-
- seqnum = getenv("SEQNUM");
- return seqnum;
-}
-
static char *subsystem_blacklist[] = {
"net",
"scsi_host",
static char *subsystem_blacklist[] = {
"net",
"scsi_host",
}
/* skip blacklisted subsystems */
}
/* skip blacklisted subsystems */
+ subsystem = get_subsystem(argv[1]);
if (!subsystem) {
dbg("no subsystem?");
goto exit;
if (!subsystem) {
dbg("no subsystem?");
goto exit;
return udev_hotplug(argc, argv);
}
return udev_hotplug(argc, argv);
}
#ifndef UDEV_H
#define UDEV_H
#ifndef UDEV_H
#define UDEV_H
+#include <stdlib.h>
+#include <string.h>
#include <sysfs/libsysfs.h>
#include <stddef.h>
#include <sys/param.h>
#include <sysfs/libsysfs.h>
#include <stddef.h>
#include <sys/param.h>
#define GROUP_SIZE 30
#define MODE_SIZE 8
#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))
/* length of public data */
#define UDEVICE_LEN (offsetof(struct udevice, bus_id))
strncat(to, from, maxsize - strlen(to)-1); \
} while (0)
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);
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);
static void udev_run(struct hotplug_msg *msg)
{
pid_t pid;
static void udev_run(struct hotplug_msg *msg)
{
pid_t pid;
- char action[32];
- char devpath[256];
+ char action[ACTION_SIZE];
+ char devpath[DEVPATH_SIZE];
char *env[] = { action, devpath, NULL };
snprintf(action, sizeof(action), "ACTION=%s", msg->action);
char *env[] = { action, devpath, NULL };
snprintf(action, sizeof(action), "ACTION=%s", msg->action);
pid_t pid;
int seqnum;
time_t queue_time;
pid_t pid;
int seqnum;
time_t queue_time;
- char action[8];
- char devpath[128];
- char subsystem[16];
+ char action[ACTION_SIZE];
+ char devpath[DEVPATH_SIZE];
+ char subsystem[SUBSYSTEM_SIZE];
-static inline char *get_action(void)
-{
- char *action;
-
- action = getenv("ACTION");
- return action;
-}
-
-static inline char *get_devpath(void)
-{
- char *devpath;
-
- devpath = getenv("DEVPATH");
- return devpath;
-}
-
-static inline char *get_seqnum(void)
-{
- char *seqnum;
-
- seqnum = getenv("SEQNUM");
- return seqnum;
-}
-
static int build_hotplugmsg(struct hotplug_msg *msg, char *action,
char *devpath, char *subsystem, int seqnum)
{
static int build_hotplugmsg(struct hotplug_msg *msg, char *action,
char *devpath, char *subsystem, int seqnum)
{
#endif
dbg("version %s", UDEV_VERSION);
#endif
dbg("version %s", UDEV_VERSION);
+ subsystem = get_subsystem(argv[1]);
if (subsystem == NULL) {
dbg("no subsystem");
goto exit;
if (subsystem == NULL) {
dbg("no subsystem");
goto exit;
-static inline char *get_action(void)
-{
- char *action;
-
- action = getenv("ACTION");
- return action;
-}
-
-static inline char *get_devpath(void)
-{
- char *devpath;
-
- devpath = getenv("DEVPATH");
- return devpath;
-}
-
-static inline char *get_seqnum(void)
-{
- char *seqnum;
-
- seqnum = getenv("SEQNUM");
- return seqnum;
-}
-
static char *subsystem_blacklist[] = {
"net",
"scsi_host",
static char *subsystem_blacklist[] = {
"net",
"scsi_host",