diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-30 15:03:26 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-30 15:03:26 +0200 |
commit | eab75f6049595a5f4261abf73a87ea8d6f6ae0f9 (patch) | |
tree | 8017ea38aa9cb76be66c9e7ef1ab749e2cbfee39 | |
parent | 3d43aed10c94bfcfc4a85b9b66bc60c18d22c2b1 (diff) | |
download | busybox-w32-eab75f6049595a5f4261abf73a87ea8d6f6ae0f9.tar.gz busybox-w32-eab75f6049595a5f4261abf73a87ea8d6f6ae0f9.tar.bz2 busybox-w32-eab75f6049595a5f4261abf73a87ea8d6f6ae0f9.zip |
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>
-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 befb91d6a..7caccef7c 100644 --- a/archival/dpkg.c +++ b/archival/dpkg.c | |||
@@ -245,7 +245,7 @@ static int version_compare(const unsigned ver1, const unsigned ver2) | |||
245 | { | 245 | { |
246 | char *ch_ver1 = name_hashtable[ver1]; | 246 | char *ch_ver1 = name_hashtable[ver1]; |
247 | char *ch_ver2 = name_hashtable[ver2]; | 247 | char *ch_ver2 = name_hashtable[ver2]; |
248 | unsigned long epoch1 = 0, epoch2 = 0; | 248 | unsigned epoch1 = 0, epoch2 = 0; |
249 | char *colon; | 249 | char *colon; |
250 | char *deb_ver1, *deb_ver2; | 250 | char *deb_ver1, *deb_ver2; |
251 | char *upstream_ver1; | 251 | char *upstream_ver1; |
@@ -278,17 +278,16 @@ static int version_compare(const unsigned ver1, const unsigned ver2) | |||
278 | deb_ver1 = strrchr(upstream_ver1, '-'); | 278 | deb_ver1 = strrchr(upstream_ver1, '-'); |
279 | deb_ver2 = strrchr(upstream_ver2, '-'); | 279 | deb_ver2 = strrchr(upstream_ver2, '-'); |
280 | if (deb_ver1) { | 280 | if (deb_ver1) { |
281 | deb_ver1[0] = '\0'; | 281 | *deb_ver1++ = '\0'; |
282 | deb_ver1++; | ||
283 | } | 282 | } |
284 | if (deb_ver2) { | 283 | if (deb_ver2) { |
285 | deb_ver2[0] = '\0'; | 284 | *deb_ver2++ = '\0'; |
286 | deb_ver2++; | ||
287 | } | 285 | } |
288 | result = version_compare_part(upstream_ver1, upstream_ver2); | 286 | result = version_compare_part(upstream_ver1, upstream_ver2); |
289 | if (!result) | 287 | if (result == 0) { |
290 | /* Compare debian versions */ | 288 | /* Compare debian versions */ |
291 | result = version_compare_part(deb_ver1, deb_ver2); | 289 | result = version_compare_part(deb_ver1, deb_ver2); |
290 | } | ||
292 | 291 | ||
293 | free(upstream_ver1); | 292 | free(upstream_ver1); |
294 | free(upstream_ver2); | 293 | free(upstream_ver2); |
@@ -1570,13 +1569,16 @@ static void FAST_FUNC data_extract_all_prefix(archive_handle_t *archive_handle) | |||
1570 | } | 1569 | } |
1571 | 1570 | ||
1572 | enum { | 1571 | enum { |
1572 | /* Commands */ | ||
1573 | OPT_configure = (1 << 0), | 1573 | OPT_configure = (1 << 0), |
1574 | OPT_force = (1 << 1), | 1574 | OPT_install = (1 << 1), |
1575 | OPT_install = (1 << 2), | 1575 | OPT_list_installed = (1 << 2), |
1576 | OPT_list_installed = (1 << 3), | 1576 | OPT_purge = (1 << 3), |
1577 | OPT_purge = (1 << 4), | 1577 | OPT_remove = (1 << 4), |
1578 | OPT_remove = (1 << 5), | 1578 | OPT_unpack = (1 << 5), |
1579 | OPT_unpack = (1 << 6), | 1579 | OPTMASK_cmd = (1 << 6) - 1, |
1580 | /* Options */ | ||
1581 | OPT_force = (1 << 6), | ||
1580 | OPT_force_ignore_depends = (1 << 7), | 1582 | OPT_force_ignore_depends = (1 << 7), |
1581 | OPT_force_confnew = (1 << 8), | 1583 | OPT_force_confnew = (1 << 8), |
1582 | OPT_force_confold = (1 << 9), | 1584 | OPT_force_confold = (1 << 9), |
@@ -1716,7 +1718,8 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv) | |||
1716 | INIT_G(); | 1718 | INIT_G(); |
1717 | 1719 | ||
1718 | IF_LONG_OPTS(applet_long_options = dpkg_longopts); | 1720 | IF_LONG_OPTS(applet_long_options = dpkg_longopts); |
1719 | opt = getopt32(argv, "CF:ilPru", &str_f); | 1721 | opt = getopt32(argv, "CilPruF:", &str_f); |
1722 | argv += optind; | ||
1720 | //if (opt & OPT_configure) ... // -C | 1723 | //if (opt & OPT_configure) ... // -C |
1721 | if (opt & OPT_force) { // -F (--force in official dpkg) | 1724 | if (opt & OPT_force) { // -F (--force in official dpkg) |
1722 | if (strcmp(str_f, "depends") == 0) | 1725 | if (strcmp(str_f, "depends") == 0) |
@@ -1725,7 +1728,8 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv) | |||
1725 | opt |= OPT_force_confnew; | 1728 | opt |= OPT_force_confnew; |
1726 | else if (strcmp(str_f, "confold") == 0) | 1729 | else if (strcmp(str_f, "confold") == 0) |
1727 | opt |= OPT_force_confold; | 1730 | opt |= OPT_force_confold; |
1728 | else bb_show_usage(); | 1731 | else |
1732 | bb_show_usage(); | ||
1729 | option_mask32 = opt; | 1733 | option_mask32 = opt; |
1730 | } | 1734 | } |
1731 | //if (opt & OPT_install) ... // -i | 1735 | //if (opt & OPT_install) ... // -i |
@@ -1733,17 +1737,19 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv) | |||
1733 | //if (opt & OPT_purge) ... // -P | 1737 | //if (opt & OPT_purge) ... // -P |
1734 | //if (opt & OPT_remove) ... // -r | 1738 | //if (opt & OPT_remove) ... // -r |
1735 | //if (opt & OPT_unpack) ... // -u (--unpack in official dpkg) | 1739 | //if (opt & OPT_unpack) ... // -u (--unpack in official dpkg) |
1736 | argv += optind; | 1740 | if (!(opt & OPTMASK_cmd) /* no cmd */ |
1737 | /* check for non-option argument if expected */ | 1741 | || ((opt & OPTMASK_cmd) & ((opt & OPTMASK_cmd)-1)) /* more than one cmd */ |
1738 | if (!opt || (!argv[0] && !(opt & OPT_list_installed))) | 1742 | || (!(opt & OPT_list_installed) && !argv[0]) /* - all except -l require argument */ |
1743 | ) { | ||
1739 | bb_show_usage(); | 1744 | bb_show_usage(); |
1745 | } | ||
1740 | 1746 | ||
1741 | /* puts("(Reading database ... xxxxx files and directories installed.)"); */ | 1747 | /* puts("(Reading database ... xxxxx files and directories installed.)"); */ |
1742 | index_status_file("/var/lib/dpkg/status"); | 1748 | index_status_file("/var/lib/dpkg/status"); |
1743 | 1749 | ||
1744 | /* if the list action was given print the installed packages and exit */ | 1750 | /* if the list action was given print the installed packages and exit */ |
1745 | if (opt & OPT_list_installed) { | 1751 | if (opt & OPT_list_installed) { |
1746 | list_packages(argv[0]); | 1752 | list_packages(argv[0]); /* param can be NULL */ |
1747 | return EXIT_SUCCESS; | 1753 | return EXIT_SUCCESS; |
1748 | } | 1754 | } |
1749 | 1755 | ||