aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modutils/insmod.c60
1 files changed, 35 insertions, 25 deletions
diff --git a/modutils/insmod.c b/modutils/insmod.c
index e65f874ea..094ef1279 100644
--- a/modutils/insmod.c
+++ b/modutils/insmod.c
@@ -233,7 +233,7 @@
233#ifndef MODUTILS_MODULE_H 233#ifndef MODUTILS_MODULE_H
234static const int MODUTILS_MODULE_H = 1; 234static const int MODUTILS_MODULE_H = 1;
235 235
236#ident "$Id: insmod.c,v 1.85 2002/06/18 05:16:25 andersen Exp $" 236#ident "$Id: insmod.c,v 1.86 2002/06/22 17:15:42 andersen Exp $"
237 237
238/* This file contains the structures used by the 2.0 and 2.1 kernels. 238/* This file contains the structures used by the 2.0 and 2.1 kernels.
239 We do not use the kernel headers directly because we do not wish 239 We do not use the kernel headers directly because we do not wish
@@ -454,7 +454,7 @@ int delete_module(const char *);
454#ifndef MODUTILS_OBJ_H 454#ifndef MODUTILS_OBJ_H
455static const int MODUTILS_OBJ_H = 1; 455static const int MODUTILS_OBJ_H = 1;
456 456
457#ident "$Id: insmod.c,v 1.85 2002/06/18 05:16:25 andersen Exp $" 457#ident "$Id: insmod.c,v 1.86 2002/06/22 17:15:42 andersen Exp $"
458 458
459/* The relocatable object is manipulated using elfin types. */ 459/* The relocatable object is manipulated using elfin types. */
460 460
@@ -738,7 +738,7 @@ static int n_ext_modules;
738static int n_ext_modules_used; 738static int n_ext_modules_used;
739extern int delete_module(const char *); 739extern int delete_module(const char *);
740 740
741static char m_filename[FILENAME_MAX]; 741static char *m_filename;
742static char m_fullName[FILENAME_MAX]; 742static char m_fullName[FILENAME_MAX];
743 743
744 744
@@ -759,7 +759,7 @@ static int check_module_name_match(const char *filename, struct stat *statbuf,
759 if (strcmp(tmp, fullname) == 0) { 759 if (strcmp(tmp, fullname) == 0) {
760 free(tmp1); 760 free(tmp1);
761 /* Stop searching if we find a match */ 761 /* Stop searching if we find a match */
762 safe_strncpy(m_filename, filename, sizeof(m_filename)); 762 m_filename = xstrdup(filename);
763 return (TRUE); 763 return (TRUE);
764 } 764 }
765 free(tmp1); 765 free(tmp1);
@@ -3429,10 +3429,9 @@ extern int insmod_main( int argc, char **argv)
3429 char *tmp, *tmp1; 3429 char *tmp, *tmp1;
3430 unsigned long m_size; 3430 unsigned long m_size;
3431 ElfW(Addr) m_addr; 3431 ElfW(Addr) m_addr;
3432 FILE *fp;
3433 struct obj_file *f; 3432 struct obj_file *f;
3434 struct stat st; 3433 struct stat st;
3435 char m_name[FILENAME_MAX] = "\0"; 3434 char *m_name = 0;
3436 int exit_status = EXIT_FAILURE; 3435 int exit_status = EXIT_FAILURE;
3437 int m_has_modinfo; 3436 int m_has_modinfo;
3438#ifdef CONFIG_FEATURE_INSMOD_VERSION_CHECKING 3437#ifdef CONFIG_FEATURE_INSMOD_VERSION_CHECKING
@@ -3441,6 +3440,11 @@ extern int insmod_main( int argc, char **argv)
3441 int m_version; 3440 int m_version;
3442 int m_crcs; 3441 int m_crcs;
3443#endif 3442#endif
3443#ifdef CONFIG_FEATURE_CLEAN_UP
3444 FILE *fp = 0;
3445#else
3446 FILE *fp;
3447#endif
3444 3448
3445 /* Parse any options */ 3449 /* Parse any options */
3446 while ((opt = getopt(argc, argv, "fksvxLo:")) > 0) { 3450 while ((opt = getopt(argc, argv, "fksvxLo:")) > 0) {
@@ -3464,7 +3468,9 @@ extern int insmod_main( int argc, char **argv)
3464 flag_export = 0; 3468 flag_export = 0;
3465 break; 3469 break;
3466 case 'o': /* name the output module */ 3470 case 'o': /* name the output module */
3467 safe_strncpy(m_name, optarg, sizeof(m_name)); 3471 if(m_name) /* Hmmm, duplicate "-o name". */
3472 free(m_name);
3473 m_name = xstrdup(optarg);
3468 break; 3474 break;
3469 case 'L': /* Stub warning */ 3475 case 'L': /* Stub warning */
3470 /* This is needed for compatibility with modprobe. 3476 /* This is needed for compatibility with modprobe.
@@ -3490,22 +3496,17 @@ extern int insmod_main( int argc, char **argv)
3490 len-=2; 3496 len-=2;
3491 tmp[len] = '\0'; 3497 tmp[len] = '\0';
3492 } 3498 }
3493 /* Make sure there is space for the terminal NULL */
3494 len += 1;
3495 3499
3496 if (len >= sizeof(m_fullName)) { 3500 if (len > (sizeof(m_fullName)-3))
3497 len = sizeof(m_fullName); 3501 error_msg_and_die("%s: module name too long", tmp);
3498 } 3502
3499 safe_strncpy(m_fullName, tmp, len); 3503 strcat(strcpy(m_fullName, tmp), ".o");
3500 if (tmp1) 3504 if (!m_name) {
3505 m_name = tmp;
3506 } else {
3501 free(tmp1); 3507 free(tmp1);
3502 if (*m_name == '\0') { 3508 tmp1 = 0; /* flag for free(m_name) before exit() */
3503 safe_strncpy(m_name, m_fullName, sizeof(m_name));
3504 } 3509 }
3505 len = strlen(m_fullName);
3506 if (len > (sizeof(m_fullName)-3))
3507 error_msg_and_die("%s: no module by that name found", m_fullName);
3508 strcat(m_fullName, ".o");
3509 3510
3510 /* Get a filedesc for the module. Check we we have a complete path */ 3511 /* Get a filedesc for the module. Check we we have a complete path */
3511 if (stat(argv[optind], &st) < 0 || !S_ISREG(st.st_mode) || 3512 if (stat(argv[optind], &st) < 0 || !S_ISREG(st.st_mode) ||
@@ -3531,7 +3532,7 @@ extern int insmod_main( int argc, char **argv)
3531 } 3532 }
3532 3533
3533 /* Check if we have found anything yet */ 3534 /* Check if we have found anything yet */
3534 if (m_filename[0] == '\0' || ((fp = fopen(m_filename, "r")) == NULL)) 3535 if (m_filename == 0 || ((fp = fopen(m_filename, "r")) == NULL))
3535 { 3536 {
3536 char module_dir[FILENAME_MAX]; 3537 char module_dir[FILENAME_MAX];
3537 if (realpath (_PATH_MODULES, module_dir) == NULL) 3538 if (realpath (_PATH_MODULES, module_dir) == NULL)
@@ -3541,17 +3542,17 @@ extern int insmod_main( int argc, char **argv)
3541 if (! recursive_action(module_dir, TRUE, FALSE, FALSE, 3542 if (! recursive_action(module_dir, TRUE, FALSE, FALSE,
3542 check_module_name_match, 0, m_fullName)) 3543 check_module_name_match, 0, m_fullName))
3543 { 3544 {
3544 if (m_filename[0] == '\0' 3545 if (m_filename == 0
3545 || ((fp = fopen(m_filename, "r")) == NULL)) 3546 || ((fp = fopen(m_filename, "r")) == NULL))
3546 { 3547 {
3547 error_msg("%s: no module by that name found", m_fullName); 3548 error_msg("%s: no module by that name found", m_fullName);
3548 return EXIT_FAILURE; 3549 goto out;
3549 } 3550 }
3550 } else 3551 } else
3551 error_msg_and_die("%s: no module by that name found", m_fullName); 3552 error_msg_and_die("%s: no module by that name found", m_fullName);
3552 } 3553 }
3553 } else 3554 } else
3554 safe_strncpy(m_filename, argv[optind], sizeof(m_filename)); 3555 m_filename = xstrdup(argv[optind]);
3555 3556
3556 printf("Using %s\n", m_filename); 3557 printf("Using %s\n", m_filename);
3557 3558
@@ -3668,7 +3669,7 @@ extern int insmod_main( int argc, char **argv)
3668 3669
3669 3670
3670 m_addr = create_module(m_name, m_size); 3671 m_addr = create_module(m_name, m_size);
3671 if (m_addr==-1) switch (errno) { 3672 if (m_addr == -1) switch (errno) {
3672 case EEXIST: 3673 case EEXIST:
3673 error_msg("A module named %s already exists", m_name); 3674 error_msg("A module named %s already exists", m_name);
3674 goto out; 3675 goto out;
@@ -3708,6 +3709,15 @@ extern int insmod_main( int argc, char **argv)
3708 exit_status = EXIT_SUCCESS; 3709 exit_status = EXIT_SUCCESS;
3709 3710
3710out: 3711out:
3712#ifdef CONFIG_FEATURE_CLEAN_UP
3713 if(fp)
3711 fclose(fp); 3714 fclose(fp);
3715 if(tmp1) {
3716 free(tmp1);
3717 } else {
3718 free(m_name);
3719 }
3720 free(m_filename);
3721#endif
3712 return(exit_status); 3722 return(exit_status);
3713} 3723}