Preparation so that we can grow fname to accommodate large file names.
---
 tar.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tar.c b/tar.c
index fb7e7ab..934b9c6 100644
--- a/tar.c
+++ b/tar.c
@@ -445,13 +445,15 @@ bad:
 static void
 xt(int argc, char *argv[], int mode)
 {
-       char b[BLKSIZ], fname[256 + 1], *p;
+       char b[BLKSIZ], *p;
        struct timespec times[2];
        struct header *h = (struct header *)b;
        struct dirtime *dirtime;
        long size;
        int i, n;
        int (*fn)(char *, ssize_t, char[BLKSIZ]) = (mode == 'x') ? unarchive : 
print;
+       long fnmax = 256 + 1;
+       char *fname = ecalloc(1, fnmax);
 
        while (eread(tarfd, b, BLKSIZ) > 0 && h->name[0]) {
                chktar(h);
@@ -470,9 +472,9 @@ xt(int argc, char *argv[], int mode)
                
                /* small dance around non-null terminated fields */
                if (h->prefix[0])
-                       n = snprintf(fname, sizeof(fname), "%.*s/",
+                       n = snprintf(fname, fnmax, "%.*s/",
                                     (int)sizeof(h->prefix), h->prefix);
-               snprintf(fname + n, sizeof(fname) - n, "%.*s",
+               snprintf(fname + n, fnmax - n, "%.*s",
                         (int)sizeof(h->name), h->name);
                
                if (argc) {
@@ -490,6 +492,7 @@ xt(int argc, char *argv[], int mode)
                if (vflag && mode != 't')
                        puts(fname);
        }
+       free(fname);
        
        if (mode == 'x' && !mflag) {
                while ((dirtime = popdirtime())) {
-- 
2.28.0


Reply via email to