[PATCH] udev - safer string handling - part four
Mainly a cleanup of the earlier patches with a few missing pieces and some cosmetical changes. I've moved the udev_init_config() to very early init, otherwise we don't get any logging for the processing of the input. What would I do without gdb :) Greg, it's the 7th patch in your box to apply. I will stop now and wait for you :)
This commit is contained in:
parent
e964c2c05d
commit
3fe0734266
|
@ -37,14 +37,14 @@
|
||||||
#undef info
|
#undef info
|
||||||
#define info(format, arg...) \
|
#define info(format, arg...) \
|
||||||
do { \
|
do { \
|
||||||
log_message (LOG_INFO , format , ## arg); \
|
log_message(LOG_INFO , format , ## arg); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#undef dbg
|
#undef dbg
|
||||||
#define dbg(format, arg...) \
|
#define dbg(format, arg...) \
|
||||||
do { \
|
do { \
|
||||||
log_message (LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg); \
|
log_message(LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -53,11 +53,11 @@
|
||||||
#undef dbg_parse
|
#undef dbg_parse
|
||||||
#define dbg_parse(format, arg...) \
|
#define dbg_parse(format, arg...) \
|
||||||
do { \
|
do { \
|
||||||
log_message (LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg); \
|
log_message(LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void log_message (int level, const char *format, ...)
|
extern void log_message(int level, const char *format, ...)
|
||||||
__attribute__ ((format (printf, 2, 3)));
|
__attribute__ ((format (printf, 2, 3)));
|
||||||
|
|
||||||
/* each program that uses syslog must declare this variable somewhere */
|
/* each program that uses syslog must declare this variable somewhere */
|
||||||
|
|
18
namedev.c
18
namedev.c
|
@ -228,7 +228,7 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
|
||||||
pos = string;
|
pos = string;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
pos = strchr(pos, '%');
|
pos = strchr(string, '%');
|
||||||
if (pos != NULL) {
|
if (pos != NULL) {
|
||||||
pos[0] = '\0';
|
pos[0] = '\0';
|
||||||
tail = pos+1;
|
tail = pos+1;
|
||||||
|
@ -247,19 +247,19 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
|
||||||
case 'b':
|
case 'b':
|
||||||
if (strlen(udev->bus_id) == 0)
|
if (strlen(udev->bus_id) == 0)
|
||||||
break;
|
break;
|
||||||
strnfieldcat(pos, udev->bus_id, maxsize);
|
strnfieldcat(string, udev->bus_id, maxsize);
|
||||||
dbg("substitute bus_id '%s'", udev->bus_id);
|
dbg("substitute bus_id '%s'", udev->bus_id);
|
||||||
break;
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
if (strlen(udev->kernel_name) == 0)
|
if (strlen(udev->kernel_name) == 0)
|
||||||
break;
|
break;
|
||||||
strnfieldcat(pos, udev->kernel_name, maxsize);
|
strnfieldcat(string, udev->kernel_name, maxsize);
|
||||||
dbg("substitute kernel name '%s'", udev->kernel_name);
|
dbg("substitute kernel name '%s'", udev->kernel_name);
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
if (strlen(udev->kernel_number) == 0)
|
if (strlen(udev->kernel_number) == 0)
|
||||||
break;
|
break;
|
||||||
strnfieldcat(pos, udev->kernel_number, maxsize);
|
strnfieldcat(string, udev->kernel_number, maxsize);
|
||||||
dbg("substitute kernel number '%s'", udev->kernel_number);
|
dbg("substitute kernel number '%s'", udev->kernel_number);
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
|
@ -289,11 +289,11 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pos3) {
|
if (pos3) {
|
||||||
strnfieldcat(pos, pos3, maxsize);
|
strnfieldcat(string, pos3, maxsize);
|
||||||
dbg("substitute part of result string '%s'", pos3);
|
dbg("substitute part of result string '%s'", pos3);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
strnfieldcat(pos, udev->program_result, maxsize);
|
strnfieldcat(string, udev->program_result, maxsize);
|
||||||
dbg("substitute result string '%s'", udev->program_result);
|
dbg("substitute result string '%s'", udev->program_result);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -304,20 +304,20 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
|
||||||
dbg("sysfa attribute '%s' not found", attr);
|
dbg("sysfa attribute '%s' not found", attr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
strnfieldcpy(pos, tmpattr->value, maxsize);
|
strnfieldcat(string, tmpattr->value, maxsize);
|
||||||
dbg("substitute sysfs value '%s'", tmpattr->value);
|
dbg("substitute sysfs value '%s'", tmpattr->value);
|
||||||
} else {
|
} else {
|
||||||
dbg("missing attribute");
|
dbg("missing attribute");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '%':
|
case '%':
|
||||||
strnfieldcat(pos, "%", maxsize);
|
strnfieldcat(string, "%", maxsize);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dbg("unknown substitution type '%%%c'", c);
|
dbg("unknown substitution type '%%%c'", c);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
strnfieldcat(pos, tail, maxsize);
|
strnfieldcat(string, tail, maxsize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
udev.c
15
udev.c
|
@ -41,7 +41,7 @@ char **main_envp;
|
||||||
|
|
||||||
#ifdef LOG
|
#ifdef LOG
|
||||||
unsigned char logname[42];
|
unsigned char logname[42];
|
||||||
void log_message (int level, const char *format, ...)
|
void log_message(int level, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ static char *subsystem_blacklist[] = {
|
||||||
"",
|
"",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int udev_hotplug(int argc, char **argv)
|
static int udev_hotplug(void)
|
||||||
{
|
{
|
||||||
char *action;
|
char *action;
|
||||||
char *devpath;
|
char *devpath;
|
||||||
|
@ -106,7 +106,7 @@ static int udev_hotplug(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* skip blacklisted subsystems */
|
/* skip blacklisted subsystems */
|
||||||
subsystem = get_subsystem(argv[1]);
|
subsystem = get_subsystem(main_argv[1]);
|
||||||
if (!subsystem) {
|
if (!subsystem) {
|
||||||
dbg("no subsystem?");
|
dbg("no subsystem?");
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -123,9 +123,6 @@ static int udev_hotplug(int argc, char **argv)
|
||||||
/* connect to the system message bus */
|
/* connect to the system message bus */
|
||||||
sysbus_connect();
|
sysbus_connect();
|
||||||
|
|
||||||
/* initialize our configuration */
|
|
||||||
udev_init_config();
|
|
||||||
|
|
||||||
/* initialize udev database */
|
/* initialize udev database */
|
||||||
retval = udevdb_init(UDEVDB_DEFAULT);
|
retval = udevdb_init(UDEVDB_DEFAULT);
|
||||||
if (retval != 0) {
|
if (retval != 0) {
|
||||||
|
@ -172,7 +169,11 @@ int main(int argc, char **argv, char **envp)
|
||||||
main_envp = envp;
|
main_envp = envp;
|
||||||
|
|
||||||
init_logging("udev");
|
init_logging("udev");
|
||||||
|
|
||||||
|
/* initialize our configuration */
|
||||||
|
udev_init_config();
|
||||||
|
|
||||||
dbg("version %s", UDEV_VERSION);
|
dbg("version %s", UDEV_VERSION);
|
||||||
|
|
||||||
return udev_hotplug(argc, argv);
|
return udev_hotplug();
|
||||||
}
|
}
|
||||||
|
|
6
udev.h
6
udev.h
|
@ -90,7 +90,7 @@ static inline char *get_action(void)
|
||||||
char *action;
|
char *action;
|
||||||
|
|
||||||
action = getenv("ACTION");
|
action = getenv("ACTION");
|
||||||
if (strlen(action) > ACTION_SIZE)
|
if (action != NULL && strlen(action) > ACTION_SIZE)
|
||||||
action[ACTION_SIZE-1] = '\0';
|
action[ACTION_SIZE-1] = '\0';
|
||||||
|
|
||||||
return action;
|
return action;
|
||||||
|
@ -101,7 +101,7 @@ static inline char *get_devpath(void)
|
||||||
char *devpath;
|
char *devpath;
|
||||||
|
|
||||||
devpath = getenv("DEVPATH");
|
devpath = getenv("DEVPATH");
|
||||||
if (strlen(devpath) > DEVPATH_SIZE)
|
if (devpath != NULL && strlen(devpath) > DEVPATH_SIZE)
|
||||||
devpath[DEVPATH_SIZE-1] = '\0';
|
devpath[DEVPATH_SIZE-1] = '\0';
|
||||||
|
|
||||||
return devpath;
|
return devpath;
|
||||||
|
@ -118,7 +118,7 @@ static inline char *get_seqnum(void)
|
||||||
|
|
||||||
static inline char *get_subsystem(char *subsystem)
|
static inline char *get_subsystem(char *subsystem)
|
||||||
{
|
{
|
||||||
if (strlen(subsystem) > SUBSYSTEM_SIZE)
|
if (subsystem != NULL && strlen(subsystem) > SUBSYSTEM_SIZE)
|
||||||
subsystem[SUBSYSTEM_SIZE-1] = '\0';
|
subsystem[SUBSYSTEM_SIZE-1] = '\0';
|
||||||
|
|
||||||
return subsystem;
|
return subsystem;
|
||||||
|
|
Loading…
Reference in a new issue