Author: kib
Date: Wed Sep 26 21:27:08 2018
New Revision: 338955
URL: https://svnweb.freebsd.org/changeset/base/338955

Log:
  When doing lm_add(), check for duplicates.
  
  This is useful when lm_find() moves the match to the global mapping,
  since lm_find() could be called with a same path more than once.
  
  Reported and tested by:       Andreas Longwitz <[email protected]>
  Sponsored by: The FreeBSD Foundation
  Approved by:  re (gjb)
  MFC after:    1 week

Modified:
  head/libexec/rtld-elf/libmap.c

Modified: head/libexec/rtld-elf/libmap.c
==============================================================================
--- head/libexec/rtld-elf/libmap.c      Wed Sep 26 21:16:07 2018        
(r338954)
+++ head/libexec/rtld-elf/libmap.c      Wed Sep 26 21:27:08 2018        
(r338955)
@@ -353,6 +353,7 @@ lm_add(const char *p, const char *f, const char *t)
 {
        struct lm_list *lml;
        struct lm *lm;
+       const char *t1;
 
        if (p == NULL)
                p = "$DEFAULT$";
@@ -362,11 +363,14 @@ lm_add(const char *p, const char *f, const char *t)
        if ((lml = lmp_find(p)) == NULL)
                lml = lmp_init(xstrdup(p));
 
-       lm = xmalloc(sizeof(struct lm));
-       lm->f = xstrdup(f);
-       lm->t = xstrdup(t);
-       TAILQ_INSERT_HEAD(lml, lm, lm_link);
-       lm_count++;
+       t1 = lml_find(lml, f);
+       if (t1 == NULL || strcmp(t1, t) != 0) {
+               lm = xmalloc(sizeof(struct lm));
+               lm->f = xstrdup(f);
+               lm->t = xstrdup(t);
+               TAILQ_INSERT_HEAD(lml, lm, lm_link);
+               lm_count++;
+       }
 }
 
 char *
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to