BUG: fix for bug 5837, libtar and long path names

This commit is contained in:
Bill Hoffman 2007-12-17 17:50:55 -05:00
parent c6089d1642
commit c391c5cbf4
1 changed files with 3 additions and 3 deletions

View File

@ -93,16 +93,16 @@ th_set_path(TAR *t, char *pathname)
if (pathname[strlen(pathname) - 1] != '/' && TH_ISDIR(t)) if (pathname[strlen(pathname) - 1] != '/' && TH_ISDIR(t))
strcpy(suffix, "/"); strcpy(suffix, "/");
if (strlen(pathname) > T_NAMELEN && (t->options & TAR_GNU)) if (strlen(pathname)+strlen(suffix) >= T_NAMELEN && (t->options & TAR_GNU))
{ {
/* GNU-style long name */ /* GNU-style long name */
t->th_buf.gnu_longname = strdup(pathname); t->th_buf.gnu_longname = strdup(pathname);
strncpy(t->th_buf.name, t->th_buf.gnu_longname, T_NAMELEN); strncpy(t->th_buf.name, t->th_buf.gnu_longname, T_NAMELEN);
} }
else if (strlen(pathname) > T_NAMELEN) else if (strlen(pathname)+ strlen(suffix) >= T_NAMELEN)
{ {
/* POSIX-style prefix field */ /* POSIX-style prefix field */
tmp = strchr(&(pathname[strlen(pathname) - T_NAMELEN - 1]), '/'); tmp = strrchr(pathname, '/');
if (tmp == NULL) if (tmp == NULL)
{ {
printf("!!! '/' not found in \"%s\"\n", pathname); printf("!!! '/' not found in \"%s\"\n", pathname);