46
46
size = archive_entry_size(entry);
48
fprintf(stderr, "Error: Empty control file within %s!\n", debfile);
51
if( size > 10*1024*1024 ) {
52
fprintf(stderr, "Error: Ridiculously long control file within %s!\n", debfile);
55
buffer = malloc(size+2);
48
fprintf(stderr, "Error: Empty control file within %s!\n",
52
if (size > 10*1024*1024) {
54
"Error: Ridiculously long control file within %s!\n",
58
buffer = malloc(size + 2);
59
if (FAILEDTOALLOC(buffer))
57
while( (got = archive_read_data(tar, buffer+len, ((size_t)size+1)-len)) > 0
62
while ((got = archive_read_data(tar, buffer+len, ((size_t)size+1)-len)) > 0
60
if( len > (size_t)size ) {
61
fprintf(stderr, "Internal Error: libarchive miscalculated length of the control file inside '%s',\n"
62
" perhaps the file is corrupt, perhaps libarchive!\n", debfile);
65
if (len > (size_t)size) {
67
"Internal Error: libarchive miscalculated length of the control file inside '%s',\n"
68
" perhaps the file is corrupt, perhaps libarchive!\n", debfile);
69
75
return RET_ERROR_INTERRUPTED;
73
fprintf(stderr, "Error reading control file from %s\n", debfile);
79
fprintf(stderr, "Error reading control file from %s\n",
76
if( len < (size_t)size )
77
fprintf(stderr, "Warning: libarchive miscalculated length of the control file inside '%s'.\n"
78
"Maybe the file is corrupt, perhaps libarchive!\n", debfile);
83
if (len < (size_t)size)
85
"Warning: libarchive miscalculated length of the control file inside '%s'.\n"
86
"Maybe the file is corrupt, perhaps libarchive!\n", debfile);
79
87
buffer[len] = '\0';
81
89
controllen = chunk_extract(buffer, buffer, &afterchanges);
83
if( controllen == 0 ) {
84
fprintf(stderr,"Could only find spaces within control file of '%s'!\n",
91
if (controllen == 0) {
93
"Could only find spaces within control file of '%s'!\n",
89
if( (size_t)(afterchanges - buffer) < len ) {
90
if( *afterchanges == '\0' )
98
if ((size_t)(afterchanges - buffer) < len) {
99
if (*afterchanges == '\0')
92
101
"Unexpected \\0 character within control file of '%s'!\n", debfile);
117
126
ar_archivemember_open,
118
127
ar_archivemember_read,
119
128
ar_archivemember_close);
120
if( a != ARCHIVE_OK ) {
121
fprintf(stderr,"open control.tar.gz within '%s' failed: %d:%d:%s\n",
129
if (a != ARCHIVE_OK) {
131
"open control.tar.gz within '%s' failed: %d:%d:%s\n",
123
a,archive_errno(tar),
133
a, archive_errno(tar),
124
134
archive_error_string(tar));
125
135
return RET_ERROR;
127
while( (a=archive_read_next_header(tar, &entry)) == ARCHIVE_OK ) {
128
if( strcmp(archive_entry_pathname(entry),"./control") != 0 &&
129
strcmp(archive_entry_pathname(entry),"control") != 0 ) {
137
while ((a=archive_read_next_header(tar, &entry)) == ARCHIVE_OK) {
138
if (strcmp(archive_entry_pathname(entry), "./control") != 0 &&
139
strcmp(archive_entry_pathname(entry), "control") != 0) {
130
140
a = archive_read_data_skip(tar);
131
if( a != ARCHIVE_OK ) {
141
if (a != ARCHIVE_OK) {
132
142
int e = archive_errno(tar);
133
printf("Error skipping %s within data.tar.gz from %s: %d=%s\n",
144
"Error skipping %s within data.tar.gz from %s: %d=%s\n",
134
145
archive_entry_pathname(entry),
136
147
e, archive_error_string(tar));
137
148
return (e!=0)?(RET_ERRNO(e)):RET_ERROR;
140
151
return RET_ERROR_INTERRUPTED;
142
153
r = read_control_file(control, debfile, tar, entry);
143
if( r != RET_NOTHING )
154
if (r != RET_NOTHING)
147
if( a != ARCHIVE_EOF ) {
158
if (a != ARCHIVE_EOF) {
148
159
int e = archive_errno(tar);
149
160
printf("Error reading control.tar.gz from %s: %d=%s\n",
151
162
e, archive_error_string(tar));
152
163
return (e!=0)?(RET_ERRNO(e)):RET_ERROR;
154
fprintf(stderr,"Could not find a control file within control.tar.gz within '%s'!\n",debfile);
166
"Could not find a control file within control.tar.gz within '%s'!\n",
155
168
return RET_ERROR_MISSING;
158
retvalue extractcontrol(char **control,const char *debfile) {
171
retvalue extractcontrol(char **control, const char *debfile) {
159
172
struct ar_archive *ar;
161
174
bool hadcandidate = false;
163
r = ar_open(&ar,debfile);
164
if( RET_WAS_ERROR(r) )
176
r = ar_open(&ar, debfile);
177
if (RET_WAS_ERROR(r))
166
assert( r != RET_NOTHING);
179
assert (r != RET_NOTHING);
169
182
enum compression c;
171
184
r = ar_nextmember(ar, &filename);
173
if( strncmp(filename, "control.tar", 11) != 0 ) {
186
if (strncmp(filename, "control.tar", 11) != 0) {
177
190
hadcandidate = true;
178
for( c = 0 ; c < c_COUNT ; c++ ) {
179
if( strcmp(filename + 11,
191
for (c = 0 ; c < c_COUNT ; c++) {
192
if (strcmp(filename + 11,
180
193
uncompression_suffix[c]) == 0)
187
200
ar_archivemember_setcompression(ar, c);
188
if( uncompression_supported(c) ) {
201
if (uncompression_supported(c)) {
189
202
struct archive *tar;
191
204
tar = archive_read_new();
192
205
r = read_control_tar(control, debfile, ar, tar);
193
206
// TODO run archive_read_close to get error messages?
194
207
archive_read_finish(tar);
195
if( r != RET_NOTHING ) {
208
if (r != RET_NOTHING) {