public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Diego Petteno (flameeyes)" <flameeyes@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] gentoo-projects commit in pax-utils: scanelf.c
Date: Mon, 17 Nov 2008 18:03:38 +0000	[thread overview]
Message-ID: <E1L28Rm-0002zc-HO@stork.gentoo.org> (raw)

flameeyes    08/11/17 18:03:38

  Modified:             scanelf.c
  Log:
  Rewrite symbol matching code in scanelf.
  
  The previous code was entirely broken when trying to match symbols in
  unstripped binaries when giving multiple symbols as target.
  
  The new code differs from the old one in quite a few ways:
  
  - debug output when -g option is passed is disabled in the code
    (hacky, but still better than before!);
  
  - regular expression matching is actually used when -g option is
    passed;
  
  - 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 $;
  
  - multiple symbols and single symbols are handled in the same way so
    that there is no more difference between them;
  
  - the returned symbol name is the actual symbol name as found in the
    file, so includes the version when the file is not stripped.
  
  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/scanelf.c?rev=1.197&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanelf.c?rev=1.197&content-type=text/plain
diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanelf.c?r1=1.196&r2=1.197

Index: scanelf.c
===================================================================
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 2008/10/22 17:03:17 flameeyes Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.197 2008/11/17 18:03:38 flameeyes Exp $
  *
  * Copyright 2003-2007 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2004-2007 Mike Frysinger  - <vapier@gentoo.org>
  */
 
-static const char *rcsid = "$Id: scanelf.c,v 1.196 2008/10/22 17:03:17 flameeyes Exp $";
+static const char *rcsid = "$Id: scanelf.c,v 1.197 2008/11/17 18:03:38 flameeyes Exp $";
 const char * const argv0 = "scanelf";
 
 #include "paxinc.h"
@@ -977,6 +977,22 @@
 	return NULL;
 }
 
+static int scanelf_match_symname(const char *compare, const char *symname, const char *symname_ver) {
+	/* We do things differently when checking with regexp */
+	if (g_match) {
+		return rematch(symname, compare, REG_EXTENDED) == 0 ||
+			rematch(symname_ver, compare, REG_EXTENDED) == 0;
+	} else {
+		const size_t symname_len = strlen(symname);
+		if (strncmp(symname, compare, symname_len) == 0 &&
+		     /* Accept unversioned symbol names */
+		     (compare[symname_len] == '\0' || compare[symname_len] == '@'))
+			return 1;
+
+		return strcmp(symname_ver, symname) == 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) == 0 : *ret == '*') { \
+				if (0 && g_match ? rematch(ret, symname, REG_EXTENDED) == 0 : *ret == '*') { \
 					printf("%s(%s) %5lX %15s %s %s\n", \
 					       ((*found_sym == 0) ? "\n\t" : "\t"), \
 					       elf->base_filename, \
@@ -1023,40 +1039,41 @@
 				} else { \
 					/* allow the user to specify a comma delimited list of symbols to search for */ \
 					char *this_sym, *this_sym_ver, *next_sym; \
-					this_sym = ret; \
+					next_sym = ret; \
 					this_sym_ver = versioned_symname; \
-					do { \
-						next_sym = strchr(this_sym, ','); \
-						if (next_sym == NULL) \
-							next_sym = this_sym + strlen(this_sym); \
+					while (next_sym) { \
+						this_sym = next_sym; \
+						if ((next_sym = strchr(this_sym, ','))) \
+							next_sym += 1; /* Skip the comma */ \
 						/* do we want a defined symbol ? */ \
 						if (*this_sym == '+') { \
 							if (sym->st_shndx == SHN_UNDEF) \
-								goto skip_this_sym##B; \
+								continue; \
 							++this_sym; \
 							++this_sym_ver; \
 						/* do we want an undefined symbol ? */ \
 						} else if (*this_sym == '-') { \
 							if (sym->st_shndx != 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 = strndup(this_sym, next_sym-this_sym); \
 						/* ok, lets compare the name now */ \
-						if ((strncmp(this_sym, symname, (next_sym-this_sym)) == 0 && symname[next_sym-this_sym] == '\0') || \
-						    (strncmp(this_sym_ver, symname, strlen(this_sym_ver)) == 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 = buf; \
 							} else \
-								ret = this_sym; \
+								ret = symname; \
 							(*found_sym)++; \
 							goto break_out; \
 						} \
-						skip_this_sym##B: this_sym = next_sym + 1; \
-					} while (*next_sym != '\0'); \
+						if (next_sym) free(this_sym); \
+					} \
 				} \
 			} \
 			++sym; \






             reply	other threads:[~2008-11-17 18:03 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-17 18:03 Diego Petteno (flameeyes) [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-02-28 22:59 [gentoo-commits] gentoo-projects commit in pax-utils: scanelf.c Mike Frysinger (vapier)
2015-02-24  6:58 Mike Frysinger (vapier)
2015-02-22  2:27 Mike Frysinger (vapier)
2015-02-22  1:38 Mike Frysinger (vapier)
2015-02-22  0:10 Mike Frysinger (vapier)
2015-02-21 19:30 Mike Frysinger (vapier)
2014-11-20  1:25 Mike Frysinger (vapier)
2014-11-05  2:02 Mike Frysinger (vapier)
2014-10-19  7:31 Mike Frysinger (vapier)
2014-03-21  5:33 Mike Frysinger (vapier)
2014-03-21  5:27 Mike Frysinger (vapier)
2014-03-20  8:08 Mike Frysinger (vapier)
2014-03-20  8:06 Mike Frysinger (vapier)
2014-01-11  0:28 Mike Frysinger (vapier)
2013-08-14 21:09 Mike Frysinger (vapier)
2013-04-16 16:22 Mike Frysinger (vapier)
2013-04-10 22:27 Mike Frysinger (vapier)
2013-04-08  6:38 Mike Frysinger (vapier)
2013-04-02 21:15 Mike Frysinger (vapier)
2012-11-30 23:25 Mike Frysinger (vapier)
2012-11-10  9:43 Mike Frysinger (vapier)
2012-11-04  8:25 Mike Frysinger (vapier)
2012-11-04  8:23 Mike Frysinger (vapier)
2012-11-04  7:48 Mike Frysinger (vapier)
2012-11-04  6:55 Mike Frysinger (vapier)
2012-08-04  6:08 Mike Frysinger (vapier)
2012-04-29  6:21 Mike Frysinger (vapier)
2012-04-29  5:41 Mike Frysinger (vapier)
2012-01-25  1:58 Mike Frysinger (vapier)
2012-01-23 23:48 Mike Frysinger (vapier)
2012-01-23 22:28 Mike Frysinger (vapier)
2011-12-21 22:17 Mike Frysinger (vapier)
2011-12-21 22:00 Mike Frysinger (vapier)
2011-12-21 17:34 Mike Frysinger (vapier)
2011-12-13  5:12 Mike Frysinger (vapier)
2011-10-13  4:49 Mike Frysinger (vapier)
2011-09-27 22:20 Mike Frysinger (vapier)
2011-09-27 19:56 Mike Frysinger (vapier)
2011-09-27 19:29 Mike Frysinger (vapier)
2011-09-27 19:21 Mike Frysinger (vapier)
2011-09-27 19:20 Mike Frysinger (vapier)
2011-09-27 17:28 Mike Frysinger (vapier)
2011-08-08  1:56 Mike Frysinger (vapier)
2011-07-30 17:08 Ned Ludd (solar)
2010-12-06 20:43 Mike Frysinger (vapier)
2010-01-15 11:56 Mike Frysinger (vapier)
2009-12-20 20:25 Mike Frysinger (vapier)
2009-12-01 10:18 Mike Frysinger (vapier)
2009-03-15  9:13 Mike Frysinger (vapier)
2009-03-15  9:01 Mike Frysinger (vapier)
2009-03-15  8:53 Mike Frysinger (vapier)
2008-12-30 13:38 Mike Frysinger (vapier)
2008-12-30 12:38 Mike Frysinger (vapier)
2008-12-10 20:06 Fabian Groffen (grobian)
2008-12-10 20:05 Fabian Groffen (grobian)
2008-11-17 18:09 Diego Petteno (flameeyes)
2008-10-22 17:03 Diego Petteno (flameeyes)
2008-10-22 15:20 Diego Petteno (flameeyes)
2008-09-29  6:05 Mike Frysinger (vapier)
2008-09-29  6:03 Mike Frysinger (vapier)
2008-09-29  6:01 Mike Frysinger (vapier)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1L28Rm-0002zc-HO@stork.gentoo.org \
    --to=flameeyes@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox