public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] gentoo-projects commit in pax-utils: scanelf.c xfuncs.c xfuncs.h
@ 2009-01-31 17:58 Fabian Groffen (grobian)
  0 siblings, 0 replies; 2+ messages in thread
From: Fabian Groffen (grobian) @ 2009-01-31 17:58 UTC (permalink / raw
  To: gentoo-commits

grobian     09/01/31 17:58:37

  Modified:             scanelf.c xfuncs.c xfuncs.h
  Log:
  For bug #249731, add an xstrndup wrapper, and implement strndup on hosts that don't have it, based on the strndup implementation of sandbox, with a little change to make it C90 compliant.

Revision  Changes    Path
1.208                pax-utils/scanelf.c

file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanelf.c?rev=1.208&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanelf.c?rev=1.208&content-type=text/plain
diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanelf.c?r1=1.207&r2=1.208

Index: scanelf.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v
retrieving revision 1.207
retrieving revision 1.208
diff -u -r1.207 -r1.208
--- scanelf.c	30 Dec 2008 13:38:35 -0000	1.207
+++ scanelf.c	31 Jan 2009 17:58:37 -0000	1.208
@@ -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.207 2008/12/30 13:38:35 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.208 2009/01/31 17:58:37 grobian 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.207 2008/12/30 13:38:35 vapier Exp $";
+static const char *rcsid = "$Id: scanelf.c,v 1.208 2009/01/31 17:58:37 grobian Exp $";
 const char * const argv0 = "scanelf";
 
 #include "paxinc.h"
@@ -1038,7 +1038,7 @@
 							++this_sym; \
 						} \
 						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); \
+							this_sym = xstrndup(this_sym, next_sym-this_sym); \
 						/* ok, lets compare the name now */ \
 						if (scanelf_match_symname(this_sym, symname)) { \
 							if (be_semi_verbose) { \



1.4                  pax-utils/xfuncs.c

file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/xfuncs.c?rev=1.4&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/xfuncs.c?rev=1.4&content-type=text/plain
diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/xfuncs.c?r1=1.3&r2=1.4

Index: xfuncs.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- xfuncs.c	30 Dec 2008 13:00:29 -0000	1.3
+++ xfuncs.c	31 Jan 2009 17:58:37 -0000	1.4
@@ -1,7 +1,7 @@
 /*
  * Copyright 2003-2007 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.c,v 1.3 2008/12/30 13:00:29 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.c,v 1.4 2009/01/31 17:58:37 grobian Exp $
  *
  * Copyright 2003-2007 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2004-2007 Mike Frysinger  - <vapier@gentoo.org>
@@ -16,6 +16,32 @@
 	return ret;
 }
 
+#ifndef strndup
+static inline char *my_strndup(const char *str, size_t n)
+{
+	size_t r;
+	char *ret;
+	for (r = 0; r < n; ++r)
+		if (!str[r])
+			break;
+
+	ret = xmalloc(r + 1);
+	memcpy(ret, str, r);
+	ret[r] = '\0';
+	return ret;
+}
+/* do this to avoid warning: declaration of 'strndup' shadows a built-in
+ * function */
+#define strndup(S, N) my_strndup(S, N)
+#endif
+
+char *xstrndup(const char *s, const size_t n)
+{
+	char *ret = strndup(s, n);
+	if (!ret) err("Could not strdup(): %s", strerror(errno));
+	return ret;
+}
+
 void *xmalloc(size_t size)
 {
 	void *ret = malloc(size);



1.3                  pax-utils/xfuncs.h

file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/xfuncs.h?rev=1.3&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/xfuncs.h?rev=1.3&content-type=text/plain
diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/xfuncs.h?r1=1.2&r2=1.3

Index: xfuncs.h
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- xfuncs.h	30 Dec 2008 12:58:08 -0000	1.2
+++ xfuncs.h	31 Jan 2009 17:58:37 -0000	1.3
@@ -1,7 +1,7 @@
 /*
  * Copyright 2003-2007 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.h,v 1.2 2008/12/30 12:58:08 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.h,v 1.3 2009/01/31 17:58:37 grobian Exp $
  *
  * Copyright 2003-2007 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2004-2007 Mike Frysinger  - <vapier@gentoo.org>
@@ -11,6 +11,7 @@
 #define __XFUNCS_H__
 
 char *xstrdup(const char *s);
+char *xstrndup(const char *s, const size_t n);
 void *xmalloc(size_t size);
 void *xzalloc(size_t size);
 void *xrealloc(void *ptr, size_t size);






^ permalink raw reply	[flat|nested] 2+ messages in thread

* [gentoo-commits] gentoo-projects commit in pax-utils: scanelf.c xfuncs.c xfuncs.h
@ 2011-09-27 18:37 Mike Frysinger (vapier)
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Frysinger (vapier) @ 2011-09-27 18:37 UTC (permalink / raw
  To: gentoo-commits

vapier      11/09/27 18:37:22

  Modified:             scanelf.c xfuncs.c xfuncs.h
  Log:
  allow people to search for multiple libraries (-N) or data sections (-k)

Revision  Changes    Path
1.226                pax-utils/scanelf.c

file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?rev=1.226&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?rev=1.226&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/scanelf.c?r1=1.225&r2=1.226

Index: scanelf.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v
retrieving revision 1.225
retrieving revision 1.226
diff -u -r1.225 -r1.226
--- scanelf.c	27 Sep 2011 17:28:19 -0000	1.225
+++ scanelf.c	27 Sep 2011 18:37:22 -0000	1.226
@@ -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.225 2011/09/27 17:28:19 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.226 2011/09/27 18:37:22 vapier 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.225 2011/09/27 17:28:19 vapier Exp $";
+static const char *rcsid = "$Id: scanelf.c,v 1.226 2011/09/27 18:37:22 vapier Exp $";
 const char argv0[] = "scanelf";
 
 #include "paxinc.h"
@@ -58,7 +58,9 @@
 static char be_semi_verbose = 0;
 static char *find_sym = NULL;
 static char *find_lib = NULL;
+static array_t _find_lib_arr = array_init_decl, *find_lib_arr = &_find_lib_arr;
 static char *find_section = NULL;
+static array_t _find_section_arr = array_init_decl, *find_section_arr = &_find_section_arr;
 static char *out_format = NULL;
 static char *search_path = NULL;
 static char fix_elf = 0;
@@ -814,7 +816,12 @@
 	void *strtbl_void;
 	char *p;
 
-	if ((op==0 && !show_needed) || (op==1 && !find_lib)) return NULL;
+	/*
+	 * -n -> op==0 -> print all
+	 * -N -> op==1 -> print requested
+	 */
+	if ((op == 0 && !show_needed) || (op == 1 && !find_lib))
+		return NULL;
 
 	strtbl_void = elf_findsecbyname(elf, ".dynstr");
 
@@ -826,10 +833,15 @@
 		Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \
 		Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \
 		Elf ## B ## _Off offset; \
+		size_t matched = 0; \
+		/* Walk all the program headers to find the PT_DYNAMIC */ \
 		for (i = 0; i < EGET(ehdr->e_phnum); i++) { \
-			if (EGET(phdr[i].p_type) != PT_DYNAMIC || EGET(phdr[i].p_filesz) == 0) continue; \
+			if (EGET(phdr[i].p_type) != PT_DYNAMIC || EGET(phdr[i].p_filesz) == 0) \
+				continue; \
 			offset = EGET(phdr[i].p_offset); \
-			if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) continue; \
+			if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) \
+				continue; \
+			/* Walk all the dynamic tags to find NEEDED entries */ \
 			dyn = DYN ## B (elf->vdata + offset); \
 			while (EGET(dyn->d_tag) != DT_NULL) { \
 				if (EGET(dyn->d_tag) == DT_NEEDED) { \
@@ -840,6 +852,7 @@
 					} \
 					needed = elf->data + offset; \
 					if (op == 0) { \
+						/* -n -> print all entries */ \
 						if (!be_wewy_wewy_quiet) { \
 							if (*found_needed) xchrcat(ret, ',', ret_len); \
 							if (use_ldcache) \
@@ -849,9 +862,17 @@
 						} \
 						*found_needed = 1; \
 					} else { \
-						if (!strncmp(find_lib, needed, strlen( !g_match ? needed : find_lib))) { \
+						/* -N -> print matching entries */ \
+						size_t n; \
+						const char *find_lib_name; \
+						\
+						array_for_each(find_lib_arr, n, find_lib_name) \
+							if (!strcmp(find_lib_name, needed)) \
+								++matched; \
+						\
+						if (matched == array_cnt(find_lib_arr)) { \
 							*found_lib = 1; \
-							return (be_wewy_wewy_quiet ? NULL : needed); \
+							return (be_wewy_wewy_quiet ? NULL : find_lib); \
 						} \
 					} \
 				} \
@@ -1213,11 +1234,20 @@
 
 #define FIND_SECTION(B) \
 	if (elf->elf_class == ELFCLASS ## B) { \
+		size_t matched, n; \
 		int invert; \
+		const char *section_name; \
 		Elf ## B ## _Shdr *section; \
-		invert = (*find_section == '!' ? 1 : 0); \
-		section = SHDR ## B (elf_findsecbyname(elf, find_section+invert)); \
-		if ((section == NULL && invert) || (section != NULL && !invert)) \
+		\
+		matched = 0; \
+		array_for_each(find_section_arr, n, section_name) { \
+			invert = (*section_name == '!' ? 1 : 0); \
+			section = SHDR ## B (elf_findsecbyname(elf, section_name + invert)); \
+			if ((section == NULL && invert) || (section != NULL && !invert)) \
+				++matched; \
+		} \
+		\
+		if (matched == array_cnt(find_section_arr)) \
 			*found_section = 1; \
 	}
 	FIND_SECTION(32)
@@ -1822,7 +1852,7 @@
 	"Find a specified symbol",
 	"Find a specified section",
 	"Find a specified library",
-	"Use strncmp to match libraries. (use with -N)",
+	"Use regex matching rather than string compare (use with -s)",
 	"Locate cause of TEXTREL",
 	"Print only ELF files matching etype ET_DYN,ET_EXEC ...",
 	"Print only ELF files matching numeric bits",
@@ -1918,20 +1948,16 @@
 			break;
 		}
 		case 'k':
-			if (find_section) warn("You prob don't want to specify -k twice");
-			find_section = optarg;
+			xarraypush(find_section_arr, optarg, strlen(optarg));
 			break;
 		case 's': {
 			if (find_sym) warn("You prob don't want to specify -s twice");
 			find_sym = optarg;
 			break;
 		}
-		case 'N': {
-			if (find_lib) warn("You prob don't want to specify -N twice");
-			find_lib = optarg;
+		case 'N':
+			xarraypush(find_lib_arr, optarg, strlen(optarg));
 			break;
-		}
-
 		case 'F': {
 			if (out_format) warn("You prob don't want to specify -F twice");
 			out_format = optarg;
@@ -2022,6 +2048,11 @@
 		if (which("objdump") != NULL)
 			has_objdump = 1;
 	}
+	/* flatten arrays for display */
+	if (array_cnt(find_lib_arr))
+		find_lib = array_flatten_str(find_lib_arr);
+	if (array_cnt(find_section_arr))
+		find_section = array_flatten_str(find_section_arr);
 	/* let the format option override all other options */
 	if (out_format) {
 		show_pax = show_phdr = show_textrel = show_rpath = \
@@ -2112,6 +2143,8 @@
 	/* clean up */
 	for (i = 0; ldpaths[i]; ++i)
 		free(ldpaths[i]);
+	free(find_lib);
+	free(find_section);
 
 	if (ldcache != 0)
 		munmap(ldcache, ldcache_size);



1.10                 pax-utils/xfuncs.c

file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/xfuncs.c?rev=1.10&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/xfuncs.c?rev=1.10&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/xfuncs.c?r1=1.9&r2=1.10

Index: xfuncs.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- xfuncs.c	13 Feb 2010 23:27:12 -0000	1.9
+++ xfuncs.c	27 Sep 2011 18:37:22 -0000	1.10
@@ -1,7 +1,7 @@
 /*
  * Copyright 2003-2007 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.c,v 1.9 2010/02/13 23:27:12 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.c,v 1.10 2011/09/27 18:37:22 vapier Exp $
  *
  * Copyright 2003-2007 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2004-2007 Mike Frysinger  - <vapier@gentoo.org>
@@ -64,3 +64,43 @@
 	my_app[1] = '\0';
 	xstrcat(dst, my_app, curr_len);
 }
+
+void *xmemdup(const void *src, size_t n)
+{
+	void *ret = xmalloc(n);
+	memcpy(ret, src, n);
+	return ret;
+}
+
+void xarraypush(array_t *arr, const void *ele, size_t ele_len)
+{
+	size_t n = arr->num++;
+	arr->eles = xrealloc_array(arr->eles, arr->num, sizeof(ele));
+	arr->eles[n] = xmemdup(ele, ele_len);
+}
+
+void xarrayfree(array_t *arr)
+{
+	array_t blank = array_init_decl;
+	size_t n;
+
+	for (n = 0; n < arr->num; ++n)
+		free(arr->eles[n]);
+	free(arr->eles);
+
+	*arr = blank;
+}
+
+char *array_flatten_str(array_t *array)
+{
+	size_t n, len = 0;
+	char *str, *ret = NULL;
+
+	array_for_each(array, n, str) {
+		if (ret)
+			xchrcat(&ret, ',', &len);
+		xstrcat(&ret, str, &len);
+	}
+
+	return ret;
+}



1.5                  pax-utils/xfuncs.h

file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/xfuncs.h?rev=1.5&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/xfuncs.h?rev=1.5&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/xfuncs.h?r1=1.4&r2=1.5

Index: xfuncs.h
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- xfuncs.h	3 Dec 2009 04:15:54 -0000	1.4
+++ xfuncs.h	27 Sep 2011 18:37:22 -0000	1.5
@@ -1,7 +1,7 @@
 /*
  * Copyright 2003-2007 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.h,v 1.4 2009/12/03 04:15:54 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.h,v 1.5 2011/09/27 18:37:22 vapier Exp $
  *
  * Copyright 2003-2007 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2004-2007 Mike Frysinger  - <vapier@gentoo.org>
@@ -18,4 +18,19 @@
 #define xstrcat(dst,src,curr_len) xstrncat(dst,src,curr_len,0)
 void xchrcat(char **dst, const char append, size_t *curr_len);
 
+void *xmemdup(const void *src, size_t n);
+
+typedef struct {
+	void **eles;
+	size_t num;
+} array_t;
+void xarraypush(array_t *array, const void *ele, size_t ele_len);
+void xarrayfree(array_t *array);
+#define xrealloc_array(ptr, size, ele_size) xrealloc(ptr, (size) * (ele_size))
+#define array_for_each(arr, n, ele) \
+	for (n = 0, ele = arr->eles[n]; n < arr->num; ++n, ele = arr->eles[n])
+#define array_init_decl { .eles = NULL, .num = 0, }
+#define array_cnt(arr) (arr)->num
+char *array_flatten_str(array_t *array);
+
 #endif






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-09-27 18:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-31 17:58 [gentoo-commits] gentoo-projects commit in pax-utils: scanelf.c xfuncs.c xfuncs.h Fabian Groffen (grobian)
  -- strict thread matches above, loose matches on Subject: below --
2011-09-27 18:37 Mike Frysinger (vapier)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox