? pspax ? scanelf Index: paxelf.c =================================================================== RCS file: /var/cvsroot/gentoo-projects/pax-utils/paxelf.c,v retrieving revision 1.14 diff -u -r1.14 paxelf.c --- paxelf.c 5 Apr 2005 00:55:22 -0000 1.14 +++ paxelf.c 6 Apr 2005 13:03:03 -0000 @@ -232,10 +232,10 @@ if (st.st_size <= EI_NIDENT) goto close_fd_and_return; - elf = (elfobj*)malloc(sizeof(elfobj)); + elf = (elfobj*)malloc(sizeof(*elf)); if (elf == NULL) goto close_fd_and_return; - memset(elf, 0x00, sizeof(elfobj)); + memset(elf, 0x00, sizeof(*elf)); elf->fd = fd; elf->len = st.st_size; @@ -277,7 +277,7 @@ { munmap(elf->data, elf->len); close(elf->fd); - memset(elf, 0, sizeof(elfobj)); + memset(elf, 0, sizeof(*elf)); free(elf); } Index: pspax.c =================================================================== RCS file: /var/cvsroot/gentoo-projects/pax-utils/pspax.c,v retrieving revision 1.9 diff -u -r1.9 pspax.c --- pspax.c 5 Apr 2005 00:51:33 -0000 1.9 +++ pspax.c 6 Apr 2005 13:03:03 -0000 @@ -72,6 +72,8 @@ if ((fp = fopen(buf, "r")) == NULL) return NULL; + memset(&buf, 0, sizeof(buf)); + fscanf(fp, "%*d %s.16", buf); if (*buf) { buf[strlen(buf) - 1] = '\0'; @@ -97,7 +99,7 @@ static char *get_proc_status(pid_t pid, char *name) { FILE *fp; - int len; + size_t len; static char s[PATH_MAX]; snprintf(s, sizeof(s), PROC_DIR "/%d/status", (int) pid); @@ -237,7 +239,7 @@ int i; printf("¤ List ELF/PaX information about running processes\n\n" "Usage: %s [options]\n\n", argv0); - fputs("Options:\n", stdout); + printf("Options:\n"); for (i = 0; long_opts[i].name; ++i) printf(" -%c, --%-12s× %s\n", long_opts[i].val, long_opts[i].name, opts_help[i]); Index: scanelf.c =================================================================== RCS file: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v retrieving revision 1.31 diff -u -r1.31 scanelf.c --- scanelf.c 6 Apr 2005 02:01:52 -0000 1.31 +++ scanelf.c 6 Apr 2005 13:03:03 -0000 @@ -213,8 +213,14 @@ } if (find_sym) { + size_t len = strlen(find_sym) + 1 + 1; void *symtab_void, *strtab_void; - char *versioned_symname = malloc(strlen(find_sym)+2); + char *versioned_symname = malloc(sizeof(char) * len); + + if (!versioned_symname) { + warn("Can not malloc() memory for symbol scanning"); + return; + } sprintf(versioned_symname, "%s@", find_sym); symtab_void = elf_findsecbyname(elf, ".symtab"); @@ -239,7 +245,7 @@ found_sym = 1; \ } \ if ((strcmp(find_sym, symname) == 0) || \ - (strncmp(symname, versioned_symname, strlen(versioned_symname)) == 0)) \ + (strncmp(symname, versioned_symname, len) == 0)) \ found_sym++; \ } \ ++sym; \ @@ -269,7 +275,7 @@ register struct dirent *dentry; struct stat st_top, st; char buf[_POSIX_PATH_MAX]; - size_t len = 0; + size_t pathlen = 0, len = 0; /* make sure path exists */ if (lstat(path, &st_top) == -1) @@ -288,10 +294,12 @@ } if (be_verbose) printf("%s: scanning dir\n", path); + pathlen = strlen(path); + while ((dentry = readdir(dir))) { if (!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, "..")) continue; - len = (strlen(path) + 2 + strlen(dentry->d_name)); + len = (pathlen + 1 + strlen(dentry->d_name) + 1); if (len >= sizeof(buf)) warn("len > sizeof(buf); %d %d = %s\n", len, sizeof(buf), path); assert(len < sizeof(buf)); sprintf(buf, "%s/%s", path, dentry->d_name); @@ -310,15 +318,13 @@ /* scan /etc/ld.so.conf for paths */ static void scanelf_ldpath() { - char scan_l, scan_ul, scan_ull; + char scan_l = 0, scan_ul = 0, scan_ull = 0; char *path, *p; FILE *fp; if ((fp = fopen("/etc/ld.so.conf", "r")) == NULL) err("Unable to open ld.so.conf: %s", strerror(errno)); - scan_l = scan_ul = scan_ull = 0; - if ((path = malloc(_POSIX_PATH_MAX)) == NULL) { warn("Can not malloc() memory for ldpath scanning"); return; @@ -335,12 +341,11 @@ scanelf_dir(path); } free(path); + fclose(fp); if (!scan_l) scanelf_dir("/lib"); if (!scan_ul) scanelf_dir("/usr/lib"); if (!scan_ull) scanelf_dir("/usr/local/lib"); - - fclose(fp); } /* scan env PATH for paths */ @@ -353,7 +358,7 @@ err("PATH is not set in your env !"); if ((path = strdup(path)) == NULL) - err("stdup failed: %s", strerror(errno)); + err("strdup failed: %s", strerror(errno)); while ((p = strrchr(path, ':')) != NULL) { scanelf_dir(p + 1);