From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([69.77.167.62] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1L28Ro-0007yX-Bv for garchives@archives.gentoo.org; Mon, 17 Nov 2008 18:03:41 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2ECA4E03BA; Mon, 17 Nov 2008 18:03:41 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id D3E4FE03BA for ; Mon, 17 Nov 2008 18:03:40 +0000 (UTC) Received: from stork.gentoo.org (stork.gentoo.org [64.127.104.133]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTP id CA97C64C31 for ; Mon, 17 Nov 2008 18:03:38 +0000 (UTC) Received: from flameeyes by stork.gentoo.org with local (Exim 4.69) (envelope-from ) id 1L28Rm-0002zc-HO for gentoo-commits@lists.gentoo.org; Mon, 17 Nov 2008 18:03:38 +0000 From: "Diego Petteno (flameeyes)" To: gentoo-commits@lists.gentoo.org Reply-To: gentoo-dev@lists.gentoo.org, flameeyes@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: flameeyes X-VCS-Committer-Name: Diego Petteno Content-Type: text/plain; charset=utf8 Message-Id: Sender: Diego Petteno Date: Mon, 17 Nov 2008 18:03:38 +0000 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 1e09355f-cb3e-492b-b978-7d783d232a96 X-Archives-Hash: 920fff6ec99f5bf9a7367c7a4e572a23 flameeyes 08/11/17 18:03:38 Modified: scanelf.c Log: Rewrite symbol matching code in scanelf. =20 The previous code was entirely broken when trying to match symbols in unstripped binaries when giving multiple symbols as target. =20 The new code differs from the old one in quite a few ways: =20 - debug output when -g option is passed is disabled in the code (hacky, but still better than before!); =20 - regular expression matching is actually used when -g option is passed; =20 - by default, the symbol name is tested against the symbol name without version; no-version symbol name matching is possible by using the -g option and adding a final $; =20 - multiple symbols and single symbols are handled in the same way so that there is no more difference between them; =20 - the returned symbol name is the actual symbol name as found in the file, so includes the version when the file is not stripped. =20 While this means that there are some minimal differences between the previous code, it's arguable that this code is less buggy and more consistent than the one before. Revision Changes Path 1.197 pax-utils/scanelf.c file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/sca= nelf.c?rev=3D1.197&view=3Dmarkup plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/sca= nelf.c?rev=3D1.197&content-type=3Dtext/plain diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/sca= nelf.c?r1=3D1.196&r2=3D1.197 Index: scanelf.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v retrieving revision 1.196 retrieving revision 1.197 diff -u -r1.196 -r1.197 --- scanelf.c 22 Oct 2008 17:03:17 -0000 1.196 +++ scanelf.c 17 Nov 2008 18:03:38 -0000 1.197 @@ -1,13 +1,13 @@ /* * Copyright 2003-2007 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.196 200= 8/10/22 17:03:17 flameeyes Exp $ + * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.197 200= 8/11/17 18:03:38 flameeyes Exp $ * * Copyright 2003-2007 Ned Ludd - * Copyright 2004-2007 Mike Frysinger - */ =20 -static const char *rcsid =3D "$Id: scanelf.c,v 1.196 2008/10/22 17:03:17= flameeyes Exp $"; +static const char *rcsid =3D "$Id: scanelf.c,v 1.197 2008/11/17 18:03:38= flameeyes Exp $"; const char * const argv0 =3D "scanelf"; =20 #include "paxinc.h" @@ -977,6 +977,22 @@ return NULL; } =20 +static int scanelf_match_symname(const char *compare, const char *symnam= e, const char *symname_ver) { + /* We do things differently when checking with regexp */ + if (g_match) { + return rematch(symname, compare, REG_EXTENDED) =3D=3D 0 || + rematch(symname_ver, compare, REG_EXTENDED) =3D=3D 0; + } else { + const size_t symname_len =3D strlen(symname); + if (strncmp(symname, compare, symname_len) =3D=3D 0 && + /* Accept unversioned symbol names */ + (compare[symname_len] =3D=3D '\0' || compare[symname_len] =3D=3D = '@')) + return 1; + + return strcmp(symname_ver, symname) =3D=3D 0; + } +} + static char *scanelf_file_sym(elfobj *elf, char *found_sym) { unsigned long i; @@ -1012,7 +1028,7 @@ continue; \ } \ /* debug display ... show all symbols and some extra info */ \ - if (g_match ? rematch(ret, symname, REG_EXTENDED) =3D=3D 0 : *ret =3D= =3D '*') { \ + if (0 && g_match ? rematch(ret, symname, REG_EXTENDED) =3D=3D 0 : *r= et =3D=3D '*') { \ printf("%s(%s) %5lX %15s %s %s\n", \ ((*found_sym =3D=3D 0) ? "\n\t" : "\t"), \ elf->base_filename, \ @@ -1023,40 +1039,41 @@ } else { \ /* allow the user to specify a comma delimited list of symbols to s= earch for */ \ char *this_sym, *this_sym_ver, *next_sym; \ - this_sym =3D ret; \ + next_sym =3D ret; \ this_sym_ver =3D versioned_symname; \ - do { \ - next_sym =3D strchr(this_sym, ','); \ - if (next_sym =3D=3D NULL) \ - next_sym =3D this_sym + strlen(this_sym); \ + while (next_sym) { \ + this_sym =3D next_sym; \ + if ((next_sym =3D strchr(this_sym, ','))) \ + next_sym +=3D 1; /* Skip the comma */ \ /* do we want a defined symbol ? */ \ if (*this_sym =3D=3D '+') { \ if (sym->st_shndx =3D=3D SHN_UNDEF) \ - goto skip_this_sym##B; \ + continue; \ ++this_sym; \ ++this_sym_ver; \ /* do we want an undefined symbol ? */ \ } else if (*this_sym =3D=3D '-') { \ if (sym->st_shndx !=3D SHN_UNDEF) \ - goto skip_this_sym##B; \ + continue; \ ++this_sym; \ ++this_sym_ver; \ } \ + if (next_sym) /* Copy it so that we don't have to worry about the = final , */ \ + this_sym =3D strndup(this_sym, next_sym-this_sym); \ /* ok, lets compare the name now */ \ - if ((strncmp(this_sym, symname, (next_sym-this_sym)) =3D=3D 0 && s= ymname[next_sym-this_sym] =3D=3D '\0') || \ - (strncmp(this_sym_ver, symname, strlen(this_sym_ver)) =3D=3D 0= )) { \ + if (scanelf_match_symname(symname, this_sym, this_sym_ver)) { \ if (be_semi_verbose) { \ char buf[126]; \ snprintf(buf, sizeof(buf), "%lX %s %s", \ (unsigned long)sym->st_size, get_elfstttype(sym->st_info), this= _sym); \ ret =3D buf; \ } else \ - ret =3D this_sym; \ + ret =3D symname; \ (*found_sym)++; \ goto break_out; \ } \ - skip_this_sym##B: this_sym =3D next_sym + 1; \ - } while (*next_sym !=3D '\0'); \ + if (next_sym) free(this_sym); \ + } \ } \ } \ ++sym; \