linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH] udev - safer string handling - part three
Date: Thu, 26 Feb 2004 02:22:45 +0000	[thread overview]
Message-ID: <20040226022245.GA27238@vrfy.org> (raw)
In-Reply-To: <20040226003100.GA27025@vrfy.org>

[-- Attachment #1: Type: text/plain, Size: 420 bytes --]

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'?

thanks,
Kay

[-- Attachment #2: 06-truncate-input-strings.patch --]
[-- Type: text/plain, Size: 4664 bytes --]

diff -Nru a/namedev.c b/namedev.c
--- a/namedev.c	Thu Feb 26 03:09:18 2004
+++ b/namedev.c	Thu Feb 26 03:09:18 2004
@@ -405,7 +405,7 @@
 	int fds[2];
 	pid_t pid;
 	int value_set = 0;
-	char buffer[256];
+	char buffer[255];
 	char *pos;
 
 	retval = pipe(fds);
diff -Nru a/udev.c b/udev.c
--- a/udev.c	Thu Feb 26 03:09:18 2004
+++ b/udev.c	Thu Feb 26 03:09:18 2004
@@ -43,7 +43,7 @@
 unsigned char logname[42];
 void log_message (int level, const char *format, ...)
 {
-	va_list	args;
+	va_list args;
 
 	if (!udev_log)
 		return;
@@ -67,30 +67,6 @@
 	}
 }
 
-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",
@@ -130,7 +106,7 @@
 	}
 
 	/* skip blacklisted subsystems */
-	subsystem = argv[1];
+	subsystem = get_subsystem(argv[1]);
 	if (!subsystem) {
 		dbg("no subsystem?");
 		goto exit;
@@ -200,5 +176,3 @@
 
 	return udev_hotplug(argc, argv);
 }
-
-
diff -Nru a/udev.h b/udev.h
--- a/udev.h	Thu Feb 26 03:09:18 2004
+++ b/udev.h	Thu Feb 26 03:09:18 2004
@@ -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))
 
@@ -78,6 +84,45 @@
 	to[maxsize-1] = '\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);
diff -Nru a/udevd.c b/udevd.c
--- a/udevd.c	Thu Feb 26 03:09:18 2004
+++ b/udevd.c	Thu Feb 26 03:09:18 2004
@@ -119,8 +119,8 @@
 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);
diff -Nru a/udevd.h b/udevd.h
--- a/udevd.h	Thu Feb 26 03:09:18 2004
+++ b/udevd.h	Thu Feb 26 03:09:18 2004
@@ -35,7 +35,7 @@
 	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];
 };
diff -Nru a/udevsend.c b/udevsend.c
--- a/udevsend.c	Thu Feb 26 03:09:18 2004
+++ b/udevsend.c	Thu Feb 26 03:09:18 2004
@@ -52,30 +52,6 @@
 }
 #endif
 
-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)
 {
@@ -144,7 +120,7 @@
 #endif
 	dbg("version %s", UDEV_VERSION);
 
-	subsystem = argv[1];
+	subsystem = get_subsystem(argv[1]);
 	if (subsystem == NULL) {
 		dbg("no subsystem");
 		goto exit;
diff -Nru a/udevtest.c b/udevtest.c
--- a/udevtest.c	Thu Feb 26 03:09:18 2004
+++ b/udevtest.c	Thu Feb 26 03:09:18 2004
@@ -66,30 +66,6 @@
 	}
 }
 
-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",

  reply	other threads:[~2004-02-26  2:22 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 ` Kay Sievers [this message]
2004-02-26  4:26 ` [PATCH] udev - safer string handling - part four Kay Sievers
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=20040226022245.GA27238@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).