OSDN Git Service

Fix silly buffer overflow
authorEric Andersen <andersen@codepoet.org>
Wed, 13 Feb 2002 07:25:03 +0000 (07:25 -0000)
committerEric Andersen <andersen@codepoet.org>
Wed, 13 Feb 2002 07:25:03 +0000 (07:25 -0000)
ldso/util/ldd.c

index 68221fa..f9cdd8d 100644 (file)
@@ -38,6 +38,9 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include "elf.h"
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
 
 struct library {
        char *name;
@@ -252,7 +255,7 @@ static int add_library(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, char *strtab, int i
        newlib = malloc(sizeof(struct library));
        if (!newlib)
                return 1;
-       newlib->name = malloc(strlen(s));
+       newlib->name = malloc(strlen(s)+1);
        strcpy(newlib->name, s);
        newlib->resolved = 0;
        newlib->path = NULL;
@@ -317,7 +320,7 @@ static void find_elf_interpreter(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, char *str
                        newlib = malloc(sizeof(struct library));
                if (!newlib)
                        return;
-               newlib->name = malloc(strlen(s));
+               newlib->name = malloc(strlen(s)+1);
                strcpy(newlib->name, s);
                newlib->path = newlib->name;
                newlib->resolved = 1;