aboutsummaryrefslogtreecommitdiff
path: root/modutils
diff options
context:
space:
mode:
Diffstat (limited to 'modutils')
-rw-r--r--modutils/modprobe-small.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c
index 02d8fbd40..e2359d042 100644
--- a/modutils/modprobe-small.c
+++ b/modutils/modprobe-small.c
@@ -44,11 +44,13 @@ struct globals {
44 char *module_load_options; 44 char *module_load_options;
45 smallint dep_bb_seen; 45 smallint dep_bb_seen;
46 smallint wrote_dep_bb_ok; 46 smallint wrote_dep_bb_ok;
47 int module_count; 47 unsigned module_count;
48 int module_found_idx; 48 int module_found_idx;
49 int stringbuf_idx; 49 unsigned stringbuf_idx;
50 char stringbuf[32 * 1024]; /* some modules have lots of stuff */ 50 unsigned stringbuf_size;
51 char *stringbuf; /* some modules have lots of stuff */
51 /* for example, drivers/media/video/saa7134/saa7134.ko */ 52 /* for example, drivers/media/video/saa7134/saa7134.ko */
53 /* therefore having a fixed biggish buffer is not wise */
52}; 54};
53#define G (*ptr_to_globals) 55#define G (*ptr_to_globals)
54#define modinfo (G.modinfo ) 56#define modinfo (G.modinfo )
@@ -58,16 +60,29 @@ struct globals {
58#define module_found_idx (G.module_found_idx ) 60#define module_found_idx (G.module_found_idx )
59#define module_load_options (G.module_load_options) 61#define module_load_options (G.module_load_options)
60#define stringbuf_idx (G.stringbuf_idx ) 62#define stringbuf_idx (G.stringbuf_idx )
63#define stringbuf_size (G.stringbuf_size )
61#define stringbuf (G.stringbuf ) 64#define stringbuf (G.stringbuf )
62#define INIT_G() do { \ 65#define INIT_G() do { \
63 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 66 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
64} while (0) 67} while (0)
65 68
69static void append(const char *s)
70{
71 unsigned len = strlen(s);
72 if (stringbuf_idx + len + 15 > stringbuf_size) {
73 stringbuf_size = stringbuf_idx + len + 127;
74 dbg2_error_msg("grow stringbuf to %u", stringbuf_size);
75 stringbuf = xrealloc(stringbuf, stringbuf_size);
76 }
77 memcpy(stringbuf + stringbuf_idx, s, len);
78 stringbuf_idx += len;
79}
66 80
67static void appendc(char c) 81static void appendc(char c)
68{ 82{
69 if (stringbuf_idx < sizeof(stringbuf)) 83 /* We appendc() only after append(), + 15 trick in append()
70 stringbuf[stringbuf_idx++] = c; 84 * makes it unnecessary to check for overflow here */
85 stringbuf[stringbuf_idx++] = c;
71} 86}
72 87
73static void bksp(void) 88static void bksp(void)
@@ -76,15 +91,6 @@ static void bksp(void)
76 stringbuf_idx--; 91 stringbuf_idx--;
77} 92}
78 93
79static void append(const char *s)
80{
81 size_t len = strlen(s);
82 if (stringbuf_idx + len < sizeof(stringbuf)) {
83 memcpy(stringbuf + stringbuf_idx, s, len);
84 stringbuf_idx += len;
85 }
86}
87
88static void reset_stringbuf(void) 94static void reset_stringbuf(void)
89{ 95{
90 stringbuf_idx = 0; 96 stringbuf_idx = 0;
@@ -92,7 +98,7 @@ static void reset_stringbuf(void)
92 98
93static char* copy_stringbuf(void) 99static char* copy_stringbuf(void)
94{ 100{
95 char *copy = xmalloc(stringbuf_idx); 101 char *copy = xzalloc(stringbuf_idx + 1); /* terminating NUL */
96 return memcpy(copy, stringbuf, stringbuf_idx); 102 return memcpy(copy, stringbuf, stringbuf_idx);
97} 103}
98 104
@@ -216,8 +222,8 @@ static void parse_module(module_info *info, const char *pathname)
216 pos = (ptr - module_image); 222 pos = (ptr - module_image);
217 } 223 }
218 bksp(); /* remove last ' ' */ 224 bksp(); /* remove last ' ' */
219 appendc('\0');
220 info->aliases = copy_stringbuf(); 225 info->aliases = copy_stringbuf();
226 replace(info->aliases, '-', '_');
221 227
222 /* "dependency1 depandency2" */ 228 /* "dependency1 depandency2" */
223 reset_stringbuf(); 229 reset_stringbuf();
@@ -228,7 +234,6 @@ static void parse_module(module_info *info, const char *pathname)
228 dbg2_error_msg("dep:'%s'", ptr); 234 dbg2_error_msg("dep:'%s'", ptr);
229 append(ptr); 235 append(ptr);
230 } 236 }
231 appendc('\0');
232 info->deps = copy_stringbuf(); 237 info->deps = copy_stringbuf();
233 238
234 free(module_image); 239 free(module_image);