/[gentoo-projects]/pax-utils/scanelf.c
Gentoo

Diff of /pax-utils/scanelf.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.154 Revision 1.155
1/* 1/*
2 * Copyright 2003-2006 Gentoo Foundation 2 * Copyright 2003-2006 Gentoo Foundation
3 * Distributed under the terms of the GNU General Public License v2 3 * Distributed under the terms of the GNU General Public License v2
4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.154 2006/06/03 18:25:18 solar Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.155 2006/06/11 00:07:33 vapier Exp $
5 * 5 *
6 * Copyright 2003-2006 Ned Ludd - <solar@gentoo.org> 6 * Copyright 2003-2006 Ned Ludd - <solar@gentoo.org>
7 * Copyright 2004-2006 Mike Frysinger - <vapier@gentoo.org> 7 * Copyright 2004-2006 Mike Frysinger - <vapier@gentoo.org>
8 */ 8 */
9 9
10#include "paxinc.h" 10#include "paxinc.h"
11 11
12static const char *rcsid = "$Id: scanelf.c,v 1.154 2006/06/03 18:25:18 solar Exp $"; 12static const char *rcsid = "$Id: scanelf.c,v 1.155 2006/06/11 00:07:33 vapier Exp $";
13#define argv0 "scanelf" 13#define argv0 "scanelf"
14 14
15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+') 15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+')
16 16
17#define do_state(option, flag) \ 17#define do_state(option, flag) \
82 82
83int match_bits = 0; 83int match_bits = 0;
84caddr_t ldcache = 0; 84caddr_t ldcache = 0;
85size_t ldcache_size = 0; 85size_t ldcache_size = 0;
86unsigned long setpax = 0UL; 86unsigned long setpax = 0UL;
87
88/* utility funcs */
89static char *xstrdup(const char *s)
90{
91 char *ret = strdup(s);
92 if (!ret) err("Could not strdup(): %s", strerror(errno));
93 return ret;
94}
95static void *xmalloc(size_t size)
96{
97 void *ret = malloc(size);
98 if (!ret) err("Could not malloc() %li bytes", (unsigned long)size);
99 return ret;
100}
101static void *xrealloc(void *ptr, size_t size)
102{
103 void *ret = realloc(ptr, size);
104 if (!ret) err("Could not realloc() %li bytes", (unsigned long)size);
105 return ret;
106}
107static void xstrncat(char **dst, const char *src, size_t *curr_len, size_t n)
108{
109 size_t new_len;
110
111 new_len = strlen(*dst) + strlen(src);
112 if (*curr_len <= new_len) {
113 *curr_len = new_len + (*curr_len / 2);
114 *dst = realloc(*dst, *curr_len);
115 if (!*dst)
116 err("could not realloc() %li bytes", (unsigned long)*curr_len);
117 }
118
119 if (n)
120 strncat(*dst, src, n);
121 else
122 strcat(*dst, src);
123}
124static inline void xchrcat(char **dst, const char append, size_t *curr_len)
125{
126 static char my_app[2];
127 my_app[0] = append;
128 my_app[1] = '\0';
129 xstrcat(dst, my_app, curr_len);
130}
131
132/* Match filename against entries in matchlist, return TRUE
133 * if the file is listed */
134static int file_matches_list(const char *filename, char **matchlist)
135{
136 char **file;
137 char *match;
138 char buf[__PAX_UTILS_PATH_MAX];
139
140 if (matchlist == NULL)
141 return 0;
142
143 for (file = matchlist; *file != NULL; file++) {
144 if (search_path) {
145 snprintf(buf, sizeof(buf), "%s%s", search_path, *file);
146 match = buf;
147 } else {
148 match = *file;
149 }
150 if (fnmatch(match, filename, 0) == 0)
151 return 1;
152 }
153 return 0;
154}
155 87
156 88
157 89
158/* sub-funcs for scanelf_file() */ 90/* sub-funcs for scanelf_file() */
159static void scanelf_file_get_symtabs(elfobj *elf, void **sym, void **tab) 91static void scanelf_file_get_symtabs(elfobj *elf, void **sym, void **tab)
1942 "\t- 1 due to the out_buffer not being freed in scanelf_file()\n" 1874 "\t- 1 due to the out_buffer not being freed in scanelf_file()\n"
1943 "\t- 1 per QA_TEXTRELS/QA_EXECSTACK/QA_WX_LOAD"); 1875 "\t- 1 per QA_TEXTRELS/QA_EXECSTACK/QA_WX_LOAD");
1944#endif 1876#endif
1945 return EXIT_SUCCESS; 1877 return EXIT_SUCCESS;
1946} 1878}
1879
1880
1881
1882/* utility funcs */
1883static char *xstrdup(const char *s)
1884{
1885 char *ret = strdup(s);
1886 if (!ret) err("Could not strdup(): %s", strerror(errno));
1887 return ret;
1888}
1889static void *xmalloc(size_t size)
1890{
1891 void *ret = malloc(size);
1892 if (!ret) err("Could not malloc() %li bytes", (unsigned long)size);
1893 return ret;
1894}
1895static void *xrealloc(void *ptr, size_t size)
1896{
1897 void *ret = realloc(ptr, size);
1898 if (!ret) err("Could not realloc() %li bytes", (unsigned long)size);
1899 return ret;
1900}
1901static void xstrncat(char **dst, const char *src, size_t *curr_len, size_t n)
1902{
1903 size_t new_len;
1904
1905 new_len = strlen(*dst) + strlen(src);
1906 if (*curr_len <= new_len) {
1907 *curr_len = new_len + (*curr_len / 2);
1908 *dst = realloc(*dst, *curr_len);
1909 if (!*dst)
1910 err("could not realloc() %li bytes", (unsigned long)*curr_len);
1911 }
1912
1913 if (n)
1914 strncat(*dst, src, n);
1915 else
1916 strcat(*dst, src);
1917}
1918static inline void xchrcat(char **dst, const char append, size_t *curr_len)
1919{
1920 static char my_app[2];
1921 my_app[0] = append;
1922 my_app[1] = '\0';
1923 xstrcat(dst, my_app, curr_len);
1924}
1925
1926/* Match filename against entries in matchlist, return TRUE
1927 * if the file is listed */
1928static int file_matches_list(const char *filename, char **matchlist)
1929{
1930 char **file;
1931 char *match;
1932 char buf[__PAX_UTILS_PATH_MAX];
1933
1934 if (matchlist == NULL)
1935 return 0;
1936
1937 for (file = matchlist; *file != NULL; file++) {
1938 if (search_path) {
1939 snprintf(buf, sizeof(buf), "%s%s", search_path, *file);
1940 match = buf;
1941 } else {
1942 match = *file;
1943 }
1944 if (fnmatch(match, filename, 0) == 0)
1945 return 1;
1946 }
1947 return 0;
1948}

Legend:
Removed from v.1.154  
changed lines
  Added in v.1.155

  ViewVC Help
Powered by ViewVC 1.1.20