diff mbox series

elf: check for rpath emptiness before making a copy of it

Message ID 20171227230220.GC11902@altlinux.org
State New
Headers show
Series elf: check for rpath emptiness before making a copy of it | expand

Commit Message

Dmitry V. Levin Dec. 27, 2017, 11:02 p.m. UTC
* elf/dl-load.c (decompose_rpath): Check for rpath emptiness before
making a copy of it.
---
 ChangeLog     |  3 +++
 elf/dl-load.c | 18 ++++++++----------
 2 files changed, 11 insertions(+), 10 deletions(-)

Comments

Aurelien Jarno Dec. 31, 2017, 4:36 p.m. UTC | #1
On 2017-12-28 02:02, Dmitry V. Levin wrote:
> * elf/dl-load.c (decompose_rpath): Check for rpath emptiness before
> making a copy of it.
> ---
>  ChangeLog     |  3 +++
>  elf/dl-load.c | 18 ++++++++----------
>  2 files changed, 11 insertions(+), 10 deletions(-)
> 
> diff --git a/elf/dl-load.c b/elf/dl-load.c
> index ae86f0b..f3ff49b 100644
> --- a/elf/dl-load.c
> +++ b/elf/dl-load.c
> @@ -490,7 +490,6 @@ decompose_rpath (struct r_search_path_struct *sps,
>  {
>    /* Make a copy we can work with.  */
>    const char *where = l->l_name;
> -  char *copy;
>    char *cp;
>    struct r_search_path_elem **result;
>    size_t nelems;
> @@ -529,22 +528,21 @@ decompose_rpath (struct r_search_path_struct *sps,
>        while (*inhp != '\0');
>      }
>  
> +  /* Ignore empty rpaths.  */
> +  if (*rpath == '\0')
> +    {
> +      sps->dirs = (struct r_search_path_elem **) -1;
> +      return false;
> +    }
> +
>    /* Make a writable copy.  */
> -  copy = __strdup (rpath);
> +  char *copy = __strdup (rpath);
>    if (copy == NULL)
>      {
>        errstring = N_("cannot create RUNPATH/RPATH copy");
>        goto signal_error;
>      }
>  
> -  /* Ignore empty rpaths.  */
> -  if (*copy == 0)
> -    {
> -      free (copy);
> -      sps->dirs = (struct r_search_path_elem **) -1;
> -      return false;
> -    }
> -
>    /* Count the number of necessary elements in the result array.  */
>    nelems = 0;
>    for (cp = copy; *cp != '\0'; ++cp)

That looks good to me.
diff mbox series

Patch

diff --git a/elf/dl-load.c b/elf/dl-load.c
index ae86f0b..f3ff49b 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -490,7 +490,6 @@  decompose_rpath (struct r_search_path_struct *sps,
 {
   /* Make a copy we can work with.  */
   const char *where = l->l_name;
-  char *copy;
   char *cp;
   struct r_search_path_elem **result;
   size_t nelems;
@@ -529,22 +528,21 @@  decompose_rpath (struct r_search_path_struct *sps,
       while (*inhp != '\0');
     }
 
+  /* Ignore empty rpaths.  */
+  if (*rpath == '\0')
+    {
+      sps->dirs = (struct r_search_path_elem **) -1;
+      return false;
+    }
+
   /* Make a writable copy.  */
-  copy = __strdup (rpath);
+  char *copy = __strdup (rpath);
   if (copy == NULL)
     {
       errstring = N_("cannot create RUNPATH/RPATH copy");
       goto signal_error;
     }
 
-  /* Ignore empty rpaths.  */
-  if (*copy == 0)
-    {
-      free (copy);
-      sps->dirs = (struct r_search_path_elem **) -1;
-      return false;
-    }
-
   /* Count the number of necessary elements in the result array.  */
   nelems = 0;
   for (cp = copy; *cp != '\0'; ++cp)