From patchwork Fri Oct 24 03:07:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos O'Donell X-Patchwork-Id: 3352 Received: (qmail 6066 invoked by alias); 24 Oct 2014 03:07:28 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 6056 invoked by uid 89); 24 Oct 2014 03:07:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Message-ID: <5449C26B.4070600@redhat.com> Date: Thu, 23 Oct 2014 23:07:23 -0400 From: "Carlos O'Donell" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.0 MIME-Version: 1.0 To: GNU C Library Subject: [PATCH] elf/dl-load.c: Remove local_strdup. This patch removes the apparently superfluous local_strdup. I can find no reason for it to be here and the reason for it being there is not documented. It has been present since 1996-08-15 in a patch that simply refactored strlen/malloc/memcpy code into local_strdup without changing anything. Probably a conservative change. Why strdup was not called is not clear. I have verified that building dl-load.c uses the __strdup alias so the loader is self-consistent. Tested on x86_64 with no regressions. OK to commit? 2014-10-23 Carlos O'Donell * dl-load.c (local_strdup): Remove. (expand_dynamic_string_token): Use strdup. (decompose_rpath): Likewise. (_dl_map_object): Likewise. --- Cheers, Carlos. diff --git a/elf/dl-load.c b/elf/dl-load.c index 9dd40e3..538a00a 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -112,20 +112,6 @@ static const size_t system_dirs_len[] = (sizeof (system_dirs_len) / sizeof (system_dirs_len[0])) -/* Local version of `strdup' function. */ -static char * -local_strdup (const char *s) -{ - size_t len = strlen (s) + 1; - void *new = malloc (len); - - if (new == NULL) - return NULL; - - return (char *) memcpy (new, s, len); -} - - static bool is_trusted_path (const char *path, size_t len) { @@ -384,7 +370,7 @@ expand_dynamic_string_token (struct link_map *l, const char *s, int is_path) /* If we do not have to replace anything simply copy the string. */ if (__glibc_likely (cnt == 0)) - return local_strdup (s); + return strdup (s); /* Determine the length of the substituted string. */ total = DL_DST_REQUIRED (l, s, strlen (s), cnt); @@ -593,7 +579,7 @@ decompose_rpath (struct r_search_path_struct *sps, } /* Make a writable copy. */ - copy = local_strdup (rpath); + copy = strdup (rpath); if (copy == NULL) { errstring = N_("cannot create RUNPATH/RPATH copy"); @@ -2101,7 +2087,7 @@ _dl_map_object (struct link_map *loader, const char *name, false); if (__glibc_likely (fd != -1)) { - realname = local_strdup (cached); + realname = strdup (cached); if (realname == NULL) { __close (fd); @@ -2130,7 +2116,7 @@ _dl_map_object (struct link_map *loader, const char *name, /* The path may contain dynamic string tokens. */ realname = (loader ? expand_dynamic_string_token (loader, name, 0) - : local_strdup (name)); + : strdup (name)); if (realname == NULL) fd = -1; else @@ -2164,7 +2150,7 @@ _dl_map_object (struct link_map *loader, const char *name, static const Elf_Symndx dummy_bucket = STN_UNDEF; /* Allocate a new object map. */ - if ((name_copy = local_strdup (name)) == NULL + if ((name_copy = strdup (name)) == NULL || (l = _dl_new_object (name_copy, name, type, loader, mode, nsid)) == NULL) {