On Tue, 2004-03-02 at 22:59, Scott James Remnant wrote: > Patch attached. > Bugger. Scott -- Have you ever, ever felt like this? Had strange things happen? Are you going round the twist?
--- lib/tarfn.c~ +++ lib/tarfn.c @@ -51,6 +51,21 @@ return n; } +/* String block to C null-terminated string */ +char * +StoC(const char *s, int size) +{ + int len; + char * str; + + len = strnlen(s, size); + str = malloc(len + 1); + strncpy(str, s, len); + str[len] = 0; + + return str; +} + static int DecodeTarHeader(char * block, TarInfo * d) { @@ -67,8 +82,8 @@ if ( *h->GroupName ) group = getgrnam(h->GroupName); - d->Name = h->Name; - d->LinkName = h->LinkName; + d->Name = StoC(h->Name, sizeof(h->Name)); + d->LinkName = StoC(h->LinkName, sizeof(h->LinkName)); d->Mode = (mode_t)OtoL(h->Mode, sizeof(h->Mode)); d->Size = (size_t)OtoL(h->Size, sizeof(h->Size)); d->ModTime = (time_t)OtoL(h->ModificationTime @@ -267,6 +282,8 @@ symListPointer = symListBottom; } free(symListPointer); + free(h.Name); + free(h.LinkName); if ( status > 0 ) { /* Read partial header record */ errno = 0; /* Indicates broken tarfile */ return -1;
Attachment:
signature.asc
Description: This is a digitally signed message part