From ca343c4e2493c8d05e73ab62c89b9245841a32ea Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Wed, 6 Oct 2021 15:13:56 +0900 Subject: [PATCH] Imported Upstream version 0.16 --- Makefile.am | 4 ++++ NEWS | 5 +++++ README | 4 ++-- acinclude.m4 | 4 ++-- bootstrap | 5 +++++ chrpath.c | 27 +++++++++++++++++++++++---- config.guess | 34 ++++++++++++++++++++++------------ config.sub | 6 +++--- configure.ac | 4 ++-- elf.c | 6 +++--- killrpath.c | 9 ++++++++- main.c | 1 + 12 files changed, 80 insertions(+), 29 deletions(-) create mode 100755 bootstrap diff --git a/Makefile.am b/Makefile.am index 92229b7..b50ad21 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,6 +20,10 @@ chrpath_SOURCES = \ EXTRA_DIST = $(man_MANS) +config-updates: + GET 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD' > config.guess + GET 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD' > config.sub + CLEANFILES = *.bb *.bbg *.da *.gcov testsuite/*.bb testsuite/*.bbg coverage: all check for f in *.c; do gcov $$f; done diff --git a/NEWS b/NEWS index aa79845..ebfed8e 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +New in 0.16 released 2014-01-14: + * Fixed all minor bugs discovered by Coverity. + * Updated config.sub and config.guess from the GNU project. + * Mention new project mailing list in the documentation. + New in 0.15 released 2013-11-24: * Updated config.sub and config.guess from the GNU project to work with newer architectures. Thanks to isha vishnoi for the heads up. diff --git a/README b/README index e6c1e88..4be93a2 100644 --- a/README +++ b/README @@ -27,7 +27,7 @@ Source, patches and fixes: The latest source is available from -The project repository is available from - +The project repository and developer mailing list are available +from Send patches and updates to the Alioth project. diff --git a/acinclude.m4 b/acinclude.m4 index 62b03c1..73a7097 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -8,7 +8,7 @@ dnl JAPHAR_GREP_CFLAGS(flag, cmd_if_missing, cmd_if_present) dnl dnl From Japhar. Report changes to japhar@hungry.com dnl -AC_DEFUN(JAPHAR_GREP_CFLAGS, +AC_DEFUN([JAPHAR_GREP_CFLAGS], [case "$CFLAGS" in "$1" | "$1 "* | *" $1" | *" $1 "* ) ifelse($#, 3, [$3], [:]) @@ -19,7 +19,7 @@ AC_DEFUN(JAPHAR_GREP_CFLAGS, esac ]) -AC_DEFUN(CHRPATH_LDRPATH_OPTION, +AC_DEFUN([CHRPATH_LDRPATH_OPTION], [AC_REQUIRE([AC_CANONICAL_TARGET])[]dnl case "$target" in *-linux*|*-gnu*|*-k*bsd*-gnu) diff --git a/bootstrap b/bootstrap new file mode 100755 index 0000000..210db5f --- /dev/null +++ b/bootstrap @@ -0,0 +1,5 @@ +#!/bin/sh +aclocal +autoheader +automake -ac +autoconf diff --git a/chrpath.c b/chrpath.c index 6dfcac1..207e369 100644 --- a/chrpath.c +++ b/chrpath.c @@ -89,6 +89,7 @@ chrpath(const char *filename, const char *newpath, int convert) if (0 != elf_find_dynamic_section(fd, &ehdr, &phdr)) { perror("found no dynamic section"); + elf_close(fd); return 1; } @@ -96,14 +97,16 @@ chrpath(const char *filename, const char *newpath, int convert) if (dyns == NULL) { perror ("allocating memory for dynamic section"); + elf_close(fd); return 1; } memset(dyns, 0, PHDR(p_filesz)); if (lseek(fd, PHDR(p_offset), SEEK_SET) == -1 - || read(fd, dyns, PHDR(p_filesz)) != (int)PHDR(p_filesz)) + || read(fd, dyns, PHDR(p_filesz)) != (ssize_t)PHDR(p_filesz)) { perror ("reading dynamic section"); free(dyns); + elf_close(fd); return 1; } @@ -121,6 +124,7 @@ chrpath(const char *filename, const char *newpath, int convert) { printf("%s: no rpath or runpath tag found.\n", filename); free(dyns); + elf_close(fd); return 2; } @@ -128,6 +132,7 @@ chrpath(const char *filename, const char *newpath, int convert) { perror ("positioning for sections"); free(dyns); + elf_close(fd); return 1; } @@ -138,6 +143,7 @@ chrpath(const char *filename, const char *newpath, int convert) { perror ("reading section header"); free(dyns); + elf_close(fd); return 1; } if (SHDR_W(sh_type) == SHT_STRTAB) @@ -147,31 +153,36 @@ chrpath(const char *filename, const char *newpath, int convert) { fprintf (stderr, "No string table found.\n"); free(dyns); + elf_close(fd); return 2; } - strtab = (char *)malloc(SHDR_O(sh_size)); + /* +1 for forced trailing null */ + strtab = (char *)calloc(1, SHDR_O(sh_size)+1); if (strtab == NULL) { perror ("allocating memory for string table"); free(dyns); + elf_close(fd); return 1; } - memset(strtab, 0, SHDR_O(sh_size)); if (lseek(fd, SHDR_O(sh_offset), SEEK_SET) == -1) { perror ("positioning for string table"); free(strtab); free(dyns); + elf_close(fd); return 1; } - if (read(fd, strtab, SHDR_O(sh_size)) != (int)SHDR_O(sh_size)) + if (read(fd, strtab, SHDR_O(sh_size)) != (ssize_t)SHDR_O(sh_size)) { perror ("reading string table"); free(strtab); free(dyns); + elf_close(fd); return 1; } + strtab[SHDR_O(sh_size)] = 0; /* make sure printed string is null terminated */ if ((int)SHDR_O(sh_size) < rpathoff) { @@ -179,6 +190,7 @@ chrpath(const char *filename, const char *newpath, int convert) elf_tagname(DYNSS(rpath_dyns_index, d_tag))); free(strtab); free(dyns); + elf_close(fd); return 5; } rpath = strtab+rpathoff; @@ -196,6 +208,9 @@ chrpath(const char *filename, const char *newpath, int convert) || write(fd, dyns, PHDR(p_filesz)) != (int)PHDR(p_filesz)) { perror ("converting RPATH to RUNPATH"); + free(strtab); + free(dyns); + elf_close(fd); return 1; } printf("%s: RPATH converted to RUNPATH\n", filename); @@ -209,6 +224,7 @@ chrpath(const char *filename, const char *newpath, int convert) { free(dyns); free(strtab); + elf_close(fd); return 0; } @@ -232,6 +248,7 @@ chrpath(const char *filename, const char *newpath, int convert) newpath, rpathlen); free(dyns); free(strtab); + elf_close(fd); return 7; } @@ -243,6 +260,7 @@ chrpath(const char *filename, const char *newpath, int convert) perror ("positioning for RPATH"); free(dyns); free(strtab); + elf_close(fd); return 1; } if (write(fd, rpath, rpathlen) != (int)rpathlen) @@ -250,6 +268,7 @@ chrpath(const char *filename, const char *newpath, int convert) perror ("writing RPATH"); free(dyns); free(strtab); + elf_close(fd); return 1; } printf("%s: new %s: %s\n", filename, diff --git a/config.guess b/config.guess index b79252d..4438cd7 100755 --- a/config.guess +++ b/config.guess @@ -1,8 +1,8 @@ #! /bin/sh # Attempt to guess a canonical system name. -# Copyright 1992-2013 Free Software Foundation, Inc. +# Copyright 1992-2014 Free Software Foundation, Inc. -timestamp='2013-06-10' +timestamp='2014-01-01' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -50,7 +50,7 @@ version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright 1992-2013 Free Software Foundation, Inc. +Copyright 1992-2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -1260,16 +1260,26 @@ EOF if test "$UNAME_PROCESSOR" = unknown ; then UNAME_PROCESSOR=powerpc fi - if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then - if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_64BIT_ARCH >/dev/null - then - case $UNAME_PROCESSOR in - i386) UNAME_PROCESSOR=x86_64 ;; - powerpc) UNAME_PROCESSOR=powerpc64 ;; - esac + if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then + if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then + if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + case $UNAME_PROCESSOR in + i386) UNAME_PROCESSOR=x86_64 ;; + powerpc) UNAME_PROCESSOR=powerpc64 ;; + esac + fi fi + elif test "$UNAME_PROCESSOR" = i386 ; then + # Avoid executing cc on OS X 10.9, as it ships with a stub + # that puts up a graphical alert prompting to install + # developer tools. Any system running Mac OS X 10.7 or + # later (Darwin 11 and later) is required to have a 64-bit + # processor. This is not true of the ARM version of Darwin + # that Apple uses in portable devices. + UNAME_PROCESSOR=x86_64 fi echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} exit ;; diff --git a/config.sub b/config.sub index 61cb4bc..092cff0 100755 --- a/config.sub +++ b/config.sub @@ -1,8 +1,8 @@ #! /bin/sh # Configuration validation subroutine script. -# Copyright 1992-2013 Free Software Foundation, Inc. +# Copyright 1992-2014 Free Software Foundation, Inc. -timestamp='2013-10-01' +timestamp='2014-01-01' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -68,7 +68,7 @@ Report bugs and patches to ." version="\ GNU config.sub ($timestamp) -Copyright 1992-2013 Free Software Foundation, Inc. +Copyright 1992-2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." diff --git a/configure.ac b/configure.ac index 6fcac09..875f0f5 100644 --- a/configure.ac +++ b/configure.ac @@ -1,10 +1,10 @@ dnl Process this file with autoconf to produce a configure script. -AC_INIT(chrpath, 0.15, pere@hungry.com) +AC_INIT(chrpath, 0.16, chrpath-devel@lists.alioth.debian.org) AC_CANONICAL_TARGET -AM_INIT_AUTOMAKE("chrpath", "0.15") +AM_INIT_AUTOMAKE("chrpath", "0.16") AC_CONFIG_SRCDIR(chrpath.c) AM_CONFIG_HEADER(config.h) diff --git a/elf.c b/elf.c index 4693658..5b9e8b1 100644 --- a/elf.c +++ b/elf.c @@ -86,10 +86,10 @@ elf_open(const char *filename, int flags, Elf_Ehdr *ehdr) } sz_phdr = is_e32() ? sizeof(Elf32_Phdr) : sizeof(Elf64_Phdr); - if (EHDR_PHS(e_phentsize) != sz_phdr) + if ((size_t)EHDR_PHS(e_phentsize) != sz_phdr) { - fprintf(stderr, "section size was read as %d, not %d!\n", - (int)EHDR_PHS(e_phentsize), (int)sz_phdr); + fprintf(stderr, "section size was read as %zd, not %zd!\n", + (size_t)EHDR_PHS(e_phentsize), sz_phdr); close(fd); return -1; } diff --git a/killrpath.c b/killrpath.c index 4acb673..c19fc55 100644 --- a/killrpath.c +++ b/killrpath.c @@ -49,6 +49,7 @@ killrpath(const char *filename) if (0 != elf_find_dynamic_section(fd, &ehdr, &phdr)) { perror("found no dynamic section"); + elf_close(fd); return 1; } @@ -56,13 +57,16 @@ killrpath(const char *filename) if (dyns == NULL) { perror ("allocating memory for dynamic section"); + elf_close(fd); return 1; } memset(dyns, 0, PHDR(p_memsz)); if (lseek(fd, PHDR(p_offset), SEEK_SET) == -1 - || read(fd, dyns, PHDR(p_filesz)) != (int)PHDR(p_filesz)) + || read(fd, dyns, PHDR(p_filesz)) != (ssize_t)PHDR(p_filesz)) { perror ("reading dynamic section"); + free(dyns); + elf_close(fd); return 1; } @@ -91,9 +95,12 @@ killrpath(const char *filename) || write(fd, dyns, PHDR(p_filesz)) != (int)PHDR(p_filesz)) { perror ("writing dynamic section"); + free(dyns); + elf_close(fd); return 1; } + free(dyns); elf_close(fd); return 0; diff --git a/main.c b/main.c index ff5eed6..e0bfc2c 100644 --- a/main.c +++ b/main.c @@ -111,6 +111,7 @@ main(int argc, char * const argv[]) break; default: printf("Invalid argument '%c'\n", opt); + /* Fall through */ case 'h': usage(argv[0]); exit(0); -- 2.7.4