1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
From ec3fd37495e977af375a98a472d19ae0ccbcd874 Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
Date: Sat, 3 Dec 2016 20:49:24 -0800
Subject: [PATCH] pax: Fix GNU long name handling with short read
---
bin/pax/ar_subs.c | 66 +++++++++++++++++++++++++++++++++------------
bin/pax/buf_subs.c | 4 +--
bin/pax/file_subs.c | 25 +----------------
3 files changed, 51 insertions(+), 44 deletions(-)
diff --git a/bin/pax/ar_subs.c b/bin/pax/ar_subs.c
index e5b0a4ee5d1..f0a55abe2f7 100644
--- a/bin/pax/ar_subs.c
+++ b/bin/pax/ar_subs.c
@@ -37,6 +37,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
@@ -51,6 +52,7 @@
static void wr_archive(ARCHD *, int is_app);
static int get_arc(void);
static int next_head(ARCHD *);
+static int rd_gnu_string(ARCHD *);
extern sigset_t s_mask;
/*
@@ -93,16 +95,8 @@ list(void)
* step through the archive until the format says it is done
*/
while (next_head(arcn) == 0) {
- if (arcn->type == PAX_GLL || arcn->type == PAX_GLF) {
- /*
- * we need to read, to get the real filename
- */
- off_t cnt;
- if (!rd_wrfile(arcn, arcn->type == PAX_GLF
- ? -1 : -2, &cnt))
- (void)rd_skip(cnt + arcn->pad);
+ if (rd_gnu_string(arcn))
continue;
- }
/*
* check for pattern, and user specified options match.
@@ -208,15 +202,8 @@ extract(void)
* says it is done
*/
while (next_head(arcn) == 0) {
- if (arcn->type == PAX_GLL || arcn->type == PAX_GLF) {
- /*
- * we need to read, to get the real filename
- */
- if (!rd_wrfile(arcn, arcn->type == PAX_GLF
- ? -1 : -2, &cnt))
- (void)rd_skip(cnt + arcn->pad);
+ if (rd_gnu_string(arcn))
continue;
- }
/*
* check for pattern, and user specified options match. When
@@ -1243,3 +1230,48 @@ get_arc(void)
paxwarn(1, "Sorry, unable to determine archive format.");
return(-1);
}
+
+/*
+ * rd_gnu_string()
+ * Read the file contents into an allocated string if it is a GNU tar
+ * long link/file.
+ * Return:
+ * 1 if gnu string read, 0 otherwise
+ */
+
+static int
+rd_gnu_string(ARCHD *arcn)
+{
+ char **strp;
+
+ switch (arcn->type) {
+ case PAX_GLF:
+ strp = &gnu_name_string;
+ break;
+ case PAX_GLL:
+ strp = &gnu_link_string;
+ break;
+ default:
+ strp = NULL;
+ break;
+ }
+ if (!strp)
+ return 0;
+ /*
+ * we need to read, to get the real filename
+ */
+ if (*strp)
+ err(1, "WARNING! Major Internal Error! GNU hack Failing!");
+ *strp = malloc(arcn->sb.st_size + 1);
+ if (*strp == NULL) {
+ paxwarn(1, "Out of memory");
+ (void)rd_skip(arcn->skip + arcn->pad);
+ } else if (rd_wrbuf(*strp, arcn->sb.st_size) < arcn->sb.st_size) {
+ free(*strp);
+ *strp = NULL;
+ } else {
+ (*strp)[arcn->sb.st_size] = '\0';
+ (void)rd_skip(arcn->pad);
+ }
+ return 1;
+}
diff --git a/bin/pax/buf_subs.c b/bin/pax/buf_subs.c
index 68534dcbe25..e84f9e0d3d6 100644
--- a/bin/pax/buf_subs.c
+++ b/bin/pax/buf_subs.c
@@ -673,9 +673,7 @@ rd_wrfile(ARCHD *arcn, int ofd, off_t *left)
* pass the blocksize of the file being written to the write routine,
* if the size is zero, use the default MINFBSZ
*/
- if (ofd < 0)
- sz = PAXPATHLEN + 1; /* GNU tar long link/file */
- else if (fstat(ofd, &sb) == 0) {
+ if (fstat(ofd, &sb) == 0) {
if (sb.st_blksize > 0)
sz = (int)sb.st_blksize;
} else
diff --git a/bin/pax/file_subs.c b/bin/pax/file_subs.c
index 89b4872988b..8aa3d249923 100644
--- a/bin/pax/file_subs.c
+++ b/bin/pax/file_subs.c
@@ -919,7 +919,6 @@ file_write(int fd, char *str, int cnt, int *rem, int *isempt, int sz,
char *end;
int wcnt;
char *st = str;
- char **strp;
/*
* while we have data to process
@@ -978,29 +977,7 @@ file_write(int fd, char *str, int cnt, int *rem, int *isempt, int sz,
/*
* have non-zero data in this file system block, have to write
*/
- switch (fd) {
- case -1:
- strp = &gnu_name_string;
- break;
- case -2:
- strp = &gnu_link_string;
- break;
- default:
- strp = NULL;
- break;
- }
- if (strp) {
- if (*strp)
- err(1, "WARNING! Major Internal Error! GNU hack Failing!");
- *strp = malloc(wcnt + 1);
- if (*strp == NULL) {
- paxwarn(1, "Out of memory");
- return(-1);
- }
- memcpy(*strp, st, wcnt);
- (*strp)[wcnt] = '\0';
- break;
- } else if (write(fd, st, wcnt) != wcnt) {
+ if (write(fd, st, wcnt) != wcnt) {
syswarn(1, errno, "Failed write to file %s", name);
return(-1);
}
--
2.26.2
|