From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 9D4C9138334 for ; Fri, 1 Mar 2019 13:51:17 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4A7CAE0858; Fri, 1 Mar 2019 13:51:16 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 08C27E0858 for ; Fri, 1 Mar 2019 13:51:15 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 15223335C9C for ; Fri, 1 Mar 2019 13:51:14 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 79E20520 for ; Fri, 1 Mar 2019 13:51:12 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1551448183.55ad84ae976fdfc53d09faaca17549172ed62681.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: porting.h q.c qfile.c qgrep.c qlist.c qmerge.c qpkg.c quse.c X-VCS-Directories: / X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 55ad84ae976fdfc53d09faaca17549172ed62681 X-VCS-Branch: master Date: Fri, 1 Mar 2019 13:51:12 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 270939f9-915f-4b54-a1c8-6273fbf67a01 X-Archives-Hash: e4041b17d34a2c9e87ffb13d8a5dca4a commit: 55ad84ae976fdfc53d09faaca17549172ed62681 Author: Fabian Groffen gentoo org> AuthorDate: Fri Mar 1 13:49:43 2019 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Fri Mar 1 13:49:43 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=55ad84ae fix GCC-8.2 warnings Signed-off-by: Fabian Groffen gentoo.org> porting.h | 4 ++ q.c | 9 ++-- qfile.c | 76 +++++++++++++------------- qgrep.c | 7 +-- qlist.c | 10 ++-- qmerge.c | 181 ++++++++++++++++++++++++++++++++++++++++---------------------- qpkg.c | 29 ++++++---- quse.c | 7 +-- 8 files changed, 196 insertions(+), 127 deletions(-) diff --git a/porting.h b/porting.h index daf1d2e..9239897 100644 --- a/porting.h +++ b/porting.h @@ -51,6 +51,10 @@ #include +#if defined(__MACH__) +#include +#endif + #if defined(__sun) && defined(__SVR4) /* workaround non-const defined name in option struct, such that we * don't get a zillion of warnings */ diff --git a/q.c b/q.c index 3d45160..64aa284 100644 --- a/q.c +++ b/q.c @@ -1,15 +1,12 @@ /* - * Copyright 2005-2018 Gentoo Foundation + * Copyright 2005-2019 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2010 Ned Ludd - * Copyright 2005-2014 Mike Frysinger - + * Copyright 2017- Fabian Groffen - */ -#if defined(__MACH__) -#include -#endif - #define Q_FLAGS "irmM:" COMMON_FLAGS static struct option const q_long_opts[] = { {"install", no_argument, NULL, 'i'}, @@ -129,7 +126,7 @@ int q_main(int argc, char **argv) if ((size_t)rret > sizeof(buf) - 1) { rret = -1; } else { - strncpy(buf, prog, rret); + snprintf(buf, sizeof(buf), "%s", prog); } #else rret = readlink("/proc/self/exe", buf, sizeof(buf) - 1); diff --git a/qfile.c b/qfile.c index 6e1cb0a..55fbb42 100644 --- a/qfile.c +++ b/qfile.c @@ -270,13 +270,15 @@ prepare_qfile_args(const int argc, const char **argv, struct qfile_opt_state *st int i; int nb_of_queries = argc; char *pwd = state->pwd; + const char *p; size_t real_root_len = state->real_root_len; + size_t len; char *real_root = state->real_root; char **basenames = NULL; char **dirnames = NULL; char **realdirnames = NULL; - char tmppath[_Q_PATH_MAX+1]; - char abspath[_Q_PATH_MAX+1]; + char tmppath[_Q_PATH_MAX]; + char abspath[_Q_PATH_MAX]; /* For each argument, we store its basename, its absolute dirname, * and the realpath of its dirname. Dirnames and their realpaths @@ -289,17 +291,17 @@ prepare_qfile_args(const int argc, const char **argv, struct qfile_opt_state *st for (i = 0; i < argc; ++i) { /* Record basename, but if it is ".", ".." or "/" */ - /* strncopy so that "argv" can be "const" */ - strncpy(abspath, argv[i], _Q_PATH_MAX); - strncpy(tmppath, basename(abspath), _Q_PATH_MAX); - if ((strlen(tmppath) > 2) || - (strncmp(tmppath, "..", strlen(tmppath)) - && strncmp(tmppath, "/", strlen(tmppath)))) + /* copy so that "argv" can be "const" */ + snprintf(tmppath, sizeof(tmppath), "%s", argv[i]); + p = basename(tmppath); + len = strlen(p); + if ((len > 2) || + (strncmp(tmppath, "..", len) != 0 && + strncmp(tmppath, "/", len) != 0)) { - basenames[i] = xstrdup(tmppath); + basenames[i] = xstrdup(p); /* If there is no "/" in the argument, then it's over. - * (we are searching a simple file name) - */ + * (we are searching a simple file name) */ if (strchr(argv[i], '/') == NULL) continue; } @@ -307,15 +309,13 @@ prepare_qfile_args(const int argc, const char **argv, struct qfile_opt_state *st /* Make sure we have an absolute path available (with * "realpath(ROOT)" prefix) */ if (argv[i][0] == '/') { - if (state->assume_root_prefix) - strncpy(abspath, argv[i], _Q_PATH_MAX); - else - snprintf(abspath, _Q_PATH_MAX, "%s%s", real_root, argv[i]); + snprintf(abspath, sizeof(abspath), "%s%s", + state->assume_root_prefix ? real_root : "", argv[i]); } else if (pwd) { if (state->assume_root_prefix) - snprintf(abspath, _Q_PATH_MAX, "%s/%s", pwd, argv[i]); + snprintf(abspath, sizeof(abspath), "%s/%s", pwd, argv[i]); else - snprintf(abspath, _Q_PATH_MAX, "%s%s/%s", + snprintf(abspath, sizeof(abspath), "%s%s/%s", real_root, pwd, argv[i]); } else { warn("$PWD was not found in environment, " @@ -323,38 +323,36 @@ prepare_qfile_args(const int argc, const char **argv, struct qfile_opt_state *st goto skip_query_item; } - if (basenames[i]) { - /* Get both the dirname and its realpath. This paths will - * have no trailing slash, but if it is the only char (ie., - * when searching for "/foobar"). - */ - strncpy(tmppath, abspath, _Q_PATH_MAX); - strncpy(abspath, dirname(tmppath), _Q_PATH_MAX); - if (abspath[real_root_len] == '\0') - strncat(abspath, "/", 1); - dirnames[i] = xstrdup(abspath + real_root_len); - if (realpath(abspath, tmppath) == NULL) { + if (basenames[i] != NULL) { + /* Get both the dirname and its realpath. These paths will + * have no trailing slash, except if it is the only char (ie., + * when searching for "/foobar"). */ + snprintf(tmppath, sizeof(tmppath), "%s%s", + dirname(abspath), + abspath[real_root_len] == '\0' ? "/" : ""); + dirnames[i] = xstrdup(tmppath + real_root_len); + if (realpath(tmppath, abspath) == NULL) { if (verbose) { - warnp("Could not read real path of \"%s\"", abspath); + warnp("Could not read real path of \"%s\"", tmppath); warn("Results for query item \"%s\" may be inaccurate.", argv[i]); } continue; } - if (!qfile_is_prefix(tmppath, real_root, real_root_len)) { + if (!qfile_is_prefix(abspath, real_root, real_root_len)) { warn("Real path of \"%s\" is not under ROOT: %s", - abspath, tmppath); + tmppath, abspath); goto skip_query_item; } - if (tmppath[real_root_len] == '\0') - strncat(tmppath, "/", 1); + snprintf(tmppath, sizeof(tmppath), "%s%s", + dirname(abspath), + abspath[real_root_len] == '\0' ? "/" : ""); if (strcmp(dirnames[i], tmppath + real_root_len)) realdirnames[i] = xstrdup(tmppath + real_root_len); } else { /* No basename means we are looking for something like "/foo/bar/.." * Dirname is meaningless here, we can only get realpath of the full - * path and then split it. - */ + * path and then split it. */ if (realpath(abspath, tmppath) == NULL) { warnp("Could not read real path of \"%s\"", abspath); goto skip_query_item; @@ -364,11 +362,11 @@ prepare_qfile_args(const int argc, const char **argv, struct qfile_opt_state *st abspath, tmppath); goto skip_query_item; } - strncpy(abspath, tmppath, _Q_PATH_MAX); + snprintf(abspath, sizeof(abspath), "%s", tmppath); basenames[i] = xstrdup(basename(abspath)); - strncpy(abspath, dirname(tmppath), _Q_PATH_MAX); - if (tmppath[real_root_len] == '\0') - strncat(tmppath, "/", 1); + snprintf(abspath, sizeof(abspath), "%s%s", + dirname(tmppath), + tmppath[real_root_len] == '\0' ? "/" : ""); realdirnames[i] = xstrdup(abspath + real_root_len); } continue; diff --git a/qgrep.c b/qgrep.c index 85dab58..f018821 100644 --- a/qgrep.c +++ b/qgrep.c @@ -1,10 +1,11 @@ /* - * Copyright 2005-2018 Gentoo Foundation + * Copyright 2005-2019 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * + * Copyright 2005 Petteri Räty - * Copyright 2005-2010 Ned Ludd - * Copyright 2005-2014 Mike Frysinger - - * Copyright 2005 Petteri Räty - + * Copyright 2018- Fabian Groffen - */ #ifdef APPLET_qgrep @@ -245,7 +246,7 @@ int qgrep_main(int argc, char **argv) DIR *cat_dir = NULL; struct dirent *dentry = NULL; char ebuild[_Q_PATH_MAX]; - char name[_Q_PATH_MAX]; + char name[_Q_PATH_MAX * 2]; char *label; int reflags = 0; char invert_match = 0; diff --git a/qlist.c b/qlist.c index a332acc..4a3b95a 100644 --- a/qlist.c +++ b/qlist.c @@ -1,10 +1,11 @@ /* - * Copyright 2005-2018 Gentoo Foundation + * Copyright 2005-2019 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * + * Copyright 2005 Martin Schlemmer - * Copyright 2005-2010 Ned Ludd - * Copyright 2005-2014 Mike Frysinger - - * Copyright 2005 Martin Schlemmer - + * Copyright 2018- Fabian Groffen - */ #ifdef APPLET_qlist @@ -115,7 +116,10 @@ umapstr(char display, q_vdb_pkg_ctx *pkg_ctx) rmspace(umap); if (!strlen(umap)) return buf; - snprintf(buf, sizeof(buf), " %s%s%s%s%s", quiet ? "": "(", RED, umap, NORM, quiet ? "": ")"); + snprintf(buf, sizeof(buf), " %s%s%.*s%s%s", + quiet ? "": "(", RED, + (int)(sizeof(buf) - (quiet ? 3 : 1) - sizeof(RED) - sizeof(NORM)), + umap, NORM, quiet ? "": ")"); return buf; } diff --git a/qmerge.c b/qmerge.c index 535966e..195d92b 100644 --- a/qmerge.c +++ b/qmerge.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2018 Gentoo Authors + * Copyright 2005-2019 Gentoo Authors * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2010 Ned Ludd - @@ -538,16 +538,6 @@ install_mask_pwd(int iargc, char **iargv, const struct stat * const st, int fd) install_mask_check_dir(masksv, masksc, st, fd, 1, INCLUDE, qpth); } -static char * -atom2str(const depend_atom *atom, char *buf, size_t size) -{ - if (atom->PR_int) - snprintf(buf, size, "%s-%s-r%i", atom->PN, atom->PV, atom->PR_int); - else - snprintf(buf, size, "%s-%s", atom->PN, atom->PV); - return buf; -} - static char qprint_tree_node(int level, const depend_atom *atom, const struct pkg_t *pkg) { @@ -570,17 +560,18 @@ qprint_tree_node(int level, const depend_atom *atom, const struct pkg_t *pkg) } else { depend_atom *subatom = atom_explode(p); if (subatom != NULL) { - atom2str(subatom, buf, sizeof(buf)); - atom2str(atom, install_ver, sizeof(install_ver)); - ret = atom_compare_str(install_ver, buf); + ret = atom_compare(atom, subatom); switch (ret) { case EQUAL: c = 'R'; break; case NEWER: c = 'U'; break; case OLDER: c = 'D'; break; default: c = '?'; break; } - strncpy(buf, subatom->P, sizeof(buf)); - snprintf(install_ver, sizeof(install_ver), "[%s%s%s] ", DKBLUE, buf, NORM); + snprintf(install_ver, sizeof(install_ver), "[%s%.*s%s] ", + DKBLUE, + (int)(sizeof(install_ver) - 4 - + sizeof(DKBLUE) - sizeof(NORM)), + subatom->P, NORM); atom_implode(subatom); } if (update_only && c != 'U') @@ -1814,23 +1805,38 @@ grab_binpkg_info(const char *name) snprintf(buf, sizeof(buf), "%s/%s", pkg->CATEGORY, pkg->PF); if (strstr(buf, name) != NULL) { if (!best_match[0]) - strncpy(best_match, buf, sizeof(best_match)); + snprintf(best_match, sizeof(best_match), "%.*s", + (int)sizeof(best_match) - 1, buf); atom = atom_explode(buf); - snprintf(buf, sizeof(buf), "%s/%s-%s", atom->CATEGORY, atom->PN, atom->PV); - if (atom->PR_int) - snprintf(buf, sizeof(buf), "%s/%s-%s-r%i", atom->CATEGORY, atom->PN, atom->PV, atom->PR_int); + if (atom->PR_int) { + snprintf(buf, sizeof(buf), "%s/%s-%s-r%i", + atom->CATEGORY, atom->PN, + atom->PV, atom->PR_int); + } else { + snprintf(buf, sizeof(buf), "%s/%s-%s", + atom->CATEGORY, atom->PN, atom->PV); + } ret = atom_compare_str(name, buf); - IF_DEBUG(fprintf(stderr, "=== atom_compare(%s, %s) = %d %s\n", name, buf, ret, booga[ret])); /* buf(%s) depend(%s)\n", ret, pkg->CATEGORY, pkg->PF, name, pkg->RDEPEND); */ + IF_DEBUG(fprintf(stderr, + "=== atom_compare(%s, %s) = %d %s\n", + name, buf, ret, booga[ret])); + /* buf(%s) depend(%s)\n", ret, pkg->CATEGORY, + * pkg->PF, name, pkg->RDEPEND); */ switch (ret) { case EQUAL: case NEWER: - snprintf(buf, sizeof(buf), "%s/%s", pkg->CATEGORY, pkg->PF); + snprintf(buf, sizeof(buf), "%s/%s", + pkg->CATEGORY, pkg->PF); ret = atom_compare_str(buf, best_match); if (ret == NEWER || ret == EQUAL) { - strncpy(best_match, buf, sizeof(best_match)); + snprintf(best_match, sizeof(best_match), "%.*s", + (int)sizeof(best_match) - 1, buf); memcpy(rpkg, pkg, sizeof(struct pkg_t)); - IF_DEBUG(fprintf(stderr, "--- %s/%s depend(%s)\n", rpkg->CATEGORY, rpkg->PF, rpkg->RDEPEND)); + IF_DEBUG(fprintf(stderr, + "--- %s/%s depend(%s)\n", + rpkg->CATEGORY, rpkg->PF, + rpkg->RDEPEND)); } case OLDER: break; default: @@ -1856,34 +1862,46 @@ grab_binpkg_info(const char *name) if (*buf) { /* we dont need all the info */ if (strcmp(buf, "RDEPEND") == 0) - strncpy(pkg->RDEPEND, p, sizeof(Pkg.RDEPEND)); + snprintf(pkg->RDEPEND, sizeof(Pkg.RDEPEND), "%.*s", + (int)sizeof(Pkg.RDEPEND) - 1, p); if (strcmp(buf, "PF") == 0) - strncpy(pkg->PF, p, sizeof(Pkg.PF)); + snprintf(pkg->PF, sizeof(Pkg.PF), "%.*s", + (int)sizeof(Pkg.PF) - 1, p); if (strcmp(buf, "CATEGORY") == 0) - strncpy(pkg->CATEGORY, p, sizeof(Pkg.CATEGORY)); + snprintf(pkg->CATEGORY, sizeof(Pkg.CATEGORY), "%.*s", + (int)sizeof(Pkg.CATEGORY) - 1, p); if (strcmp(buf, "REPO") == 0) - strncpy(pkg->REPO, p, sizeof(Pkg.REPO)); + snprintf(pkg->REPO, sizeof(Pkg.REPO), "%.*s", + (int)sizeof(Pkg.REPO) - 1, p); if (strcmp(buf, "CPV") == 0) { if ((atom = atom_explode(p)) != NULL) { - snprintf(buf, sizeof(buf), "%s-%s", atom->PN, atom->PV); - if (atom->PR_int) - snprintf(buf, sizeof(buf), "%s-%s-r%i", atom->PN, atom->PV, atom->PR_int); - strncpy(pkg->PF, buf, sizeof(Pkg.PF)); - strncpy(pkg->CATEGORY, atom->CATEGORY, sizeof(Pkg.CATEGORY)); + if (atom->PR_int) { + snprintf(buf, sizeof(buf), "%s-%s-r%i", + atom->PN, atom->PV, atom->PR_int); + } else { + snprintf(buf, sizeof(buf), "%s-%s", atom->PN, atom->PV); + } + snprintf(pkg->PF, sizeof(Pkg.PF), "%.*s", + (int)sizeof(Pkg.PF) - 1, buf); + snprintf(pkg->CATEGORY, sizeof(Pkg.CATEGORY), "%.*s", + (int)sizeof(Pkg.CATEGORY) - 1, atom->CATEGORY); atom_implode(atom); } } if (strcmp(buf, "SLOT") == 0) - strncpy(pkg->SLOT, p, sizeof(Pkg.SLOT)); + snprintf(pkg->SLOT, sizeof(Pkg.SLOT), "%.*s", + (int)sizeof(Pkg.SLOT) - 1, p); if (strcmp(buf, "USE") == 0) - strncpy(pkg->USE, p, sizeof(Pkg.USE)); - + snprintf(pkg->USE, sizeof(Pkg.USE), "%.*s", + (int)sizeof(Pkg.USE) - 1, p); /* checksums. We must have 1 or the other unless --*/ if (strcmp(buf, "MD5") == 0) - strncpy(pkg->MD5, p, sizeof(Pkg.MD5)); + snprintf(pkg->MD5, sizeof(Pkg.MD5), "%.*s", + (int)sizeof(Pkg.MD5) - 1, p); if (strcmp(buf, "SHA1") == 0) - strncpy(pkg->SHA1, p, sizeof(Pkg.SHA1)); + snprintf(pkg->SHA1, sizeof(Pkg.SHA1), "%.*s", + (int)sizeof(Pkg.SHA1) - 1, p); } } fclose(fp); @@ -1918,10 +1936,12 @@ find_binpkg(const char *name) depend_atom *atom; if (!best_match[0]) - strncpy(best_match, buf, sizeof(best_match)); + snprintf(best_match, sizeof(best_match), "%.*s", + (int)sizeof(best_match) - 1, buf); atom = atom_explode(buf); - snprintf(buf, sizeof(buf), "%s/%s", atom->CATEGORY, atom->PN); + snprintf(buf, sizeof(buf), "%s/%s", + atom->CATEGORY, atom->PN); ret = atom_compare_str(name, buf); switch (ret) { case OLDER: break; @@ -1930,8 +1950,10 @@ find_binpkg(const char *name) snprintf(buf, sizeof(buf), "%s/%s", CATEGORY, PF); ret = atom_compare_str(buf, best_match); if (ret == NEWER || ret == EQUAL) - strncpy(best_match, buf, sizeof(best_match)); - /* printf("[%s == %s] = %d; %s/%s\n", name, buf, ret, CATEGORY, PF); */ + snprintf(best_match, sizeof(best_match), "%.*s", + (int)sizeof(best_match) - 1, buf); + /* printf("[%s == %s] = %d; %s/%s\n", + * name, buf, ret, CATEGORY, PF); */ default: break; } @@ -1954,18 +1976,23 @@ find_binpkg(const char *name) if (strcmp(buf, "CPV") == 0) { depend_atom *atom; if ((atom = atom_explode(p)) != NULL) { - snprintf(buf, sizeof(buf), "%s-%s", atom->PN, atom->PV); - if (atom->PR_int) - snprintf(buf, sizeof(buf), "%s-%s-r%i", atom->PN, atom->PV, atom->PR_int); - strncpy(PF, buf, sizeof(PF)); - strncpy(CATEGORY, atom->CATEGORY, sizeof(CATEGORY)); + if (atom->PR_int) { + snprintf(buf, sizeof(buf), "%s-%s-r%i", + atom->PN, atom->PV, atom->PR_int); + } else { + snprintf(buf, sizeof(buf), "%s-%s", atom->PN, atom->PV); + } + snprintf(PF, sizeof(PF), "%.*s", (int)sizeof(PF) - 1, buf); + snprintf(CATEGORY, sizeof(CATEGORY), "%.*s", + (int)sizeof(CATEGORY) - 1, atom->CATEGORY); atom_implode(atom); } } if (strcmp(buf, "PF") == 0) - strncpy(PF, p, sizeof(PF)); + snprintf(PF, sizeof(PF), "%.*s", (int)sizeof(PF) - 1, p); if (strcmp(buf, "CATEGORY") == 0) - strncpy(CATEGORY, p, sizeof(CATEGORY)); + snprintf(CATEGORY, sizeof(CATEGORY), "%.*s", + (int)sizeof(CATEGORY) - 1, p); } } fclose(fp); @@ -2004,7 +2031,7 @@ parse_packages(queue *todo) switch (*buf) { case 'R': if (!strcmp(buf, "REPO")) - strncpy(repo, p, sizeof(repo)); + snprintf(repo, sizeof(repo), "%.*s", (int)sizeof(repo) - 1, p); break; } } @@ -2057,40 +2084,66 @@ parse_packages(queue *todo) switch (*buf) { case 'U': - if (strcmp(buf, "USE") == 0) strncpy(Pkg.USE, p, sizeof(Pkg.USE)); + if (strcmp(buf, "USE") == 0) + snprintf(Pkg.USE, sizeof(Pkg.USE), "%.*s", + (int)sizeof(Pkg.USE) - 1, p); break; case 'P': - if (strcmp(buf, "PF") == 0) strncpy(Pkg.PF, p, sizeof(Pkg.PF)); + if (strcmp(buf, "PF") == 0) + snprintf(Pkg.PF, sizeof(Pkg.PF), "%.*s", + (int)sizeof(Pkg.PF) - 1, p); break; case 'S': - if (strcmp(buf, "SIZE") == 0) Pkg.SIZE = atol(p); - if (strcmp(buf, "SLOT") == 0) strncpy(Pkg.SLOT, p, sizeof(Pkg.SLOT)); - if (strcmp(buf, "SHA1") == 0) strncpy(Pkg.SHA1, p, sizeof(Pkg.SHA1)); + if (strcmp(buf, "SIZE") == 0) + Pkg.SIZE = atol(p); + if (strcmp(buf, "SLOT") == 0) + snprintf(Pkg.SLOT, sizeof(Pkg.SLOT), "%.*s", + (int)sizeof(Pkg.SLOT) - 1, p); + if (strcmp(buf, "SHA1") == 0) + snprintf(Pkg.SHA1, sizeof(Pkg.SHA1), "%.*s", + (int)sizeof(Pkg.SHA1) - 1, p); break; case 'M': - if (strcmp(buf, "MD5") == 0) strncpy(Pkg.MD5, p, sizeof(Pkg.MD5)); + if (strcmp(buf, "MD5") == 0) + snprintf(Pkg.MD5, sizeof(Pkg.MD5), "%.*s", + (int)sizeof(Pkg.MD5) - 1, p); break; case 'R': - if (strcmp(buf, "REPO") == 0) strncpy(Pkg.REPO, p, sizeof(Pkg.REPO)); - if (strcmp(buf, "RDEPEND") == 0) strncpy(Pkg.RDEPEND, p, sizeof(Pkg.RDEPEND)); + if (strcmp(buf, "REPO") == 0) + snprintf(Pkg.REPO, sizeof(Pkg.REPO), "%.*s", + (int)sizeof(Pkg.REPO) - 1, p); + if (strcmp(buf, "RDEPEND") == 0) + snprintf(Pkg.RDEPEND, sizeof(Pkg.RDEPEND), "%.*s", + (int)sizeof(Pkg.RDEPEND) - 1, p); break; case 'L': - if (strcmp(buf, "LICENSE") == 0) strncpy(Pkg.LICENSE, p, sizeof(Pkg.LICENSE)); + if (strcmp(buf, "LICENSE") == 0) + snprintf(Pkg.LICENSE, sizeof(Pkg.LICENSE), "%.*s", + (int)sizeof(Pkg.LICENSE) - 1, p); break; case 'C': - if (strcmp(buf, "CATEGORY") == 0) strncpy(Pkg.CATEGORY, p, sizeof(Pkg.CATEGORY)); + if (strcmp(buf, "CATEGORY") == 0) + snprintf(Pkg.CATEGORY, sizeof(Pkg.CATEGORY), "%.*s", + (int)sizeof(Pkg.CATEGORY) - 1, p); if (strcmp(buf, "CPV") == 0) { if ((pkg_atom = atom_explode(p)) != NULL) { if (pkg_atom->PR_int) - snprintf(Pkg.PF, sizeof(Pkg.PF), "%s-%s-r%i", pkg_atom->PN, pkg_atom->PV, pkg_atom->PR_int); + snprintf(Pkg.PF, sizeof(Pkg.PF), "%s-%s-r%i", + pkg_atom->PN, pkg_atom->PV, + pkg_atom->PR_int); else - snprintf(Pkg.PF, sizeof(Pkg.PF), "%s-%s", pkg_atom->PN, pkg_atom->PV); - strncpy(Pkg.CATEGORY, pkg_atom->CATEGORY, sizeof(Pkg.CATEGORY)); + snprintf(Pkg.PF, sizeof(Pkg.PF), "%s-%s", + pkg_atom->PN, pkg_atom->PV); + snprintf(Pkg.CATEGORY, sizeof(Pkg.CATEGORY), + "%.*s", (int)sizeof(Pkg.CATEGORY) - 1, + pkg_atom->CATEGORY); } } break; case 'D': - if (strcmp(buf, "DESC") == 0) strncpy(Pkg.DESC, p, sizeof(Pkg.DESC)); + if (strcmp(buf, "DESC") == 0) + snprintf(Pkg.DESC, sizeof(Pkg.DESC), "%.*s", + (int)sizeof(Pkg.DESC) - 1, p); break; default: break; diff --git a/qpkg.c b/qpkg.c index bab3cd1..dcdc190 100644 --- a/qpkg.c +++ b/qpkg.c @@ -1,9 +1,10 @@ /* - * Copyright 2005-2018 Gentoo Foundation + * Copyright 2005-2019 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * - * Copyright 2005-2010 Ned Ludd - + * Copyright 2005-2010 Ned Ludd - * Copyright 2005-2014 Mike Frysinger - + * Copyright 2018- Fabian Groffen - */ #ifdef APPLET_qpkg @@ -215,7 +216,10 @@ static int qpkg_make(depend_atom *atom) { FILE *fp, *out; - char tmpdir[BUFSIZE], filelist[BUFSIZE], xpak[BUFSIZE], tbz2[BUFSIZE]; + char tmpdir[BUFSIZE]; + char filelist[BUFSIZE + 32]; + char xpak[BUFSIZE + 32]; + char tbz2[BUFSIZE + 32]; size_t buflen; char *buf; int i; @@ -230,7 +234,8 @@ qpkg_make(depend_atom *atom) buflen = _Q_PATH_MAX; buf = xmalloc(buflen); - snprintf(buf, buflen, "%s/%s/%s/CONTENTS", portvdb, atom->CATEGORY, atom_to_pvr(atom)); + snprintf(buf, buflen, "%s/%s/%s/CONTENTS", + portvdb, atom->CATEGORY, atom_to_pvr(atom)); if ((fp = fopen(buf, "r")) == NULL) return -1; @@ -258,7 +263,8 @@ qpkg_make(depend_atom *atom) char *hash = (char *)hash_file(e->name, HASH_MD5); if (hash != NULL) { if (strcmp(e->digest, hash) != 0) - warn("MD5: mismatch expected %s got %s for %s", e->digest, hash, e->name); + warn("MD5: mismatch expected %s got %s for %s", + e->digest, hash, e->name); free(hash); } } @@ -271,13 +277,16 @@ qpkg_make(depend_atom *atom) fflush(stdout); snprintf(tbz2, sizeof(tbz2), "%s/bin.tar.bz2", tmpdir); - snprintf(buf, buflen, "tar jcf '%s' --files-from='%s' --no-recursion >/dev/null 2>&1", tbz2, filelist); + if (snprintf(buf, buflen, "tar jcf '%s' --files-from='%s' " + "--no-recursion >/dev/null 2>&1", tbz2, filelist) > (int)buflen) + return 2; if ((fp = popen(buf, "r")) == NULL) return 2; pclose(fp); snprintf(xpak, sizeof(xpak), "%s/inf.xpak", tmpdir); - snprintf(buf, buflen, "%s/%s/%s", portvdb, atom->CATEGORY, atom_to_pvr(atom)); + snprintf(buf, buflen, "%s/%s/%s", + portvdb, atom->CATEGORY, atom_to_pvr(atom)); xpak_argv[0] = buf; xpak_argv[1] = NULL; xpak_create(AT_FDCWD, xpak, 1, xpak_argv); @@ -289,7 +298,8 @@ qpkg_make(depend_atom *atom) unlink(xpak); unlink(tbz2); - snprintf(tbz2, sizeof(tbz2), "%s/%s.tbz2", qpkg_get_bindir(), atom_to_pvr(atom)); + snprintf(tbz2, sizeof(tbz2), "%s/%s.tbz2", + qpkg_get_bindir(), atom_to_pvr(atom)); if (rename(buf, tbz2)) { warnp("could not move '%s' to '%s'", buf, tbz2); return 1; @@ -298,7 +308,8 @@ qpkg_make(depend_atom *atom) rmdir(tmpdir); stat(tbz2, &st); - printf("%s%s%s kB\n", RED, make_human_readable_str(st.st_size, 1, KILOBYTE), NORM); + printf("%s%s%s kB\n", + RED, make_human_readable_str(st.st_size, 1, KILOBYTE), NORM); return 0; } diff --git a/quse.c b/quse.c index 05ba2f4..1fd4f3a 100644 --- a/quse.c +++ b/quse.c @@ -1,9 +1,10 @@ /* - * Copyright 2005-2018 Gentoo Foundation + * Copyright 2005-2019 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2010 Ned Ludd - * Copyright 2005-2014 Mike Frysinger - + * Copyright 2018- Fabian Groffen - */ #ifdef APPLET_quse @@ -50,12 +51,12 @@ print_highlighted_use_flags(char *string, int ind, int argc, char **argv) if (quse_name_only) return; - strncpy(buf, string, sizeof(buf)); + snprintf(buf, sizeof(buf), "%.*s", (int)sizeof(buf) - 1, string); str = buf; remove_extra_space(str); rmspace(str); - if (*WHITE != '\e') { + if (*WHITE == '\0') { printf("%s", str); return; }