diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-01-17 14:58:27 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-01-17 14:58:27 +0100 |
commit | 094cc51e50bdb877fa4c245dbde47e4dfbf94387 (patch) | |
tree | 2a9eaa84a5bfd0432847ce9f1ff5e6472ce3df72 | |
parent | 10ee20b58b77bdfb941480fdf4b95347c2b2ea79 (diff) | |
download | busybox-w32-094cc51e50bdb877fa4c245dbde47e4dfbf94387.tar.gz busybox-w32-094cc51e50bdb877fa4c245dbde47e4dfbf94387.tar.bz2 busybox-w32-094cc51e50bdb877fa4c245dbde47e4dfbf94387.zip |
insmod: check for module read errors
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/libbb.h | 4 | ||||
-rw-r--r-- | modutils/modprobe-small.c | 3 |
2 files changed, 5 insertions, 2 deletions
diff --git a/include/libbb.h b/include/libbb.h index 67dfbc361..55510316b 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -674,6 +674,8 @@ extern char *xmalloc_reads(int fd, char *pfx, size_t *maxsz_p) FAST_FUNC; | |||
674 | extern void *xmalloc_read(int fd, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; | 674 | extern void *xmalloc_read(int fd, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; |
675 | /* Returns NULL if file can't be opened (default max size: INT_MAX - 4095) */ | 675 | /* Returns NULL if file can't be opened (default max size: INT_MAX - 4095) */ |
676 | extern void *xmalloc_open_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; | 676 | extern void *xmalloc_open_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; |
677 | /* Never returns NULL */ | ||
678 | extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; | ||
677 | /* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */ | 679 | /* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */ |
678 | #if ENABLE_FEATURE_SEAMLESS_LZMA \ | 680 | #if ENABLE_FEATURE_SEAMLESS_LZMA \ |
679 | || ENABLE_FEATURE_SEAMLESS_BZ2 \ | 681 | || ENABLE_FEATURE_SEAMLESS_BZ2 \ |
@@ -686,8 +688,6 @@ extern void setup_unzip_on_fd(int fd /*, int fail_if_not_detected*/) FAST_FUNC; | |||
686 | /* Autodetects .gz etc */ | 688 | /* Autodetects .gz etc */ |
687 | extern int open_zipped(const char *fname) FAST_FUNC; | 689 | extern int open_zipped(const char *fname) FAST_FUNC; |
688 | extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; | 690 | extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; |
689 | /* Never returns NULL */ | ||
690 | extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; | ||
691 | 691 | ||
692 | extern ssize_t safe_write(int fd, const void *buf, size_t count) FAST_FUNC; | 692 | extern ssize_t safe_write(int fd, const void *buf, size_t count) FAST_FUNC; |
693 | // NB: will return short write on error, not -1, | 693 | // NB: will return short write on error, not -1, |
diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c index f4f17e766..188a7f229 100644 --- a/modutils/modprobe-small.c +++ b/modutils/modprobe-small.c | |||
@@ -205,6 +205,7 @@ static void parse_module(module_info *info, const char *pathname) | |||
205 | /* Read (possibly compressed) module */ | 205 | /* Read (possibly compressed) module */ |
206 | len = 64 * 1024 * 1024; /* 64 Mb at most */ | 206 | len = 64 * 1024 * 1024; /* 64 Mb at most */ |
207 | module_image = xmalloc_open_zipped_read_close(pathname, &len); | 207 | module_image = xmalloc_open_zipped_read_close(pathname, &len); |
208 | /* module_image == NULL is ok here, find_keyword handles it */ | ||
208 | //TODO: optimize redundant module body reads | 209 | //TODO: optimize redundant module body reads |
209 | 210 | ||
210 | /* "alias1 symbol:sym1 alias2 symbol:sym2" */ | 211 | /* "alias1 symbol:sym1 alias2 symbol:sym2" */ |
@@ -845,6 +846,8 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv) | |||
845 | 846 | ||
846 | len = MAXINT(ssize_t); | 847 | len = MAXINT(ssize_t); |
847 | map = xmalloc_open_zipped_read_close(*argv, &len); | 848 | map = xmalloc_open_zipped_read_close(*argv, &len); |
849 | if (!map) | ||
850 | bb_perror_msg_and_die("can't read '%s'", *argv); | ||
848 | if (init_module(map, len, | 851 | if (init_module(map, len, |
849 | IF_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(options ? options : "") | 852 | IF_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(options ? options : "") |
850 | IF_NOT_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE("") | 853 | IF_NOT_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE("") |