From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Thu, 26 Feb 2004 04:26:06 +0000 Subject: [PATCH] udev - safer string handling - part four Message-Id: <20040226042606.GA27431@vrfy.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="jRHKVT23PllUwdXP" List-Id: References: <20040226003100.GA27025@vrfy.org> In-Reply-To: <20040226003100.GA27025@vrfy.org> To: linux-hotplug@vger.kernel.org --jRHKVT23PllUwdXP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 :) thanks, Kay --jRHKVT23PllUwdXP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="07-cleanup-earlier-changes.patch" diff -Nru a/logging.h b/logging.h --- a/logging.h Thu Feb 26 05:14:04 2004 +++ b/logging.h Thu Feb 26 05:14:04 2004 @@ -37,14 +37,14 @@ #undef info #define info(format, arg...) \ do { \ - log_message (LOG_INFO , format , ## arg); \ + log_message(LOG_INFO , format , ## arg); \ } while (0) #ifdef DEBUG #undef dbg #define dbg(format, arg...) \ do { \ - log_message (LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg); \ + log_message(LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg); \ } while (0) #endif @@ -53,11 +53,11 @@ #undef dbg_parse #define dbg_parse(format, arg...) \ do { \ - log_message (LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg); \ + log_message(LOG_DEBUG , "%s: " format , __FUNCTION__ , ## arg); \ } while (0) #endif -extern void log_message (int level, const char *format, ...) +extern void log_message(int level, const char *format, ...) __attribute__ ((format (printf, 2, 3))); /* each program that uses syslog must declare this variable somewhere */ diff -Nru a/namedev.c b/namedev.c --- a/namedev.c Thu Feb 26 05:14:04 2004 +++ b/namedev.c Thu Feb 26 05:14:04 2004 @@ -228,7 +228,7 @@ pos = string; while (1) { - pos = strchr(pos, '%'); + pos = strchr(string, '%'); if (pos != NULL) { pos[0] = '\0'; tail = pos+1; @@ -247,19 +247,19 @@ case 'b': if (strlen(udev->bus_id) == 0) break; - strnfieldcat(pos, udev->bus_id, maxsize); + strnfieldcat(string, udev->bus_id, maxsize); dbg("substitute bus_id '%s'", udev->bus_id); break; case 'k': if (strlen(udev->kernel_name) == 0) break; - strnfieldcat(pos, udev->kernel_name, maxsize); + strnfieldcat(string, udev->kernel_name, maxsize); dbg("substitute kernel name '%s'", udev->kernel_name); break; case 'n': if (strlen(udev->kernel_number) == 0) break; - strnfieldcat(pos, udev->kernel_number, maxsize); + strnfieldcat(string, udev->kernel_number, maxsize); dbg("substitute kernel number '%s'", udev->kernel_number); break; case 'm': @@ -289,11 +289,11 @@ } } if (pos3) { - strnfieldcat(pos, pos3, maxsize); + strnfieldcat(string, pos3, maxsize); dbg("substitute part of result string '%s'", pos3); } } else { - strnfieldcat(pos, udev->program_result, maxsize); + strnfieldcat(string, udev->program_result, maxsize); dbg("substitute result string '%s'", udev->program_result); } break; @@ -304,20 +304,20 @@ dbg("sysfa attribute '%s' not found", attr); break; } - strnfieldcpy(pos, tmpattr->value, maxsize); + strnfieldcat(string, tmpattr->value, maxsize); dbg("substitute sysfs value '%s'", tmpattr->value); } else { dbg("missing attribute"); } break; case '%': - strnfieldcat(pos, "%", maxsize); + strnfieldcat(string, "%", maxsize); break; default: dbg("unknown substitution type '%%%c'", c); break; } - strnfieldcat(pos, tail, maxsize); + strnfieldcat(string, tail, maxsize); } } diff -Nru a/udev.c b/udev.c --- a/udev.c Thu Feb 26 05:14:04 2004 +++ b/udev.c Thu Feb 26 05:14:04 2004 @@ -41,7 +41,7 @@ #ifdef LOG unsigned char logname[42]; -void log_message (int level, const char *format, ...) +void log_message(int level, const char *format, ...) { va_list args; @@ -76,7 +76,7 @@ "", }; -static int udev_hotplug(int argc, char **argv) +static int udev_hotplug(void) { char *action; char *devpath; @@ -106,7 +106,7 @@ } /* skip blacklisted subsystems */ - subsystem = get_subsystem(argv[1]); + subsystem = get_subsystem(main_argv[1]); if (!subsystem) { dbg("no subsystem?"); goto exit; @@ -123,9 +123,6 @@ /* connect to the system message bus */ sysbus_connect(); - /* initialize our configuration */ - udev_init_config(); - /* initialize udev database */ retval = udevdb_init(UDEVDB_DEFAULT); if (retval != 0) { @@ -172,7 +169,11 @@ main_envp = envp; init_logging("udev"); + + /* initialize our configuration */ + udev_init_config(); + dbg("version %s", UDEV_VERSION); - return udev_hotplug(argc, argv); + return udev_hotplug(); } diff -Nru a/udev.h b/udev.h --- a/udev.h Thu Feb 26 05:14:04 2004 +++ b/udev.h Thu Feb 26 05:14:04 2004 @@ -90,7 +90,7 @@ char *action; action = getenv("ACTION"); - if (strlen(action) > ACTION_SIZE) + if (action != NULL && strlen(action) > ACTION_SIZE) action[ACTION_SIZE-1] = '\0'; return action; @@ -101,7 +101,7 @@ char *devpath; devpath = getenv("DEVPATH"); - if (strlen(devpath) > DEVPATH_SIZE) + if (devpath != NULL && strlen(devpath) > DEVPATH_SIZE) devpath[DEVPATH_SIZE-1] = '\0'; return devpath; @@ -118,7 +118,7 @@ static inline char *get_subsystem(char *subsystem) { - if (strlen(subsystem) > SUBSYSTEM_SIZE) + if (subsystem != NULL && strlen(subsystem) > SUBSYSTEM_SIZE) subsystem[SUBSYSTEM_SIZE-1] = '\0'; return subsystem; --jRHKVT23PllUwdXP-- ------------------------------------------------------- SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now! http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel