From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH] udev - safer string handling - part four
Date: Thu, 26 Feb 2004 04:26:06 +0000 [thread overview]
Message-ID: <20040226042606.GA27431@vrfy.org> (raw)
In-Reply-To: <20040226003100.GA27025@vrfy.org>
[-- Attachment #1: Type: text/plain, Size: 346 bytes --]
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
[-- Attachment #2: 07-cleanup-earlier-changes.patch --]
[-- Type: text/plain, Size: 4964 bytes --]
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;
next prev parent reply other threads:[~2004-02-26 4:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-26 0:31 [PATCH] udev - safer string handling - part two Kay Sievers
2004-02-26 2:22 ` [PATCH] udev - safer string handling - part three Kay Sievers
2004-02-26 4:26 ` Kay Sievers [this message]
2004-02-26 20:56 ` [PATCH] udev - safer string handling - part two Greg KH
2004-02-26 20:56 ` [PATCH] udev - safer string handling - part three Greg KH
2004-02-26 20:57 ` [PATCH] udev - safer string handling - part four Greg KH
2004-02-26 22:42 ` Kay Sievers
2004-03-18 14:24 ` [PATCH] udev - safer string handling - part three Harald Hoyer
2004-03-18 14:39 ` Kay Sievers
2004-03-18 15:01 ` Harald Hoyer
2004-03-26 22:41 ` Kay Sievers
2004-03-29 8:09 ` Harald Hoyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040226042606.GA27431@vrfy.org \
--to=kay.sievers@vrfy.org \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).