diff options
author | Mike Frysinger <vapier@gentoo.org> | 2009-01-02 00:43:32 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2009-01-02 00:43:32 +0000 |
commit | 2b6627e28c05b2a9d92ff9a6321d5e917c9fbcdd (patch) | |
tree | cd9b77f0061b5491e3ec78bd4b115cb25064f5b2 /sys-devel | |
parent | amd64 stable wrt security bug #250752 (diff) | |
download | historical-2b6627e28c05b2a9d92ff9a6321d5e917c9fbcdd.tar.gz historical-2b6627e28c05b2a9d92ff9a6321d5e917c9fbcdd.tar.bz2 historical-2b6627e28c05b2a9d92ff9a6321d5e917c9fbcdd.zip |
optimize memory/string usage a bit more
Package-Manager: portage-2.2_rc20/cvs/Linux 2.6.28 x86_64
Diffstat (limited to 'sys-devel')
-rw-r--r-- | sys-devel/gcc-config/Manifest | 10 | ||||
-rw-r--r-- | sys-devel/gcc-config/files/wrapper-1.5.1.c | 113 |
2 files changed, 69 insertions, 54 deletions
diff --git a/sys-devel/gcc-config/Manifest b/sys-devel/gcc-config/Manifest index 448008f10c79..79d28395e60e 100644 --- a/sys-devel/gcc-config/Manifest +++ b/sys-devel/gcc-config/Manifest @@ -6,16 +6,16 @@ AUX gcc-config-1.4.0 20822 RMD160 5f0865c95634a3748462e2b6da3f26aa3b62a8d5 SHA1 AUX gcc-config-1.4.1 20945 RMD160 72d1f3fe65b15948ad2019e7ef854f654b048f2b SHA1 9b83e3ea4a50adac2b7533bf78b860c4957ba11a SHA256 ca8d4b96d1672d8cef4be7cbdf6161797a2f673df162753fa8960243ba12ccd1 AUX wrapper-1.4.8.c 9712 RMD160 1210dc111da9955926dc98264991e39489525f20 SHA1 6189891f1577451e34d4f7cc7ada851d63d2f352 SHA256 a45dec68f7a2b4f1d96e83181693afb10cf73b6fbdcd3456055e2bc64bc114e7 AUX wrapper-1.5.0.c 9656 RMD160 9f2838e2bc1e43a752196930a94fdbb79a6efcda SHA1 f824622eeccfc60a8c07bb1878667ee5253c4e42 SHA256 df3fcb1d135d654b57fe685de5321fd1959296cabcbfcf1c3174e075286f5591 -AUX wrapper-1.5.1.c 9214 RMD160 fdbdf7a2bc4099d13fd730c71721ca9c939e9544 SHA1 07174858bf955f8b000e7277e00966fabb14dd74 SHA256 84c39ff9b752e8d4fe55aeec4920ed29c97de74edecf42b96a4de00cef8ed4b4 +AUX wrapper-1.5.1.c 9788 RMD160 b628944ee01dd772eb917cd08d13dc41bf58409f SHA1 51ac1f9419bc2230a9ce2196e70b5ee4ba61be18 SHA256 991981059fdcd0a9c76d73ff2ce576e553f37ae7d3b378b92ead553963f7339a EBUILD gcc-config-1.3.16.ebuild 1527 RMD160 69365cd208813bb12bd862588108334d0b3ef084 SHA1 0c724faff5a919c723ada92e2069fc480ae3ee53 SHA256 5996ca2ce991811fd6a0989c6bcaeb41f154585a8176c3499f3ec5f727c8b4ed EBUILD gcc-config-1.4.0-r4.ebuild 1678 RMD160 479bb75080507a991c8bced82dc051be906eb4a5 SHA1 c7d5bd1d3770648c5757360c5be863b3cc178d45 SHA256 a7f98327b8fbd2d587e7bbefcdb86fcb6ba6571ab92de8d2e4764dbd6e0ab2e1 EBUILD gcc-config-1.4.1.ebuild 1688 RMD160 049dd70840948fb4f74a28efca7a606a24ae11f9 SHA1 dcd7d91b5fdc63e8b227063e65c8baf4043539da SHA256 64e78ed796ca6ad3826e7db412acbb2bd8499f3cceb94216b0c71ccc43b0862d MISC ChangeLog 32185 RMD160 7a4c6ba9f262a235443a7243ee3074fa6eb1d55e SHA1 0e3985559c6584b14d6a37b60391b36435c039f5 SHA256 d51db57ce61bfd63c9e949de51b08fc67b2370f35ab8571d1f6237dfb150ccde MISC metadata.xml 162 RMD160 d002486a43522f2116b1d9d59828c484956d66e2 SHA1 d6b4923897f6ae673b4f93646f5b4ba61d5a2c3c SHA256 65a915d44de1f01d4b7f72d313b4192c38374a9835d24988c00c1e73dca5805a -----BEGIN PGP SIGNATURE----- -Version: GnuPG v2.0.7 (GNU/Linux) +Version: GnuPG v2.0.9 (GNU/Linux) -iD8DBQFH4sZFj9hvisErhMIRAoaeAKCVvyXS9JstRvFveI/LQexu4PI+ZwCg2+17 -8OLGlQY0oeF3Ta2ItfQIsGo= -=a9Nx +iEYEARECAAYFAkldYzoACgkQn/5bYzqsSmE12gCfdYt9WkhhEman5kA5Frr7tW6d +IpMAn3qO7hPxZT6//rorZtMB5m8gRvR2 +=hODT -----END PGP SIGNATURE----- diff --git a/sys-devel/gcc-config/files/wrapper-1.5.1.c b/sys-devel/gcc-config/files/wrapper-1.5.1.c index 2adb0d696e21..055594b5ad01 100644 --- a/sys-devel/gcc-config/files/wrapper-1.5.1.c +++ b/sys-devel/gcc-config/files/wrapper-1.5.1.c @@ -1,28 +1,41 @@ /* * Copyright 1999-2008 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvsroot/gentoo-x86/sys-devel/gcc-config/files/wrapper-1.5.1.c,v 1.1 2008/03/16 01:20:11 vapier Exp $ + * $Header: /var/cvsroot/gentoo-x86/sys-devel/gcc-config/files/wrapper-1.5.1.c,v 1.2 2009/01/02 00:43:32 vapier Exp $ * Author: Martin Schlemmer <azarah@gentoo.org> * az's lackey: Mike Frysinger <vapier@gentoo.org> */ -#define _GNU_SOURCE +#ifdef DEBUG +# define USE_DEBUG 1 +#else +# define USE_DEBUG 0 +#endif +#include <errno.h> +#include <libgen.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/param.h> -#include <unistd.h> -#include <sys/wait.h> -#include <libgen.h> #include <string.h> -#include <stdarg.h> -#include <errno.h> +#include <unistd.h> +#include <sys/stat.h> +#include <sys/types.h> #define GCC_CONFIG "/usr/bin/gcc-config" #define ENVD_BASE "/etc/env.d/05gcc" +#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0])) + +/* basename(3) is allowed to modify memory */ +#undef basename +#define basename(path) \ +({ \ + char *__path = path; \ + char *__ret = strrchr(__path, '/'); \ + __ret ? __ret + 1 : __path; \ +}) + struct wrapper_data { char *name, *fullname, *bin, *path; }; @@ -33,27 +46,19 @@ static const struct { } wrapper_aliases[] = { { "cc", "gcc" }, { "f77", "g77" }, - { NULL, NULL } }; -static void wrapper_err(char *msg, ...) -{ - va_list args; - fprintf(stderr, "gcc-config error: "); - va_start(args, msg); - vfprintf(stderr, msg, args); - va_end(args); - fprintf(stderr, "\n"); - exit(1); -} +#define wrapper_warn(fmt, ...) fprintf(stderr, "%s" fmt "\n", "gcc-config: ", ## __VA_ARGS__) +#define wrapper_err(fmt, ...) ({ wrapper_warn("%s" fmt, "error: ", ## __VA_ARGS__); exit(1); }) #define wrapper_errp(fmt, ...) wrapper_err(fmt ": %s", ## __VA_ARGS__, strerror(errno)) +#define wrapper_dbg(fmt, ...) ({ if (USE_DEBUG) wrapper_warn(fmt, ## __VA_ARGS__); }) #define xmemwrap(func, proto, use) \ static void *x ## func proto \ { \ void *ret = func use; \ if (!ret) \ - wrapper_err(#func "out of memory"); \ + wrapper_err(#func "%s", ": out of memory"); \ return ret; \ } xmemwrap(malloc, (size_t size), (size)) @@ -67,25 +72,34 @@ xmemwrap(strdup, (const char *s), (s)) static int check_for_target(char *path, struct wrapper_data *data) { struct stat sbuf; - char str[MAXPATHLEN + 1]; - size_t len = strlen(path) + strlen(data->name) + 2; + char str[PATH_MAX + 1]; + size_t path_len = strlen(path); + size_t len = path_len + strlen(data->name) + 2; - snprintf(str, sizeof(str), "%s/%s", path, data->name); + if (sizeof(str) < len) + wrapper_warn("path too long: %s", path); + + strcpy(str, path); + str[path_len] = '/'; + str[path_len+1] = '\0'; + strcat(str, data->name); /* Stat possible file to check that * 1) it exist and is a regular file, and * 2) it is not the wrapper itself, and * 3) it is in a /gcc-bin/ directory tree */ - if (stat(str, &sbuf) == 0 && - (S_ISREG(sbuf.st_mode) || S_ISLNK(sbuf.st_mode)) && - (strcmp(str, data->fullname) != 0) && - (strstr(str, "/gcc-bin/") != 0)) + if (strcmp(str, data->fullname) != 0 && + strstr(str, "/gcc-bin/") != NULL && + stat(str, &sbuf) == 0 && + (S_ISREG(sbuf.st_mode) || S_ISLNK(sbuf.st_mode))) { + wrapper_dbg("%s: found in %s", data->name, path); data->bin = xstrdup(str); return 1; } + wrapper_dbg("%s: did not find in %s", data->name, path); return 0; } @@ -112,6 +126,7 @@ static int find_target_in_path(struct wrapper_data *data) token = strtok_r(NULL, ":", &state); } + wrapper_dbg("%s: did not find in PATH", data->name); return 0; } @@ -123,9 +138,9 @@ static int find_target_in_envd(struct wrapper_data *data, int cross_compile) { FILE *envfile = NULL; char *token = NULL, *state; - char str[MAXPATHLEN + 1]; + char str[PATH_MAX + 1]; char *strp = str; - char envd_file[MAXPATHLEN + 1]; + char envd_file[PATH_MAX + 1]; if (!cross_compile) { /* for the sake of speed, we'll keep a symlink around for @@ -138,7 +153,7 @@ static int find_target_in_envd(struct wrapper_data *data, int cross_compile) return 0; ctarget = xstrdup(data->name); ctarget[end - data->name] = '\0'; - snprintf(envd_file, MAXPATHLEN, "%s-%s", ENVD_BASE, ctarget); + snprintf(envd_file, PATH_MAX, "%s-%s", ENVD_BASE, ctarget); free(ctarget); } @@ -146,7 +161,7 @@ static int find_target_in_envd(struct wrapper_data *data, int cross_compile) if (envfile == NULL) return 0; - while (fgets(strp, MAXPATHLEN, envfile) != NULL) { + while (fgets(strp, PATH_MAX, envfile) != NULL) { /* Keep reading ENVD_FILE until we get a line that * starts with 'GCC_PATH=' ... keep 'PATH=' around * for older gcc versions. @@ -156,13 +171,13 @@ static int find_target_in_envd(struct wrapper_data *data, int cross_compile) continue; token = strtok_r(strp, "=", &state); - if ((token != NULL) && strlen(token)) + if ((token != NULL) && token[0]) /* The second token should be the value of PATH .. */ token = strtok_r(NULL, "=", &state); else goto bail; - if ((token != NULL) && strlen(token)) { + if ((token != NULL) && token[0]) { strp = token; /* A bash variable may be unquoted, quoted with " or * quoted with ', so extract the value without those .. @@ -202,8 +217,8 @@ static void find_wrapper_target(struct wrapper_data *data) if (inpipe == NULL) wrapper_errp("could not open pipe"); - char str[MAXPATHLEN + 1]; - if (fgets(str, MAXPATHLEN, inpipe) == 0) + char str[PATH_MAX + 1]; + if (fgets(str, PATH_MAX, inpipe) == 0) wrapper_errp("could not get compiler binary path"); /* chomp! */ @@ -211,7 +226,7 @@ static void find_wrapper_target(struct wrapper_data *data) if (str[plen-1] == '\n') str[plen-1] = '\0'; - data->bin = xmalloc(strlen(str) + 1 + strlen(data->name) + 1); + data->bin = xmalloc(plen + 1 + strlen(data->name) + 1); sprintf(data->bin, "%s/%s", str, data->name); pclose(inpipe); @@ -221,28 +236,28 @@ static void find_wrapper_target(struct wrapper_data *data) static void modify_path(struct wrapper_data *data) { char *newpath = NULL, *token = NULL, *state; - char dname_data[MAXPATHLEN + 1], str[MAXPATHLEN + 1]; + char dname_data[PATH_MAX + 1], str[PATH_MAX + 1]; char *str2 = dname_data, *dname = dname_data; size_t len = 0; if (data->bin == NULL) return; - snprintf(str2, MAXPATHLEN + 1, "%s", data->bin); - - if ((dname = dirname(str2)) == NULL) + if (data->path == NULL) return; - if (data->path == NULL) + snprintf(str2, PATH_MAX + 1, "%s", data->bin); + + if ((dname = dirname(str2)) == NULL) return; /* Make a copy since strtok_r will modify path */ - snprintf(str, MAXPATHLEN + 1, "%s", data->path); + snprintf(str, PATH_MAX + 1, "%s", data->path); token = strtok_r(str, ":", &state); /* Check if we already appended our bin location to PATH */ - if ((token != NULL) && strlen(token)) + if ((token != NULL) && token[0]) if (!strcmp(token, dname)) return; @@ -256,7 +271,7 @@ static void modify_path(struct wrapper_data *data) } static char *abi_flags[] = { - "-m32", "-m64", "-mabi", NULL + "-m32", "-m64", "-mabi", }; static char **build_new_argv(char **argv, const char *newflags_str) { @@ -274,7 +289,7 @@ static char **build_new_argv(char **argv, const char *newflags_str) * of the time ... */ for (argc = 0; argv[argc]; ++argc) - for (i = 0; abi_flags[i]; ++i) + for (i = 0; i < ARRAY_SIZE(abi_flags); ++i) if (!strncmp(argv[argc], abi_flags[i], strlen(abi_flags[i]))) return retargv; @@ -308,11 +323,11 @@ int main(int argc, char *argv[]) data.path = xstrdup(getenv("PATH")); /* What should we find ? */ - data.name = basename(xstrdup(argv[0])); + data.name = basename(argv[0]); /* Allow for common compiler names like cc->gcc */ size_t i; - for (i = 0; wrapper_aliases[i].alias; ++i) + for (i = 0; i < ARRAY_SIZE(wrapper_aliases); ++i) if (!strcmp(data.name, wrapper_aliases[i].alias)) data.name = wrapper_aliases[i].target; |