diff options
Diffstat (limited to 'libelf/libelf_ar_util.c')
| -rw-r--r-- | libelf/libelf_ar_util.c | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/libelf/libelf_ar_util.c b/libelf/libelf_ar_util.c index 958fbbf49022..7e6ec4068f69 100644 --- a/libelf/libelf_ar_util.c +++ b/libelf/libelf_ar_util.c @@ -34,21 +34,23 @@ #include "_libelf.h" #include "_libelf_ar.h" -ELFTC_VCSID("$Id: libelf_ar_util.c 2365 2011-12-29 04:36:44Z jkoshy $"); +ELFTC_VCSID("$Id: libelf_ar_util.c 3013 2014-03-23 06:16:59Z jkoshy $"); /* * Convert a string bounded by `start' and `start+sz' (exclusive) to a * number in the specified base. */ int -_libelf_ar_get_number(const char *s, size_t sz, int base, size_t *ret) +_libelf_ar_get_number(const char *src, size_t sz, unsigned int base, + size_t *ret) { - int c, v; size_t r; - const char *e; + unsigned int c, v; + const unsigned char *e, *s; assert(base <= 10); + s = (const unsigned char *) src; e = s + sz; /* skip leading blanks */ @@ -79,17 +81,18 @@ _libelf_ar_get_number(const char *s, size_t sz, int base, size_t *ret) char * _libelf_ar_get_translated_name(const struct ar_hdr *arh, Elf *ar) { - char c, *s; + char *s; + unsigned char c; size_t len, offset; - const char *buf, *p, *q, *r; + const unsigned char *buf, *p, *q, *r; const size_t bufsize = sizeof(arh->ar_name); assert(arh != NULL); assert(ar->e_kind == ELF_K_AR); - assert((const char *) arh >= ar->e_rawfile && - (const char *) arh < ar->e_rawfile + ar->e_rawsize); + assert((const unsigned char *) arh >= ar->e_rawfile && + (const unsigned char *) arh < ar->e_rawfile + ar->e_rawsize); - buf = arh->ar_name; + buf = (const unsigned char *) arh->ar_name; /* * Check for extended naming. @@ -104,8 +107,8 @@ _libelf_ar_get_translated_name(const struct ar_hdr *arh, Elf *ar) * the archive string table where the actual name * resides. */ - if (_libelf_ar_get_number(buf + 1, bufsize - 1, 10, - &offset) == 0) { + if (_libelf_ar_get_number((const char *) (buf + 1), + bufsize - 1, 10, &offset) == 0) { LIBELF_SET_ERROR(ARCHIVE, 0); return (NULL); } @@ -120,21 +123,21 @@ _libelf_ar_get_translated_name(const struct ar_hdr *arh, Elf *ar) for (; p < r && *p != '/'; p++) ; - len = p - q + 1; /* space for the trailing NUL */ + len = (size_t) (p - q + 1); /* space for the trailing NUL */ if ((s = malloc(len)) == NULL) { LIBELF_SET_ERROR(RESOURCE, 0); return (NULL); } - (void) strncpy(s, q, len - 1); + (void) strncpy(s, (const char *) q, len - 1); s[len - 1] = '\0'; return (s); } else if (IS_EXTENDED_BSD_NAME(buf)) { r = buf + LIBELF_AR_BSD_EXTENDED_NAME_PREFIX_SIZE; - if (_libelf_ar_get_number(r, bufsize - + if (_libelf_ar_get_number((const char *) r, bufsize - LIBELF_AR_BSD_EXTENDED_NAME_PREFIX_SIZE, 10, &len) == 0) { LIBELF_SET_ERROR(ARCHIVE, 0); @@ -153,9 +156,9 @@ _libelf_ar_get_translated_name(const struct ar_hdr *arh, Elf *ar) /* * The file name follows the archive header. */ - q = (const char *) (arh + 1); + q = (const unsigned char *) (arh + 1); - (void) strncpy(s, q, len); + (void) strncpy(s, (const char *) q, len); s[len] = '\0'; return (s); @@ -183,10 +186,10 @@ _libelf_ar_get_translated_name(const struct ar_hdr *arh, Elf *ar) q--; } - len = q - buf + 2; /* Add space for a trailing NUL. */ + len = (size_t) (q - buf + 2); /* Space for a trailing NUL. */ } else { /* The buffer only had blanks. */ - buf = ""; + buf = (const unsigned char *) ""; len = 1; } @@ -195,7 +198,7 @@ _libelf_ar_get_translated_name(const struct ar_hdr *arh, Elf *ar) return (NULL); } - (void) strncpy(s, buf, len - 1); + (void) strncpy(s, (const char *) buf, len - 1); s[len - 1] = '\0'; return (s); @@ -229,8 +232,8 @@ _libelf_ar_open(Elf *e, int reporterror) { size_t sz; int scanahead; - char *s, *end; struct ar_hdr arh; + unsigned char *s, *end; _libelf_init_elf(e, ELF_K_AR); @@ -264,7 +267,7 @@ _libelf_ar_open(Elf *e, int reporterror) (void) memcpy(&(ARH), (S), sizeof((ARH))); \ if ((ARH).ar_fmag[0] != '`' || (ARH).ar_fmag[1] != '\n') \ goto error; \ - if (_libelf_ar_get_number((ARH).ar_size, \ + if (_libelf_ar_get_number((char *) (ARH).ar_size, \ sizeof((ARH).ar_size), 10, &(SZ)) == 0) \ goto error; \ } while (0) |
