~ubuntu-branches/ubuntu/raring/reprepro/raring

« back to all changes in this revision

Viewing changes to debfile.c

  • Committer: Bazaar Package Importer
  • Author(s): Bernhard R. Link
  • Date: 2011-05-05 16:34:23 UTC
  • mfrom: (21.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110505163423-x49kbdijyoubai4x
Tags: 4.6.0-1
* new release
- general cleanup
- new FilterSrcList
* increase Standards-Version, no changes needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
        ssize_t got;
45
45
 
46
46
        size = archive_entry_size(entry);
47
 
        if( size <= 0 ) {
48
 
                fprintf(stderr, "Error: Empty control file within %s!\n", debfile);
49
 
                return RET_ERROR;
50
 
        }
51
 
        if( size > 10*1024*1024 ) {
52
 
                fprintf(stderr, "Error: Ridiculously long control file within %s!\n", debfile);
53
 
                return RET_ERROR;
54
 
        }
55
 
        buffer = malloc(size+2);
 
47
        if (size <= 0) {
 
48
                fprintf(stderr, "Error: Empty control file within %s!\n",
 
49
                                debfile);
 
50
                return RET_ERROR;
 
51
        }
 
52
        if (size > 10*1024*1024) {
 
53
                fprintf(stderr,
 
54
"Error: Ridiculously long control file within %s!\n",
 
55
                                debfile);
 
56
                return RET_ERROR;
 
57
        }
 
58
        buffer = malloc(size + 2);
 
59
        if (FAILEDTOALLOC(buffer))
 
60
                return RET_ERROR_OOM;
56
61
        len = 0;
57
 
        while( (got = archive_read_data(tar, buffer+len, ((size_t)size+1)-len)) > 0
58
 
                        && !interrupted() ) {
 
62
        while ((got = archive_read_data(tar, buffer+len, ((size_t)size+1)-len)) > 0
 
63
                        && !interrupted()) {
59
64
                len += got;
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) {
 
66
                        fprintf(stderr,
 
67
"Internal Error: libarchive miscalculated length of the control file inside '%s',\n"
 
68
" perhaps the file is corrupt, perhaps libarchive!\n", debfile);
63
69
                        free(buffer);
64
70
                        return RET_ERROR;
65
71
                }
66
72
        }
67
 
        if( interrupted() ) {
 
73
        if (interrupted()) {
68
74
                free(buffer);
69
75
                return RET_ERROR_INTERRUPTED;
70
76
        }
71
 
        if( got < 0 ) {
 
77
        if (got < 0) {
72
78
                free(buffer);
73
 
                fprintf(stderr, "Error reading control file from %s\n", debfile);
 
79
                fprintf(stderr, "Error reading control file from %s\n",
 
80
                                debfile);
74
81
                return RET_ERROR;
75
82
        }
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)
 
84
                fprintf(stderr,
 
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';
80
88
 
81
89
        controllen = chunk_extract(buffer, buffer, &afterchanges);
82
90
 
83
 
        if( controllen == 0 ) {
84
 
                fprintf(stderr,"Could only find spaces within control file of '%s'!\n",
 
91
        if (controllen == 0) {
 
92
                fprintf(stderr,
 
93
"Could only find spaces within control file of '%s'!\n",
85
94
                                debfile);
86
95
                free(buffer);
87
96
                return RET_ERROR;
88
97
        }
89
 
        if( (size_t)(afterchanges - buffer) < len ) {
90
 
                if( *afterchanges == '\0' )
 
98
        if ((size_t)(afterchanges - buffer) < len) {
 
99
                if (*afterchanges == '\0')
91
100
                        fprintf(stderr,
92
101
"Unexpected \\0 character within control file of '%s'!\n", debfile);
93
102
                else
96
105
                free(buffer);
97
106
                return RET_ERROR;
98
107
        }
99
 
        assert( buffer[controllen] == '\0' );
 
108
        assert (buffer[controllen] == '\0');
100
109
        n = realloc(buffer, controllen+1);
101
 
        if( n == NULL ) {
 
110
        if (FAILEDTOALLOC(n)) {
102
111
                free(buffer);
103
112
                return RET_ERROR_OOM;
104
113
        }
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) {
 
130
                fprintf(stderr,
 
131
"open control.tar.gz within '%s' failed: %d:%d:%s\n",
122
132
                                debfile,
123
 
                                a,archive_errno(tar),
 
133
                                a, archive_errno(tar),
124
134
                                archive_error_string(tar));
125
135
                return RET_ERROR;
126
136
        }
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",
 
143
                                printf(
 
144
"Error skipping %s within data.tar.gz from %s: %d=%s\n",
134
145
                                                archive_entry_pathname(entry),
135
146
                                                debfile,
136
147
                                                e, archive_error_string(tar));
137
148
                                return (e!=0)?(RET_ERRNO(e)):RET_ERROR;
138
149
                        }
139
 
                        if( interrupted() )
 
150
                        if (interrupted())
140
151
                                return RET_ERROR_INTERRUPTED;
141
152
                } else {
142
153
                        r = read_control_file(control, debfile, tar, entry);
143
 
                        if( r != RET_NOTHING )
 
154
                        if (r != RET_NOTHING)
144
155
                                return r;
145
156
                }
146
157
        }
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",
150
161
                                debfile,
151
162
                                e, archive_error_string(tar));
152
163
                return (e!=0)?(RET_ERRNO(e)):RET_ERROR;
153
164
        }
154
 
        fprintf(stderr,"Could not find a control file within control.tar.gz within '%s'!\n",debfile);
 
165
        fprintf(stderr,
 
166
"Could not find a control file within control.tar.gz within '%s'!\n",
 
167
                        debfile);
155
168
        return RET_ERROR_MISSING;
156
169
}
157
170
 
158
 
retvalue extractcontrol(char **control,const char *debfile) {
 
171
retvalue extractcontrol(char **control, const char *debfile) {
159
172
        struct ar_archive *ar;
160
173
        retvalue r;
161
174
        bool hadcandidate = false;
162
175
 
163
 
        r = ar_open(&ar,debfile);
164
 
        if( RET_WAS_ERROR(r) )
 
176
        r = ar_open(&ar, debfile);
 
177
        if (RET_WAS_ERROR(r))
165
178
                return r;
166
 
        assert( r != RET_NOTHING);
 
179
        assert (r != RET_NOTHING);
167
180
        do {
168
181
                char *filename;
169
182
                enum compression c;
170
183
 
171
184
                r = ar_nextmember(ar, &filename);
172
 
                if( RET_IS_OK(r) ) {
173
 
                        if( strncmp(filename, "control.tar", 11) != 0 ) {
 
185
                if (RET_IS_OK(r)) {
 
186
                        if (strncmp(filename, "control.tar", 11) != 0) {
174
187
                                free(filename);
175
188
                                continue;
176
189
                        }
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)
181
194
                                        break;
182
195
                        }
183
 
                        if( c >= c_COUNT ) {
 
196
                        if (c >= c_COUNT) {
184
197
                                free(filename);
185
198
                                continue;
186
199
                        }
187
200
                        ar_archivemember_setcompression(ar, c);
188
 
                        if( uncompression_supported(c) ) {
 
201
                        if (uncompression_supported(c)) {
189
202
                                struct archive *tar;
190
203
 
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) {
196
209
                                        ar_close(ar);
197
210
                                        free(filename);
198
211
                                        return r;
201
214
                        }
202
215
                        free(filename);
203
216
                }
204
 
        } while( RET_IS_OK(r) );
 
217
        } while (RET_IS_OK(r));
205
218
        ar_close(ar);
206
 
        if( hadcandidate )
 
219
        if (hadcandidate)
207
220
                fprintf(stderr,
208
221
"Could not find a suitable control.tar file within '%s'!\n", debfile);
209
222
        else