summaryrefslogtreecommitdiff
path: root/modutils/modprobe.c
diff options
context:
space:
mode:
authorRobert Griebl <griebl@gmx.de>2002-05-22 23:34:35 +0000
committerRobert Griebl <griebl@gmx.de>2002-05-22 23:34:35 +0000
commit236abbfd713dcce35066322e6ac3ef53b074f429 (patch)
tree8b987c1fcb7b1d0291b9289a8fd23e225123fc3a /modutils/modprobe.c
parent94a6a956f0ec733e1c80ff97645692d041292088 (diff)
downloadbusybox-w32-236abbfd713dcce35066322e6ac3ef53b074f429.tar.gz
busybox-w32-236abbfd713dcce35066322e6ac3ef53b074f429.tar.bz2
busybox-w32-236abbfd713dcce35066322e6ac3ef53b074f429.zip
Some cleanups, some size reductions and some buffer overflow checks
Most of it based on ideas from vodz
Diffstat (limited to 'modutils/modprobe.c')
-rw-r--r--modutils/modprobe.c104
1 files changed, 43 insertions, 61 deletions
diff --git a/modutils/modprobe.c b/modutils/modprobe.c
index b13b9b04f..9230fec85 100644
--- a/modutils/modprobe.c
+++ b/modutils/modprobe.c
@@ -37,7 +37,8 @@ struct mod_list_t {
37}; 37};
38 38
39 39
40static struct dep_t *depend = 0; 40static struct dep_t *depend;
41static int autoclean, show_only, quiet, do_syslog, verbose;
41 42
42 43
43static struct dep_t *build_dep ( void ) 44static struct dep_t *build_dep ( void )
@@ -52,6 +53,11 @@ static struct dep_t *build_dep ( void )
52 53
53 if ( uname ( &un )) 54 if ( uname ( &un ))
54 return 0; 55 return 0;
56
57 // check for buffer overflow in following code
58 if ( xstrlen ( un. release ) > ( sizeof( buffer ) - 64 ))
59 return 0;
60
55 strcpy ( filename, "/lib/modules/" ); 61 strcpy ( filename, "/lib/modules/" );
56 strcat ( filename, un. release ); 62 strcat ( filename, un. release );
57 strcat ( filename, "/modules.dep" ); 63 strcat ( filename, "/modules.dep" );
@@ -160,7 +166,7 @@ static struct dep_t *build_dep ( void )
160} 166}
161 167
162 168
163static int mod_process ( struct mod_list_t *list, int do_insert, int autoclean, int quiet, int do_syslog, int show_only, int verbose ) 169static int mod_process ( struct mod_list_t *list, int do_insert )
164{ 170{
165 char lcmd [256]; 171 char lcmd [256];
166 int rc = 0; 172 int rc = 0;
@@ -196,8 +202,6 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t *
196 if (( mod [lm-2] == '.' ) && ( mod [lm-1] == 'o' )) 202 if (( mod [lm-2] == '.' ) && ( mod [lm-1] == 'o' ))
197 mod [lm-2] = 0; 203 mod [lm-2] = 0;
198 204
199 //printf ( "check_dep: %s\n", mod );
200
201 // search for duplicates 205 // search for duplicates
202 for ( find = *head; find; find = find-> m_next ) { 206 for ( find = *head; find; find = find-> m_next ) {
203 if ( !strcmp ( mod, find-> m_module )) { 207 if ( !strcmp ( mod, find-> m_module )) {
@@ -213,8 +217,6 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t *
213 else 217 else
214 *tail = find-> m_prev; 218 *tail = find-> m_prev;
215 219
216 //printf ( "DUP\n" );
217
218 break; // there can be only one duplicate 220 break; // there can be only one duplicate
219 } 221 }
220 } 222 }
@@ -247,7 +249,7 @@ static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t *
247 249
248 250
249 251
250static int mod_insert ( char *mod, int argc, char **argv, int autoclean, int quiet, int do_syslog, int show_only, int verbose ) 252static int mod_insert ( char *mod, int argc, char **argv )
251{ 253{
252 struct mod_list_t *tail = 0; 254 struct mod_list_t *tail = 0;
253 struct mod_list_t *head = 0; 255 struct mod_list_t *head = 0;
@@ -258,10 +260,14 @@ static int mod_insert ( char *mod, int argc, char **argv, int autoclean, int qui
258 260
259 if ( head && tail ) { 261 if ( head && tail ) {
260 int i; 262 int i;
263 int l = 0;
261 264
262 // append module args 265 // append module args
263 head-> m_module = xmalloc ( 256 ); 266 l = xstrlen ( mod );
264 strcpy ( head-> m_module, mod ); 267 for ( i = 0; i < argc; i++ )
268 l += ( xstrlen ( argv [i] ) + 1 );
269
270 head-> m_module = xstrndup ( mod, l );
265 271
266 for ( i = 0; i < argc; i++ ) { 272 for ( i = 0; i < argc; i++ ) {
267 strcat ( head-> m_module, " " ); 273 strcat ( head-> m_module, " " );
@@ -269,7 +275,7 @@ static int mod_insert ( char *mod, int argc, char **argv, int autoclean, int qui
269 } 275 }
270 276
271 // process tail ---> head 277 // process tail ---> head
272 rc |= mod_process ( tail, 1, autoclean, quiet, do_syslog, show_only, verbose ); 278 rc |= mod_process ( tail, 1 );
273 } 279 }
274 else 280 else
275 rc = 1; 281 rc = 1;
@@ -277,7 +283,7 @@ static int mod_insert ( char *mod, int argc, char **argv, int autoclean, int qui
277 return rc; 283 return rc;
278} 284}
279 285
280static void mod_remove ( char *mod, int do_syslog, int show_only, int verbose ) 286static void mod_remove ( char *mod )
281{ 287{
282 static struct mod_list_t rm_a_dummy = { "-a", 0, 0 }; 288 static struct mod_list_t rm_a_dummy = { "-a", 0, 0 };
283 289
@@ -289,38 +295,35 @@ static void mod_remove ( char *mod, int do_syslog, int show_only, int verbose )
289 else // autoclean 295 else // autoclean
290 head = tail = &rm_a_dummy; 296 head = tail = &rm_a_dummy;
291 297
292 if ( head && tail ) { 298 if ( head && tail )
293 // process head ---> tail 299 mod_process ( head, 0 ); // process head ---> tail
294 mod_process ( head, 0, 0, 0, do_syslog, show_only, verbose );
295 }
296} 300}
297 301
298 302
299 303
300extern int modprobe_main(int argc, char** argv) 304extern int modprobe_main(int argc, char** argv)
301{ 305{
302 int ch, rc = 0; 306 int opt;
303 int loadall = 0, showconfig = 0, debug = 0, autoclean = 0, list = 0; 307 int remove_opt = 0;
304 int show_only = 0, quiet = 0, remove_opt = 0, do_syslog = 0, verbose = 0; 308
305 char *load_type = NULL, *config = NULL; 309 autoclean = show_only = quiet = do_syslog = verbose = 0;
306 310
307 while ((ch = getopt(argc, argv, "acdklnqrst:vVC:")) != -1) 311 while ((opt = getopt(argc, argv, "acdklnqrst:vVC:")) != -1) {
308 switch(ch) { 312 switch(opt) {
309 case 'a': 313 case 'c': // no config used
310 loadall++; 314 case 'l': // no pattern matching
311 break; 315 return EXIT_SUCCESS;
312 case 'c':
313 showconfig++;
314 break; 316 break;
315 case 'd': 317 case 'C': // no config used
316 debug++; 318 case 't': // no pattern matching
319 error_msg_and_die("-t and -C not supported");
320
321 case 'a': // ignore
322 case 'd': // ignore
317 break; 323 break;
318 case 'k': 324 case 'k':
319 autoclean++; 325 autoclean++;
320 break; 326 break;
321 case 'l':
322 list++;
323 break;
324 case 'n': 327 case 'n':
325 show_only++; 328 show_only++;
326 break; 329 break;
@@ -333,55 +336,34 @@ extern int modprobe_main(int argc, char** argv)
333 case 's': 336 case 's':
334 do_syslog++; 337 do_syslog++;
335 break; 338 break;
336 case 't':
337 load_type = optarg;
338 break;
339 case 'v': 339 case 'v':
340 verbose++; 340 verbose++;
341 break; 341 break;
342 case 'C':
343 config = optarg;
344 break;
345 case 'V': 342 case 'V':
346 default: 343 default:
347 show_usage(); 344 show_usage();
348 break; 345 break;
349 } 346 }
350
351 if (load_type || config) {
352 fprintf(stderr, "-t and -C not supported\n");
353 exit(EXIT_FAILURE);
354 } 347 }
355
356 if (showconfig)
357 exit(EXIT_SUCCESS);
358
359 if (list)
360 exit(EXIT_SUCCESS);
361 348
362 depend = build_dep ( ); 349 depend = build_dep ( );
363 350
364 if ( !depend ) { 351 if ( !depend )
365 fprintf (stderr, "could not parse modules.dep\n" ); 352 error_msg_and_die ( "could not parse modules.dep\n" );
366 exit (EXIT_FAILURE);
367 }
368 353
369 if (remove_opt) { 354 if (remove_opt) {
370 do { 355 do {
371 mod_remove ( optind < argc ? argv [optind] : 0, do_syslog, show_only, verbose ); 356 mod_remove ( optind < argc ? argv [optind] : 0 );
372 } while ( ++optind < argc ); 357 } while ( ++optind < argc );
373 358
374 exit(EXIT_SUCCESS); 359 return EXIT_SUCCESS;
375 } 360 }
376 361
377 if (optind >= argc) { 362 if (optind >= argc)
378 fprintf(stderr, "No module or pattern provided\n"); 363 error_msg_and_die ( "No module or pattern provided\n" );
379 exit(EXIT_FAILURE);
380 }
381 364
382 rc = mod_insert ( argv [optind], argc - optind - 1, argv + optind + 1, autoclean, quiet, do_syslog, show_only, verbose ); 365 return mod_insert ( argv [optind], argc - optind - 1, argv + optind + 1 ) ? \
383 366 EXIT_FAILURE : EXIT_SUCCESS;
384 exit(rc ? EXIT_FAILURE : EXIT_SUCCESS);
385} 367}
386 368
387 369