From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 816E61391DB for ; Thu, 20 Mar 2014 08:06:06 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4DC81E09FA; Thu, 20 Mar 2014 08:06:05 +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 B8873E09FA for ; Thu, 20 Mar 2014 08:06:04 +0000 (UTC) Received: from flycatcher.gentoo.org (flycatcher.gentoo.org [81.93.255.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 840BD33FCA8 for ; Thu, 20 Mar 2014 08:06:03 +0000 (UTC) Received: by flycatcher.gentoo.org (Postfix, from userid 559) id A80E92004C; Thu, 20 Mar 2014 08:06:01 +0000 (UTC) From: "Mike Frysinger (vapier)" To: gentoo-commits@lists.gentoo.org Reply-To: gentoo-dev@lists.gentoo.org, vapier@gentoo.org Subject: [gentoo-commits] gentoo-projects commit in pax-utils: scanelf.c X-VCS-Repository: gentoo-projects X-VCS-Files: scanelf.c X-VCS-Directories: pax-utils X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Message-Id: <20140320080601.A80E92004C@flycatcher.gentoo.org> Date: Thu, 20 Mar 2014 08:06:01 +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-Archives-Salt: 051bb752-b6e0-4413-86c3-ece5cd3c7240 X-Archives-Hash: 1678cea8c26761d0b5b5e9b1dd050d1a vapier 14/03/20 08:06:01 Modified: scanelf.c Log: scanelf: convert -E option to use array_t this avoids silently (and wrongly) truncating the options given to -E. it also makes the code a lot easier to handle. #504340 by David Binderman Revision Changes Path 1.262 pax-utils/scanelf.c file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?rev=1.262&view=markup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?rev=1.262&content-type=text/plain diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?r1=1.261&r2=1.262 Index: scanelf.c =================================================================== RCS file: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v retrieving revision 1.261 retrieving revision 1.262 diff -u -r1.261 -r1.262 --- scanelf.c 20 Mar 2014 07:59:27 -0000 1.261 +++ scanelf.c 20 Mar 2014 08:06:01 -0000 1.262 @@ -1,13 +1,13 @@ /* * Copyright 2003-2012 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.261 2014/03/20 07:59:27 vapier Exp $ + * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.262 2014/03/20 08:06:01 vapier Exp $ * * Copyright 2003-2012 Ned Ludd - * Copyright 2004-2012 Mike Frysinger - */ -static const char rcsid[] = "$Id: scanelf.c,v 1.261 2014/03/20 07:59:27 vapier Exp $"; +static const char rcsid[] = "$Id: scanelf.c,v 1.262 2014/03/20 08:06:01 vapier Exp $"; const char argv0[] = "scanelf"; #include "paxinc.h" @@ -18,7 +18,7 @@ static int file_matches_list(const char *filename, char **matchlist); /* variables to control behavior */ -static char *match_etypes = NULL; +static array_t _match_etypes = array_init_decl, *match_etypes = &_match_etypes; static array_t _ldpaths = array_init_decl, *ldpaths = &_ldpaths; static char scan_ldpath = 0; static char scan_envpath = 0; @@ -1550,6 +1550,8 @@ static int scanelf_elf(const char *filename, int fd, size_t len) { int ret = 1; + size_t n; + const char *match_etype; elfobj *elf; /* verify this is real ELF */ @@ -1568,20 +1570,12 @@ break; default: break; } - if (match_etypes) { - char sbuf[126]; - strncpy(sbuf, match_etypes, sizeof(sbuf)); - if (strchr(match_etypes, ',') != NULL) { - char *p; - while ((p = strrchr(sbuf, ',')) != NULL) { - *p = 0; - if (etype_lookup(p+1) == get_etype(elf)) - goto label_ret; - } - } - if (etype_lookup(sbuf) != get_etype(elf)) - goto label_done; - } + + array_for_each(match_etypes, n, match_etype) + if (etype_lookup(match_etype) == get_etype(elf)) + goto label_ret; + if (array_cnt(match_etypes)) + goto label_done; label_ret: ret = scanelf_elfobj(elf); @@ -2080,6 +2074,16 @@ flags &= ~PF_NO##flag; \ flags |= PF_##flag; \ } +static void parse_delimited(array_t *arr, char *arg, const char *delim) +{ + char *ele = strtok(arg, delim); + if (!ele) /* edge case: -s '' */ + xarraypush_str(arr, ""); + while (ele) { + xarraypush_str(arr, ele); + ele = strtok(NULL, delim); + } +} static int parseargs(int argc, char *argv[]) { int i; @@ -2103,7 +2107,8 @@ from_file = optarg; break; case 'E': - match_etypes = optarg; + /* historically, this was comma delimited */ + parse_delimited(match_etypes, optarg, ","); break; case 'M': match_bits = atoi(optarg); @@ -2126,17 +2131,10 @@ case 'k': xarraypush_str(find_section_arr, optarg); break; - case 's': { + case 's': /* historically, this was comma delimited */ - char *this_sym = strtok(optarg, ","); - if (!this_sym) /* edge case: -s '' */ - xarraypush_str(find_sym_arr, ""); - while (this_sym) { - xarraypush_str(find_sym_arr, this_sym); - this_sym = strtok(NULL, ","); - } + parse_delimited(find_sym_arr, optarg, ","); break; - } case 'N': xarraypush_str(find_lib_arr, optarg); break;