From f6c704837da8d5781c4938a94a89b9239231548f Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Thu, 22 Dec 2011 17:08:28 -0500 Subject: [PATCH] Fixed truncation check, so 100 char names get GNU extension support when enabled Reported by Barrie Walker as follows: I've experienced a problem with 1.2.11 where a name or link is exactly 100 characters. When not using TAR_GNU name/linknames longer than 99 characters are simply truncated to 99 characters (+1 for the NUL makes T_NAMELEN (= 100)). Any overflow is lost - fair enough. Using TAR_GNU, name/linknames longer than 99 characters are still truncated to 99 characters but the full string is placed in the gnu_longname/gnu_longlink fields. However the gnu_longname/gnu_longlink fields are populated only when a name/linkname would be truncated. The bug is that the check to see whether there will be truncation compares the length against T_NAMELEN rather than T_NAMELEN-1. The fix is simply, in lines 85 and 123 of encode.c, to change T_NAMELEN to T_NAMELEN-1. --- lib/encode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/encode.c b/lib/encode.c index 13b3ed0..a1f07a6 100644 --- a/lib/encode.c +++ b/lib/encode.c @@ -82,7 +82,7 @@ th_set_path(TAR *t, char *pathname) if (pathname[strlen(pathname) - 1] != '/' && TH_ISDIR(t)) strcpy(suffix, "/"); - if (strlen(pathname) > T_NAMELEN && (t->options & TAR_GNU)) + if (strlen(pathname) > T_NAMELEN-1 && (t->options & TAR_GNU)) { /* GNU-style long name */ t->th_buf.gnu_longname = strdup(pathname); @@ -120,7 +120,7 @@ th_set_link(TAR *t, char *linkname) printf("==> th_set_link(th, linkname=\"%s\")\n", linkname); #endif - if (strlen(linkname) > T_NAMELEN && (t->options & TAR_GNU)) + if (strlen(linkname) > T_NAMELEN-1 && (t->options & TAR_GNU)) { /* GNU longlink format */ t->th_buf.gnu_longlink = strdup(linkname); -- 2.11.4.GIT