diff options
author | Denys Vlasenko | 2010-03-30 15:03:26 +0200 |
---|---|---|
committer | Denys Vlasenko | 2010-03-30 15:03:26 +0200 |
commit | eab75f6049595a5f4261abf73a87ea8d6f6ae0f9 (patch) | |
tree | 8017ea38aa9cb76be66c9e7ef1ab749e2cbfee39 /archival | |
parent | 3d43aed10c94bfcfc4a85b9b66bc60c18d22c2b1 (diff) | |
download | busybox-eab75f6049595a5f4261abf73a87ea8d6f6ae0f9.zip busybox-eab75f6049595a5f4261abf73a87ea8d6f6ae0f9.tar.gz |
dpkg: better check for validity of options
function old new delta
dpkg_main 3980 4008 +28
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'archival')
-rw-r--r-- | archival/dpkg.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/archival/dpkg.c b/archival/dpkg.c index befb91d..7caccef 100644 --- a/archival/dpkg.c +++ b/archival/dpkg.c @@ -245,7 +245,7 @@ static int version_compare(const unsigned ver1, const unsigned ver2) { char *ch_ver1 = name_hashtable[ver1]; char *ch_ver2 = name_hashtable[ver2]; - unsigned long epoch1 = 0, epoch2 = 0; + unsigned epoch1 = 0, epoch2 = 0; char *colon; char *deb_ver1, *deb_ver2; char *upstream_ver1; @@ -278,17 +278,16 @@ static int version_compare(const unsigned ver1, const unsigned ver2) deb_ver1 = strrchr(upstream_ver1, '-'); deb_ver2 = strrchr(upstream_ver2, '-'); if (deb_ver1) { - deb_ver1[0] = '\0'; - deb_ver1++; + *deb_ver1++ = '\0'; } if (deb_ver2) { - deb_ver2[0] = '\0'; - deb_ver2++; + *deb_ver2++ = '\0'; } result = version_compare_part(upstream_ver1, upstream_ver2); - if (!result) + if (result == 0) { /* Compare debian versions */ result = version_compare_part(deb_ver1, deb_ver2); + } free(upstream_ver1); free(upstream_ver2); @@ -1570,13 +1569,16 @@ static void FAST_FUNC data_extract_all_prefix(archive_handle_t *archive_handle) } enum { + /* Commands */ OPT_configure = (1 << 0), - OPT_force = (1 << 1), - OPT_install = (1 << 2), - OPT_list_installed = (1 << 3), - OPT_purge = (1 << 4), - OPT_remove = (1 << 5), - OPT_unpack = (1 << 6), + OPT_install = (1 << 1), + OPT_list_installed = (1 << 2), + OPT_purge = (1 << 3), + OPT_remove = (1 << 4), + OPT_unpack = (1 << 5), + OPTMASK_cmd = (1 << 6) - 1, + /* Options */ + OPT_force = (1 << 6), OPT_force_ignore_depends = (1 << 7), OPT_force_confnew = (1 << 8), OPT_force_confold = (1 << 9), @@ -1716,7 +1718,8 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv) INIT_G(); IF_LONG_OPTS(applet_long_options = dpkg_longopts); - opt = getopt32(argv, "CF:ilPru", &str_f); + opt = getopt32(argv, "CilPruF:", &str_f); + argv += optind; //if (opt & OPT_configure) ... // -C if (opt & OPT_force) { // -F (--force in official dpkg) if (strcmp(str_f, "depends") == 0) @@ -1725,7 +1728,8 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv) opt |= OPT_force_confnew; else if (strcmp(str_f, "confold") == 0) opt |= OPT_force_confold; - else bb_show_usage(); + else + bb_show_usage(); option_mask32 = opt; } //if (opt & OPT_install) ... // -i @@ -1733,17 +1737,19 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv) //if (opt & OPT_purge) ... // -P //if (opt & OPT_remove) ... // -r //if (opt & OPT_unpack) ... // -u (--unpack in official dpkg) - argv += optind; - /* check for non-option argument if expected */ - if (!opt || (!argv[0] && !(opt & OPT_list_installed))) + if (!(opt & OPTMASK_cmd) /* no cmd */ + || ((opt & OPTMASK_cmd) & ((opt & OPTMASK_cmd)-1)) /* more than one cmd */ + || (!(opt & OPT_list_installed) && !argv[0]) /* - all except -l require argument */ + ) { bb_show_usage(); + } /* puts("(Reading database ... xxxxx files and directories installed.)"); */ index_status_file("/var/lib/dpkg/status"); /* if the list action was given print the installed packages and exit */ if (opt & OPT_list_installed) { - list_packages(argv[0]); + list_packages(argv[0]); /* param can be NULL */ return EXIT_SUCCESS; } |