diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2007-03-16 21:16:09 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2007-03-16 21:16:09 +0000 |
commit | 443871a60b935dcd2ca643cf1fde189c9c6540ac (patch) | |
tree | 577ca1796834d01cf86b6c37319a0b817796bb43 /newlib | |
parent | a167bcd8e59baf24d5a200d0c3e31817433974c6 (diff) | |
download | newlib-443871a60b935dcd2ca643cf1fde189c9c6540ac.zip newlib-443871a60b935dcd2ca643cf1fde189c9c6540ac.tar.gz newlib-443871a60b935dcd2ca643cf1fde189c9c6540ac.tar.bz2 |
2007-03-16 Charles Wilson <cygwin@...>
* libc/argz/argz_insert.c: "before" pointer is
invalid after *argz realloc. Compute offset
between "before" and *argz, and use it after
reallocation instead.
Diffstat (limited to 'newlib')
-rw-r--r-- | newlib/ChangeLog | 7 | ||||
-rw-r--r-- | newlib/libc/argz/argz_insert.c | 7 |
2 files changed, 12 insertions, 2 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog index df161dc..50a5b37 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,10 @@ +2007-03-16 Charles Wilson <cygwin@...> + + * libc/argz/argz_insert.c: "before" pointer is + invalid after *argz realloc. Compute offset + between "before" and *argz, and use it after + reallocation instead. + 2007-03-16 Eric Blake <ebb9@byu.net> * libc/stdio64/fseek064.c (_fseeko64_r): Fix reentrancy. diff --git a/newlib/libc/argz/argz_insert.c b/newlib/libc/argz/argz_insert.c index 8a9fb19..3ae6621 100644 --- a/newlib/libc/argz/argz_insert.c +++ b/newlib/libc/argz/argz_insert.c @@ -28,13 +28,16 @@ _DEFUN (argz_insert, (argz, argz_len, before, entry), while (before != *argz && before[-1]) before--; + /* delta will always be non-negative, and < *argz_len */ + ptrdiff_t delta = before - *argz; + len = strlen(entry) + 1; if(!(*argz = (char *)realloc(*argz, *argz_len + len))) return ENOMEM; - memmove(before + len, before, *argz + *argz_len - before); - memcpy(before, entry, len); + memmove(*argz + delta + len, *argz + delta, *argz_len - delta); + memcpy(*argz + delta, entry, len); *argz_len += len; |