fix insmod crash when the module is not found
[openwrt/staging/chunkeey.git] / package / busybox / patches / 470-insmod_search.patch
index 26c5650eb63e010f9a66afe25f6b63bcd15426cc..2064b465c14803abef6213f156351f3a83ef7689 100644 (file)
@@ -1,8 +1,8 @@
 Index: busybox-1.7.2/modutils/insmod.c
 ===================================================================
---- busybox-1.7.2.orig/modutils/insmod.c       2007-09-03 13:48:35.000000000 +0200
-+++ busybox-1.7.2/modutils/insmod.c    2007-10-05 01:43:47.686834357 +0200
-@@ -61,19 +61,107 @@
+--- busybox-1.7.2.orig/modutils/insmod.c       2007-10-08 22:22:17.132454529 +0200
++++ busybox-1.7.2/modutils/insmod.c    2007-10-08 22:29:04.267655851 +0200
+@@ -61,19 +61,110 @@
  #include "libbb.h"
  #include <libgen.h>
  #include <sys/utsname.h>
@@ -101,12 +101,15 @@ Index: busybox-1.7.2/modutils/insmod.c
 +              check_module_name_match, 0, filename, 0);
 +
 +      /* Check if we have a complete path */
-+      if (g_filename != NULL) {
-+              if ((stat(g_filename, &st) == 0) && S_ISREG(st.st_mode))
-+                      ret = 0;
-+              else
-+                      free(g_filename);
-+      }
++      if (g_filename == NULL)
++              goto done;
++
++      if ((stat(g_filename, &st) == 0) && S_ISREG(st.st_mode))
++              ret = 0;
++      else
++              free(g_filename);
++
++done:
 +      free(filename);
 +
 +      return ret;
@@ -114,7 +117,7 @@ Index: busybox-1.7.2/modutils/insmod.c
  
  
  #if ENABLE_FEATURE_2_4_MODULES
-@@ -677,7 +765,6 @@
+@@ -677,7 +768,6 @@
  #endif
  
  
@@ -122,7 +125,7 @@ Index: busybox-1.7.2/modutils/insmod.c
  enum { STRVERSIONLEN = 64 };
  
  /*======================================================================*/
-@@ -790,37 +877,6 @@
+@@ -790,37 +880,6 @@
  static int n_ext_modules_used;
  extern int delete_module(const char *);
  
@@ -160,7 +163,7 @@ Index: busybox-1.7.2/modutils/insmod.c
  static struct obj_file *arch_new_file(void)
  {
        struct arch_file *f;
-@@ -3952,33 +4008,35 @@
+@@ -3952,145 +4011,57 @@
  void print_load_map(struct obj_file *f);
  #endif
  
@@ -169,15 +172,16 @@ Index: busybox-1.7.2/modutils/insmod.c
 +int insmod_main_24( int argc, char **argv)
  {
        char *opt_o, *arg1;
-       int len;
+-      int len;
        int k_crcs;
 -      char *tmp, *tmp1;
        unsigned long m_size;
        ElfW(Addr) m_addr;
        struct obj_file *f;
-       struct stat st;
-       char *m_name = 0;
+-      struct stat st;
+-      char *m_name = 0;
 -      int exit_status = EXIT_FAILURE;
++      char *tmp = NULL, *m_name = NULL;
 +      int ret = EINVAL;
        int m_has_modinfo;
  #if ENABLE_FEATURE_INSMOD_VERSION_CHECKING
@@ -206,7 +210,8 @@ Index: busybox-1.7.2/modutils/insmod.c
        /* Parse any options */
        getopt32(argv, OPTION_STR, &opt_o);
        arg1 = argv[optind];
-@@ -3987,110 +4045,18 @@
+       if (option_mask32 & OPT_o) { // -o /* name the output module */
+-              free(m_name);
                m_name = xstrdup(opt_o);
        }
  
@@ -239,21 +244,26 @@ Index: busybox-1.7.2/modutils/insmod.c
 -                      tmp[len] = '\0';
 -              }
 -
--
 -#if ENABLE_FEATURE_2_6_MODULES
 -      if (k_version > 4)
 -              m_fullName = xasprintf("%s.ko", tmp);
 -      else
 -#endif
 -              m_fullName = xasprintf("%s.o", tmp);
++      ret = find_module(arg1);
++      if (ret)
++              goto out;
  
--      if (!m_name) {
+       if (!m_name) {
 -              m_name = tmp;
 -      } else {
 -              free(tmp1);
 -              tmp1 = 0;       /* flag for free(m_name) before exit() */
--      }
--
++              tmp = xstrdup(arg1);
++              m_name = basename(tmp);
+       }
 -      /* Get a filedesc for the module.  Check we we have a complete path */
 -      if (stat(arg1, &st) < 0 || !S_ISREG(st.st_mode)
 -       || (fp = fopen(arg1, "r")) == NULL
@@ -307,10 +317,7 @@ Index: busybox-1.7.2/modutils/insmod.c
 -
 -      if (flag_verbose)
 -              printf("Using %s\n", m_filename);
-+      ret = find_module(arg1);
-+      if (ret)
-+              goto out;
+-
 -#if ENABLE_FEATURE_2_6_MODULES
 -      if (k_version > 4) {
 -              argv[optind] = m_filename;
@@ -325,7 +332,7 @@ Index: busybox-1.7.2/modutils/insmod.c
  
        f = obj_load(fp, LOADBITS);
        if (f == NULL)
-@@ -4120,7 +4086,7 @@
+@@ -4120,7 +4091,7 @@
                                "\t%s was compiled for kernel version %s\n"
                                "\twhile this kernel is version %s",
                                flag_force_load ? "warning: " : "",
@@ -334,7 +341,7 @@ Index: busybox-1.7.2/modutils/insmod.c
                        if (!flag_force_load)
                                goto out;
                }
-@@ -4173,7 +4139,7 @@
+@@ -4173,7 +4144,7 @@
        hide_special_symbols(f);
  
  #if ENABLE_FEATURE_INSMOD_KSYMOOPS_SYMBOLS
@@ -343,7 +350,7 @@ Index: busybox-1.7.2/modutils/insmod.c
  #endif /* FEATURE_INSMOD_KSYMOOPS_SYMBOLS */
  
        new_create_module_ksymtab(f);
-@@ -4220,8 +4186,7 @@
+@@ -4220,30 +4191,22 @@
        if (flag_print_load_map)
                print_load_map(f);
  
@@ -353,14 +360,18 @@ Index: busybox-1.7.2/modutils/insmod.c
  out:
  #if ENABLE_FEATURE_CLEAN_UP
        if (fp)
-@@ -4229,21 +4194,13 @@
-       free(tmp1);
-       if (!tmp1)
+               fclose(fp);
+-      free(tmp1);
+-      if (!tmp1)
++      if (tmp)
++              free(tmp);
++      else if (m_name)
                free(m_name);
 -      free(m_filename);
 +      free(g_filename);
  #endif
-       return exit_status;
+-      return exit_status;
++      return ret;
  }
 -
 -
@@ -376,7 +387,7 @@ Index: busybox-1.7.2/modutils/insmod.c
  /* We use error numbers in a loose translation... */
  static const char *moderror(int err)
  {
-@@ -4261,19 +4218,33 @@
+@@ -4261,19 +4224,32 @@
        }
  }
  
@@ -407,15 +418,14 @@ Index: busybox-1.7.2/modutils/insmod.c
        if (!filename)
                bb_show_usage();
  
-+      g_filename = filename;
 +      ret = find_module(filename);
-+      if (ret)
++      if (ret || (g_filename == NULL))
 +              goto done;
 +
        /* Rest is options */
        options = xzalloc(1);
        optlen = 0;
-@@ -4283,36 +4254,46 @@
+@@ -4283,36 +4259,47 @@
                optlen += sprintf(options + optlen, (strchr(*argv,' ') ? "\"%s\" " : "%s "), *argv);
        }
  
@@ -463,6 +473,7 @@ Index: busybox-1.7.2/modutils/insmod.c
 +{
 +      int ret;
 +
++      g_filename = NULL;
 +#if ENABLE_FEATURE_2_6_MODULES
 +      ret = insmod_main_26(argc, argv);
 +      if (ret != ENOTSUP)