From 97c8eb0c361e11b67a56d7e3b664b072adc5186d Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 07:59:16 +0200 Subject: [PATCH 01/19] xbps-rindex: fix a double close (CID #98694). --- bin/xbps-rindex/sign.c | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/xbps-rindex/sign.c b/bin/xbps-rindex/sign.c index 68db5a8f..72d09106 100644 --- a/bin/xbps-rindex/sign.c +++ b/bin/xbps-rindex/sign.c @@ -281,6 +281,7 @@ sign_pkg(struct xbps_handle *xhp, const char *binpkg, const char *privkey, bool goto out; } close(binpkg_fd); + binpkg_fd = -1; rsa = load_rsa_key(privkey); if (!rsa_sign_buf(rsa, buf, st.st_size, &sig, &siglen)) { From 090464e4b283150daf98070ae9079060ec38ac0b Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 08:01:29 +0200 Subject: [PATCH 02/19] xbps_sanitize_path: fix an out-of-bounds access (CID #98686). --- lib/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util.c b/lib/util.c index df4a0963..2615ce7c 100644 --- a/lib/util.c +++ b/lib/util.c @@ -437,7 +437,7 @@ xbps_sanitize_path(const char *src) len = strlen(src); assert(len != 0); - dest = malloc(len); + dest = malloc(len+1); assert(dest); d = dest; From 7edabe907f961d8bba0280c1a6e31d8ff4fdb0dd Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 08:03:16 +0200 Subject: [PATCH 03/19] xbps_rpool_release: fix a double free (CID #98695). --- lib/rpool.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/rpool.c b/lib/rpool.c index e7132727..450df6c8 100644 --- a/lib/rpool.c +++ b/lib/rpool.c @@ -127,7 +127,6 @@ xbps_rpool_release(struct xbps_handle *xhp _unused) while ((repo = SIMPLEQ_FIRST(&rpool_queue))) { SIMPLEQ_REMOVE(&rpool_queue, repo, xbps_repo, entries); xbps_repo_close(repo); - free(repo); } if (xhp->repositories) xbps_object_release(xhp->repositories); From 9d70fcd8d0063a897f00b1b3d5e42434f0f9bebb Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 08:06:38 +0200 Subject: [PATCH 04/19] xbps-rindex/index-clean: handle possible NULL pointer derefs (CID #98685). --- bin/xbps-rindex/index-clean.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/xbps-rindex/index-clean.c b/bin/xbps-rindex/index-clean.c index 2c41a82b..0f552564 100644 --- a/bin/xbps-rindex/index-clean.c +++ b/bin/xbps-rindex/index-clean.c @@ -63,6 +63,8 @@ idx_cleaner_cb(struct xbps_handle *xhp, * broken or simply unexistent; either way, remove it. */ pkgname = xbps_pkg_name(pkgver); + if (pkgname == NULL) + goto out; xbps_dictionary_remove(dest, pkgname); free(pkgname); printf("index: removed pkg %s\n", pkgver); @@ -74,11 +76,14 @@ idx_cleaner_cb(struct xbps_handle *xhp, "filename-sha256", &sha256); if (xbps_file_hash_check(filen, sha256) != 0) { pkgname = xbps_pkg_name(pkgver); + if (pkgname == NULL) + goto out; xbps_dictionary_remove(dest, pkgname); free(pkgname); printf("index: removed pkg %s\n", pkgver); } } +out: free(filen); return 0; } From a8d2b1d7423d20093993cb52fad637cf22ad0d36 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 08:08:05 +0200 Subject: [PATCH 05/19] pkgdb: handle possible NULL pointer derefs (CID #98684). --- lib/pkgdb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pkgdb.c b/lib/pkgdb.c index af75fd6e..7e865e7d 100644 --- a/lib/pkgdb.c +++ b/lib/pkgdb.c @@ -151,6 +151,7 @@ pkgdb_map_vpkgs(struct xbps_handle *xhp) xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); pkgname = xbps_pkg_name(pkgver); + assert(pkgname); for (unsigned int i = 0; i < xbps_array_count(provides); i++) { const char *vpkg; From 0b7093e108a5d5208cd2626702d178be7228a634 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 08:10:26 +0200 Subject: [PATCH 06/19] portableproplib/prop_object: handle possible NULL pointer deref (CID #62722). --- lib/portableproplib/prop_object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/portableproplib/prop_object.c b/lib/portableproplib/prop_object.c index 8e9b02a1..0caa8313 100644 --- a/lib/portableproplib/prop_object.c +++ b/lib/portableproplib/prop_object.c @@ -600,7 +600,7 @@ _prop_object_internalize_by_tag(struct _prop_object_internalize_context *ctx) match_start: for (poi = _prop_object_internalizer_table; - poi->poi_tag != NULL; poi++) { + poi != NULL && poi->poi_tag != NULL; poi++) { if (_prop_object_internalize_match(ctx->poic_tagname, ctx->poic_tagname_len, poi->poi_tag, From 7d7f08b559c28fbec71e00363f18bfb724c5aa1f Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 08:12:22 +0200 Subject: [PATCH 07/19] xbps-rindex/sign: fix a resource leak (CID #98687). --- bin/xbps-rindex/sign.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/xbps-rindex/sign.c b/bin/xbps-rindex/sign.c index 72d09106..8d0c0b27 100644 --- a/bin/xbps-rindex/sign.c +++ b/bin/xbps-rindex/sign.c @@ -139,6 +139,8 @@ load_rsa_key(const char *privkey) fprintf(stderr, "%s: failed to read the RSA privkey\n", _XBPS_RINDEX); exit(EXIT_FAILURE); } + free(defprivkey); + defprivkey = NULL; return rsa; } From 28f01b38365c407736aec0590920203f25ff18b9 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 08:15:07 +0200 Subject: [PATCH 08/19] xbps_transaction_package_replace: fix a resource leak (CID #98688). --- lib/transaction_package_replace.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/transaction_package_replace.c b/lib/transaction_package_replace.c index 087f88d3..d8f898de 100644 --- a/lib/transaction_package_replace.c +++ b/lib/transaction_package_replace.c @@ -121,8 +121,12 @@ xbps_transaction_package_replace(struct xbps_handle *xhp, xbps_array_t pkgs) */ xbps_dictionary_set_cstring_nocopy(instd, "transaction", "remove"); - if (!xbps_array_add_first(pkgs, instd)) + if (!xbps_array_add_first(pkgs, instd)) { + xbps_object_iterator_release(iter); + free(pkgname); + free(curpkgname); return EINVAL; + } free(curpkgname); } xbps_object_iterator_release(iter); From 5f56b130fc4659196bf68118d9643e61a2388c25 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 08:17:17 +0200 Subject: [PATCH 09/19] xbps-rindex/index-clean: fix a resouce leak (CID #98689). --- bin/xbps-rindex/index-clean.c | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/xbps-rindex/index-clean.c b/bin/xbps-rindex/index-clean.c index 0f552564..454b43a8 100644 --- a/bin/xbps-rindex/index-clean.c +++ b/bin/xbps-rindex/index-clean.c @@ -114,6 +114,7 @@ index_clean(struct xbps_handle *xhp, const char *repodir) fprintf(stderr, "%s: cannot read repository data: %s\n", _XBPS_RINDEX, strerror(errno)); + xbps_repo_unlock(rlockfd, rlockfname); return rv; } if (repo->idx == NULL) { From e90ed618e823209660b9179e865a79f724592b1b Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 08:18:49 +0200 Subject: [PATCH 10/19] xbps-install/transaction: minor resource leak (CID #98690). --- bin/xbps-install/transaction.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/xbps-install/transaction.c b/bin/xbps-install/transaction.c index 536538fa..70aecdf3 100644 --- a/bin/xbps-install/transaction.c +++ b/bin/xbps-install/transaction.c @@ -322,14 +322,16 @@ exec_transaction(struct xbps_handle *xhp, int maxcols, bool yes, bool drun) if (xbps_humanize_number(instsize, (int64_t)isize) == -1) { xbps_error_printf("humanize_number2 returns " "%s\n", strerror(errno)); - return -1; + rv = -1; + goto out; } xbps_dictionary_get_uint64(xhp->transd, "disk-free-size", &fsize); if (xbps_humanize_number(freesize, (int64_t)fsize) == -1) { xbps_error_printf("humanize_number2 returns " "%s\n", strerror(errno)); - return -1; + rv = -1; + goto out; } fprintf(stderr, "Transaction aborted due to insufficient disk " "space (need %s, got %s free).\n", instsize, freesize); From 61ec2d4540a6c41b96409bddf8130572f5a82542 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 08:19:53 +0200 Subject: [PATCH 11/19] xbps-fbulk: ignore rename(2) return value (CID #98678). --- bin/xbps-fbulk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/xbps-fbulk/main.c b/bin/xbps-fbulk/main.c index e9ed5a53..e08d9116 100644 --- a/bin/xbps-fbulk/main.c +++ b/bin/xbps-fbulk/main.c @@ -202,7 +202,7 @@ processCompletion(struct item *item) else logdir = "bad"; logpath2 = xbps_xasprintf("%s/%s/%s", LogDir, logdir, item->pkgn); - rename(logpath1, logpath2); + (void)rename(logpath1, logpath2); free(logpath1); free(logpath2); } From 582de078f42471668188c074a6418a7e36157183 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 08:21:00 +0200 Subject: [PATCH 12/19] xbps-rindex/sign: ignore fstat(2) return value (CID #98679). --- bin/xbps-rindex/sign.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/xbps-rindex/sign.c b/bin/xbps-rindex/sign.c index 8d0c0b27..d9b4be38 100644 --- a/bin/xbps-rindex/sign.c +++ b/bin/xbps-rindex/sign.c @@ -274,7 +274,7 @@ sign_pkg(struct xbps_handle *xhp, const char *binpkg, const char *privkey, bool rv = EINVAL; goto out; } - fstat(binpkg_fd, &st); + (void)fstat(binpkg_fd, &st); buf = malloc(st.st_size); assert(buf); if (read(binpkg_fd, buf, st.st_size) != st.st_size) { From 58074b535881e4acc66bca05fe654f3c48c8a470 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 08:21:46 +0200 Subject: [PATCH 13/19] xbps-fbulk: ignore remove(2) return value (CID #98680). --- bin/xbps-fbulk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/xbps-fbulk/main.c b/bin/xbps-fbulk/main.c index e08d9116..49f3c7c8 100644 --- a/bin/xbps-fbulk/main.c +++ b/bin/xbps-fbulk/main.c @@ -345,7 +345,7 @@ runBuilds(const char *bpath) * attempts. */ logpath = xbps_xasprintf("%s/bad/%s", LogDir, item->pkgn); - remove(logpath); + (void)remove(logpath); free(logpath); logpath = xbps_xasprintf("%s/run/%s", LogDir, item->pkgn); From 78f9a9798086bab9930ea904e06ea249fcf50eca Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 08:22:27 +0200 Subject: [PATCH 14/19] lib/package_unpack: ignore remove(2) return value (CID #98681). --- lib/package_unpack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/package_unpack.c b/lib/package_unpack.c index 36f7f886..94d7d97b 100644 --- a/lib/package_unpack.c +++ b/lib/package_unpack.c @@ -291,7 +291,7 @@ unpack_archive(struct xbps_handle *xhp, */ if (file_exists && ((entry_statp->st_mode & S_IFMT) != (st.st_mode & S_IFMT))) - remove(entry_pname); + (void)remove(entry_pname); if (!force && (entry_type == AE_IFREG)) { buf = strchr(entry_pname, '.') + 1; From ffbdfeef6380a7b5b67018144356cbc02f90a85d Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 08:38:12 +0200 Subject: [PATCH 15/19] xbps-rindex/index-clean: fix a minor resource leak (CID #98689). --- bin/xbps-rindex/index-clean.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/xbps-rindex/index-clean.c b/bin/xbps-rindex/index-clean.c index 454b43a8..0d16db72 100644 --- a/bin/xbps-rindex/index-clean.c +++ b/bin/xbps-rindex/index-clean.c @@ -109,9 +109,10 @@ index_clean(struct xbps_handle *xhp, const char *repodir) repo = xbps_repo_open(xhp, repodir); if (repo == NULL) { rv = errno; - if (rv == ENOENT) + if (rv == ENOENT) { + xbps_repo_unlock(rlockfd, rlockfname); return 0; - + } fprintf(stderr, "%s: cannot read repository data: %s\n", _XBPS_RINDEX, strerror(errno)); xbps_repo_unlock(rlockfd, rlockfname); From 36026451ce52055460d47ca8d6f5f3c219bb1c6e Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 09:02:04 +0200 Subject: [PATCH 16/19] Fix some insecure temporary files reported by Coverity. --- bin/xbps-create/main.c | 4 +++- bin/xbps-rindex/repoflush.c | 5 ++++- lib/package_script.c | 6 +++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bin/xbps-create/main.c b/bin/xbps-create/main.c index 4544fac5..2735d532 100644 --- a/bin/xbps-create/main.c +++ b/bin/xbps-create/main.c @@ -843,9 +843,11 @@ main(int argc, char **argv) /* * Create a temp file to store archive data. */ - tname = xbps_xasprintf(".xbps-pkg-XXXXXX"); + tname = xbps_xasprintf(".xbps-pkg-XXXXXXXXX"); + myumask = umask(S_IXUSR|S_IRWXG|S_IRWXO); pkg_fd = mkstemp(tname); assert(pkg_fd != -1); + umask(myumask); /* * Process the binary package's archive (ustar compressed with xz). */ diff --git a/bin/xbps-rindex/repoflush.c b/bin/xbps-rindex/repoflush.c index 877560a7..0b56a95e 100644 --- a/bin/xbps-rindex/repoflush.c +++ b/bin/xbps-rindex/repoflush.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2013-2014 Juan Romero Pardines. + * Copyright (c) 2013-2015 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -44,13 +44,16 @@ repodata_flush(struct xbps_handle *xhp, const char *repodir, struct archive *ar; char *repofile, *tname, *buf; int rv, repofd = -1; + mode_t mask; /* Create a tempfile for our repository archive */ repofile = xbps_repo_path(xhp, repodir); tname = xbps_xasprintf("%s.XXXXXXXXXX", repofile); + mask = umask(S_IXUSR|S_IRWXG|S_IRWXO); if ((repofd = mkstemp(tname)) == -1) return false; + umask(mask); /* Create and write our repository archive */ ar = archive_write_new(); assert(ar); diff --git a/lib/package_script.c b/lib/package_script.c index de27459c..690301cf 100644 --- a/lib/package_script.c +++ b/lib/package_script.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2012-2013 Juan Romero Pardines. + * Copyright (c) 2012-2015 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -43,6 +43,7 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp, const char *tmpdir, *version; char *pkgname, *fpath; int fd, rv; + mode_t mask; assert(blob); assert(pkgver); @@ -71,12 +72,15 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp, } /* Create temp file to run script */ + mask = umask(S_IXUSR|S_IRWXG|S_IRWXO); if ((fd = mkstemp(fpath)) == -1) { + umask(mask); rv = errno; xbps_dbg_printf(xhp, "%s: mkstemp %s\n", __func__, strerror(errno)); goto out; } + umask(mask); /* write blob to our temp fd */ ret = write(fd, blob, blobsiz); if (ret == -1) { From 0d3c07cdee2ade448242930afe0fdaf73ce5da39 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 09:11:20 +0200 Subject: [PATCH 17/19] portableproplib/prop_object: fix an insecure temporary file (CID #62739). --- lib/portableproplib/prop_object.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/portableproplib/prop_object.c b/lib/portableproplib/prop_object.c index 0caa8313..5ef6cbb4 100644 --- a/lib/portableproplib/prop_object.c +++ b/lib/portableproplib/prop_object.c @@ -849,8 +849,12 @@ _prop_object_externalize_write_file(const char *fname, const char *xml, strcat(tname, PLISTTMP); #undef PLISTTMP - if ((fd = mkstemp(tname)) == -1) + myumask = umask(S_IXUSR|S_IRWXG|S_IRWXO); + if ((fd = mkstemp(tname)) == -1) { + umask(myymask); return (false); + } + umask(myymask); if (do_compress) { if ((gzf = gzdopen(fd, "a")) == NULL) From 8acc37548714397cd5b3eb3242b2fd5aa1738462 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 26 Jul 2015 09:16:32 +0200 Subject: [PATCH 18/19] portableproplib/prop_object: fix tyops in previous. --- lib/portableproplib/prop_object.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/portableproplib/prop_object.c b/lib/portableproplib/prop_object.c index 5ef6cbb4..c01cff69 100644 --- a/lib/portableproplib/prop_object.c +++ b/lib/portableproplib/prop_object.c @@ -851,10 +851,10 @@ _prop_object_externalize_write_file(const char *fname, const char *xml, myumask = umask(S_IXUSR|S_IRWXG|S_IRWXO); if ((fd = mkstemp(tname)) == -1) { - umask(myymask); + umask(myumask); return (false); } - umask(myymask); + umask(myumask); if (do_compress) { if ((gzf = gzdopen(fd, "a")) == NULL) From 0d5385ad2b7873746b91526e4b19c783584359c2 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Mon, 27 Jul 2015 09:44:25 +0200 Subject: [PATCH 19/19] xbps-checkvers: fixed an endless loop with "reverts" containing extra alphanumeric chars. --- NEWS | 4 ++++ bin/xbps-checkvers/main.c | 2 +- tests/xbps/xbps-checkvers/checkvers.sh | 31 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index f32d365a..678232ea 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,9 @@ xbps-0.48 (???): + * xbps-checkvers(1): fixed an endless loop while processing templates containing + extra alphanumeric characters in the `reverts' object. Added a new testcase + to verify its correctness. + xbps-0.47 (2015-07-18): * When executing pkg configuration, override the umask with sane defaults. diff --git a/bin/xbps-checkvers/main.c b/bin/xbps-checkvers/main.c index d74a157e..896053cc 100644 --- a/bin/xbps-checkvers/main.c +++ b/bin/xbps-checkvers/main.c @@ -533,7 +533,7 @@ check_reverts(const char *repover, const map_item_t reverts) * Check if it's the first character or the previous character is a * whitespace. */ - if (p > sreverts && !isspace(p[-1])) + if (p > sreverts && !isalpha(p[-1]) && !isspace(p[-1])) continue; p += strlen(repover); /* diff --git a/tests/xbps/xbps-checkvers/checkvers.sh b/tests/xbps/xbps-checkvers/checkvers.sh index 4b834e38..b6d3be2b 100755 --- a/tests/xbps/xbps-checkvers/checkvers.sh +++ b/tests/xbps/xbps-checkvers/checkvers.sh @@ -301,6 +301,36 @@ EOF atf_check_equal "$out" "pkgname: A repover: 1.1_1 srcpkgver: 1.0_1" } +atf_test_case reverts_alpha + +reverts_alpha_head() { + atf_set "descr" "xbps-checkvers(8): test with reverts containing an alphanumeric character" +} + +reverts_alpha_body() { + mkdir -p some_repo pkg_A void-packages/srcpkgs/fs-utils + touch pkg_A/file00 + cat > void-packages/srcpkgs/fs-utils/template <