From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <gentoo-commits+bounces-801276-garchives=archives.gentoo.org@lists.gentoo.org> Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id B7B3D138CD4 for <garchives@archives.gentoo.org>; Tue, 19 May 2015 17:37:29 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 10E7AE09E1; Tue, 19 May 2015 17:37:27 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 3073EE09CC for <gentoo-commits@lists.gentoo.org>; Tue, 19 May 2015 17:37:26 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 1C116340BDA for <gentoo-commits@lists.gentoo.org>; Tue, 19 May 2015 17:37:25 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id BD6879F3 for <gentoo-commits@lists.gentoo.org>; Tue, 19 May 2015 17:37:23 +0000 (UTC) From: "Mike Frysinger" <vapier@gentoo.org> To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" <vapier@gentoo.org> Message-ID: <1432050914.d9eb678ae9f359a1b8e22ab3eca2d70a886b497e.vapier@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: qglsa.c X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: d9eb678ae9f359a1b8e22ab3eca2d70a886b497e X-VCS-Branch: master Date: Tue, 19 May 2015 17:37:23 +0000 (UTC) Precedence: bulk List-Post: <mailto:gentoo-commits@lists.gentoo.org> List-Help: <mailto:gentoo-commits+help@lists.gentoo.org> List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org> List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org> List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org> X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 4caa0c0e-1cf4-4b49-abf0-2d12460537d5 X-Archives-Hash: 6af77ca9ce3ff0781a1439c0e5a95097 commit: d9eb678ae9f359a1b8e22ab3eca2d70a886b497e Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> AuthorDate: Tue May 19 15:55:14 2015 +0000 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> CommitDate: Tue May 19 15:55:14 2015 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=d9eb678a qglsa: update code to latest APIs qglsa.c | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/qglsa.c b/qglsa.c index 4ac3d19..328bbd8 100644 --- a/qglsa.c +++ b/qglsa.c @@ -34,19 +34,9 @@ static const char * const qglsa_opts_help[] = { static char *qglsa_load_list(void); static char *qglsa_load_list(void) { - char *ret; - struct stat st; - - if (stat(QGLSA_DB, &st)) - return NULL; - - ret = xmalloc(st.st_size+1); - - if (!eat_file(QGLSA_DB, ret, st.st_size)) { - free(ret); - return NULL; - } - + char *ret = NULL; + size_t size = 0; + eat_file(QGLSA_DB, &ret, &size); return ret; } static void qglsa_append_to_list(const char *glsa); @@ -158,8 +148,8 @@ int qglsa_main(int argc, char **argv) int i; DIR *dir; struct dirent *dentry; - struct stat st; - char buf[BUFSIZE*4]; + char *buf; + size_t buflen = 0; char *s, *p, *glsa_fixed_list; int action = GLSA_FUNKYTOWN; int all_glsas = 0; @@ -198,16 +188,19 @@ int qglsa_main(int argc, char **argv) } glsa_fixed_list = qglsa_load_list(); - xchdir(portdir); - xchdir("./metadata/glsa"); + int portdir_fd, glsa_fd; + portdir_fd = open(portdir, O_RDONLY|O_CLOEXEC|O_PATH); + glsa_fd = openat(portdir_fd, "metadata/glsa", O_RDONLY|O_CLOEXEC); switch (action) { /*case GLSA_FIX:*/ case GLSA_INJECT: + buf = NULL; for (i = optind; i < argc; ++i) { - snprintf(buf, sizeof(buf), "glsa-%s.xml", argv[i]); - if (stat(buf, &st)) { - warn("Skipping invalid GLSA '%s'", argv[i]); + free(buf); + xasprintf(&buf, "glsa-%s.xml", argv[i]); + if (faccessat(glsa_fd, buf, R_OK, 0)) { + warnp("Skipping invalid GLSA '%s'", argv[i]); continue; } if (glsa_fixed_list) { @@ -223,21 +216,27 @@ int qglsa_main(int argc, char **argv) printf("Injecting GLSA %s%s%s\n", GREEN, argv[i], NORM); qglsa_append_to_list(argv[i]); } + free(buf); break; default: - if ((dir = opendir(".")) == NULL) + if ((dir = fdopendir(glsa_fd)) == NULL) return EXIT_FAILURE; + buf = NULL; + buflen = 0; while ((dentry = readdir(dir)) != NULL) { /* validate this file as a proper glsa */ char glsa_id[20]; if (strncmp(dentry->d_name, "glsa-", 5)) continue; - strcpy(glsa_id, dentry->d_name + 5); - if ((s = strchr(glsa_id, '.')) == NULL || memcmp(s, ".xml\0", 5)) + if ((s = strchr(dentry->d_name, '.')) == NULL || memcmp(s, ".xml\0", 5)) + continue; + size_t len = s - dentry->d_name; + if (len >= sizeof(glsa_id) || len <= 5) continue; - *s = '\0'; + memcpy(glsa_id, dentry->d_name + 5, len - 5); + glsa_id[len - 5] = '\0'; /* see if we want to skip glsa's already fixed */ if (!all_glsas && glsa_fixed_list) { @@ -246,7 +245,7 @@ int qglsa_main(int argc, char **argv) } /* load the glsa into memory */ - if (eat_file(dentry->d_name, buf, sizeof(buf)) == 0) + if (!eat_file_at(glsa_fd, dentry->d_name, &buf, &buflen)) errp("could not eat %s", dentry->d_name); /* now lets figure out what to do with this memory */ @@ -300,6 +299,8 @@ int qglsa_main(int argc, char **argv) } free(glsa_fixed_list); + close(glsa_fd); + close(portdir_fd); return EXIT_SUCCESS; }