Skip to content

Commit 47c66ee

Browse files
committed
lib: pedantically check archive_entry_pathname return values
Fixes: #688
1 parent 3b5c83c commit 47c66ee

6 files changed

Lines changed: 37 additions & 7 deletions

File tree

lib/archive.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ xbps_archive_get_file(struct archive *ar, struct archive_entry *entry)
6565
for (;;) {
6666
ssize_t rd = archive_read_data(ar, buf + used, len - used);
6767
if (rd == ARCHIVE_FATAL || rd == ARCHIVE_WARN) {
68+
const char *pname = archive_entry_pathname(entry);
69+
if (!pname)
70+
xbps_unreachable();
6871
r = -xbps_archive_errno(ar);
6972
xbps_error_printf(
7073
"failed to read archive entry: %s: %s\n",
71-
archive_entry_pathname(entry),
72-
archive_error_string(ar));
74+
pname, archive_error_string(ar));
7375
goto err;
7476
} else if (rd == ARCHIVE_RETRY) {
7577
continue;
@@ -79,11 +81,13 @@ xbps_archive_get_file(struct archive *ar, struct archive_entry *entry)
7981
break;
8082
}
8183
if (used < len) {
84+
const char *pname = archive_entry_pathname(entry);
85+
if (!pname)
86+
xbps_unreachable();
8287
r = -EIO;
8388
xbps_error_printf(
8489
"failed to read archive entry: %s: could not read enough "
85-
"data: %s\n",
86-
archive_entry_pathname(entry), strerror(-r));
90+
"data: %s\n", pname, strerror(-r));
8791
goto err;
8892
}
8993

lib/package_unpack.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ unpack_archive(struct xbps_handle *xhp,
163163
break;
164164

165165
entry_pname = archive_entry_pathname(entry);
166+
if (!entry_pname)
167+
xbps_unreachable();
166168

167169
if (strcmp("./INSTALL", entry_pname) == 0 ||
168170
strcmp("./REMOVE", entry_pname) == 0 ||
@@ -215,6 +217,8 @@ unpack_archive(struct xbps_handle *xhp,
215217
continue;
216218

217219
entry_pname = archive_entry_pathname(entry);
220+
if (!entry_pname)
221+
xbps_unreachable();
218222
entry_size = archive_entry_size(entry);
219223
entry_type = archive_entry_filetype(entry);
220224
entry_statp = archive_entry_stat(entry);
@@ -407,6 +411,8 @@ unpack_archive(struct xbps_handle *xhp,
407411
* has been changed it will become a dangling pointer.
408412
*/
409413
entry_pname = archive_entry_pathname(entry);
414+
if (!entry_pname)
415+
xbps_unreachable();
410416
/*
411417
* Extract entry from archive.
412418
*/

lib/plist_fetch.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ xbps_archive_fetch_file(const char *url, const char *fname)
8989
const char *bfile;
9090

9191
bfile = archive_entry_pathname(entry);
92+
if (!bfile)
93+
xbps_unreachable();
9294
if (bfile[0] == '.')
9395
bfile++; /* skip first dot */
9496

@@ -139,6 +141,8 @@ xbps_archive_fetch_file_into_fd(const char *url, const char *fname, int fd)
139141
break;
140142
}
141143
bfile = archive_entry_pathname(entry);
144+
if (!bfile)
145+
xbps_unreachable();
142146
if (bfile[0] == '.')
143147
bfile++; /* skip first dot */
144148

lib/repo.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ static int
121121
repo_read_index(struct xbps_repo *repo, struct archive *ar)
122122
{
123123
struct archive_entry *entry;
124+
const char *pname;
124125
char *buf;
125126
int r;
126127

@@ -129,7 +130,10 @@ repo_read_index(struct xbps_repo *repo, struct archive *ar)
129130
return r;
130131

131132
/* index.plist */
132-
if (strcmp(archive_entry_pathname(entry), XBPS_REPODATA_INDEX) != 0) {
133+
pname = archive_entry_pathname(entry);
134+
if (!pname)
135+
xbps_unreachable();
136+
if (strcmp(pname, XBPS_REPODATA_INDEX) != 0) {
133137
xbps_error_printf("failed to read repository index: %s: unexpected archive entry\n",
134138
repo->uri);
135139
r = -EINVAL;
@@ -175,14 +179,18 @@ static int
175179
repo_read_meta(struct xbps_repo *repo, struct archive *ar)
176180
{
177181
struct archive_entry *entry;
182+
const char *pname;
178183
char *buf;
179184
int r;
180185

181186
r = repo_read_next(repo, ar, &entry);
182187
if (r < 0)
183188
return r;
184189

185-
if (strcmp(archive_entry_pathname(entry), XBPS_REPODATA_META) != 0) {
190+
pname = archive_entry_pathname(entry);
191+
if (!pname)
192+
xbps_unreachable();
193+
if (strcmp(pname, XBPS_REPODATA_META) != 0) {
186194
xbps_error_printf("failed to read repository metadata: %s: unexpected archive entry\n",
187195
repo->uri);
188196
r = -EINVAL;
@@ -237,6 +245,7 @@ static int
237245
repo_read_stage(struct xbps_repo *repo, struct archive *ar)
238246
{
239247
struct archive_entry *entry;
248+
const char *pname;
240249
int r;
241250

242251
r = repo_read_next(repo, ar, &entry);
@@ -249,7 +258,10 @@ repo_read_stage(struct xbps_repo *repo, struct archive *ar)
249258
return r;
250259
}
251260

252-
if (strcmp(archive_entry_pathname(entry), XBPS_REPODATA_STAGE) != 0) {
261+
pname = archive_entry_pathname(entry);
262+
if (!pname)
263+
xbps_unreachable();
264+
if (strcmp(pname, XBPS_REPODATA_STAGE) != 0) {
253265
xbps_error_printf("failed to read repository stage: %s: unexpected archive entry\n",
254266
repo->uri);
255267
r = -EINVAL;

lib/transaction_files.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,8 @@ collect_binpkg_files(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod,
736736
continue;
737737

738738
entry_pname = archive_entry_pathname(entry);
739+
if (!entry_pname)
740+
xbps_unreachable();
739741
if ((strcmp("./files.plist", entry_pname)) == 0) {
740742
filesd = xbps_archive_get_dictionary(ar, entry);
741743
if (filesd == NULL) {

lib/transaction_internalize.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ internalize_binpkg(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
140140
continue;
141141

142142
entry_pname = archive_entry_pathname(entry);
143+
if (!entry_pname)
144+
xbps_unreachable();
143145

144146
if (strcmp("./INSTALL", entry_pname) == 0) {
145147
rv = internalize_script(pkg_repod, "install-script", ar, entry);

0 commit comments

Comments
 (0)