linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] request_module_fmt(char "fmt, ...)
@ 2003-05-17 14:36 David Woodhouse
  0 siblings, 0 replies; only message in thread
From: David Woodhouse @ 2003-05-17 14:36 UTC (permalink / raw)
  To: torvalds; +Cc: linux-kernel

We do this all over the kernel, badly. Many people use sprintf, others
use snprintf but don't seem to have noticed they need to put the
trailing zero into the buffer if it truncates, etc.

If we put it in one place, we can get it right.

I didn't just change the prototype of request_module() because that
would cause stuff like 'ifconfig eth%s up' to cause oopsen. 

Untested -- 2.5 didn't even get to a prompt last time I tried to boot it
a week or so ago. Does compile though :)

===== include/linux/kmod.h 1.3 vs edited =====
--- 1.3/include/linux/kmod.h	Thu Feb 13 03:35:39 2003
+++ edited/include/linux/kmod.h	Sat May 17 15:30:01 2003
@@ -25,8 +25,12 @@
 
 #ifdef CONFIG_KMOD
 extern int request_module(const char * name);
+extern int request_module_fmt(const char *fmt, ...)
+     __attribute__ ((format (printf, 1, 2)));
 #else
 static inline int request_module(const char * name) { return -ENOSYS; }
+static inline int request_module_fmt(const char *fmt, ...)
+     __attribute__ ((format (printf, 1, 2))) { return -ENOSYS; }
 #endif
 
 #define try_then_request_module(x, mod) ((x) ?: request_module(mod), (x))
===== kernel/kmod.c 1.25 vs edited =====
--- 1.25/kernel/kmod.c	Mon Feb 24 17:40:34 2003
+++ edited/kernel/kmod.c	Sat May 17 15:30:51 2003
@@ -110,6 +110,29 @@
 	atomic_dec(&kmod_concurrent);
 	return ret;
 }
+
+int request_module_fmt(const char *fmt, ...)
+{
+	char name[32];
+	va_list args;
+	int ret;
+
+	name[sizeof(name)-1] = 0;
+
+	va_start(args, fmt);
+	ret = vsnprintf(name, sizeof(name)-1, fmt, args);
+	va_end(args);
+
+	if (ret >= sizeof(name)-1) {
+		printk(KERN_WARNING "Module name \"%s\"... too long.\n",
+		       name);
+		return -ENAMETOOLONG;
+	}
+	return request_module(name);
+}
+
+EXPORT_SYMBOL(request_module);
+EXPORT_SYMBOL(request_module_fmt);
 #endif /* CONFIG_KMOD */
 
 #ifdef CONFIG_HOTPLUG
@@ -273,8 +296,4 @@
 }
 
 EXPORT_SYMBOL(call_usermodehelper);
-
-#ifdef CONFIG_KMOD
-EXPORT_SYMBOL(request_module);
-#endif
 



-- 
dwmw2



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-05-17 14:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-17 14:36 [PATCH] request_module_fmt(char "fmt, ...) David Woodhouse

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).