summaryrefslogtreecommitdiffstats
path: root/lib/libelf
diff options
context:
space:
mode:
authorjkoshy <jkoshy@FreeBSD.org>2007-03-27 04:40:57 +0000
committerjkoshy <jkoshy@FreeBSD.org>2007-03-27 04:40:57 +0000
commite13fe525e7dcee7573087e9eea5bdbd6c9f3d265 (patch)
treeec7a8fb8cb28e6283927ee1134d02904916e7dec /lib/libelf
parentb25ea91d228fbda021f6a83bb11dbea117ac3b47 (diff)
downloadFreeBSD-src-e13fe525e7dcee7573087e9eea5bdbd6c9f3d265.zip
FreeBSD-src-e13fe525e7dcee7573087e9eea5bdbd6c9f3d265.tar.gz
Bug fixes to ar(1) archive handling:
- Correctly retrieve the initial (special) members of an archive after an archive descriptor is rewound using elf_rand(SARMAG). - Do not strip trailing white space from the 'raw' names retrieved using elf_getarhdr(). Reported by: "Hyo geol, Lee" <hyogeollee at gmail dot com>
Diffstat (limited to 'lib/libelf')
-rw-r--r--lib/libelf/libelf_ar.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/lib/libelf/libelf_ar.c b/lib/libelf/libelf_ar.c
index 8420c4d..31eea3d 100644
--- a/lib/libelf/libelf_ar.c
+++ b/lib/libelf/libelf_ar.c
@@ -114,22 +114,40 @@ _libelf_ar_get_number(char *s, size_t sz, int base, size_t *ret)
* ar(1) control characters in.
*/
static char *
-_libelf_ar_get_string(char *buf, size_t bufsize, int rawname)
+_libelf_ar_get_string(const char *buf, size_t bufsize, int rawname)
{
- char *q, *r;
+ const char *q;
+ char *r;
size_t sz;
- /* Skip back over trailing blanks. */
- for (q = buf + bufsize - 1; q > buf && *q == ' '; --q)
- ;
-
- if (rawname == 0 && *q == '/')
- q--;
+ if (rawname)
+ sz = bufsize + 1;
+ else {
+ /* Skip back over trailing blanks. */
+ for (q = buf + bufsize - 1; q >= buf && *q == ' '; --q)
+ ;
- if (q <= buf)
- return (NULL);
+ if (q < buf) {
+ /*
+ * If the input buffer only had blanks in it,
+ * return a zero-length string.
+ */
+ buf = "";
+ sz = 1;
+ } else {
+ /*
+ * Remove the trailing '/' character, but only
+ * if the name isn't one of the special names
+ * "/" and "//".
+ */
+ if (q > buf + 1 ||
+ (q == (buf + 1) && *buf != '/'))
+ q--;
+
+ sz = q - buf + 2; /* Space for a trailing NUL. */
+ }
+ }
- sz = q - buf + 2; /* Space for a trailing NUL. */
if ((r = malloc(sz)) == NULL) {
LIBELF_SET_ERROR(RESOURCE, 0);
return (NULL);
@@ -147,13 +165,13 @@ _libelf_ar_get_string(char *buf, size_t bufsize, int rawname)
static char *
_libelf_ar_get_name(char *buf, size_t bufsize, Elf *e)
{
- char *q, *r, *s;
+ char c, *q, *r, *s;
size_t len;
size_t offset;
assert(e->e_kind == ELF_K_AR);
- if (buf[0] == '/') {
+ if (buf[0] == '/' && (c = buf[1]) >= '0' && c <= '9') {
/*
* The value in field ar_name is a decimal offset into
* the archive string table where the actual name
OpenPOWER on IntegriCloud