commit: ea5396ffa7b6af401a75c090347204227a737cfe
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 26 17:18:30 2026 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Jan 26 17:18:30 2026 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=ea5396ff
q: ensure fstat succeeds before using its result, CID 557235
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
q.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/q.c b/q.c
index 546afefc..a694f0b6 100644
--- a/q.c
+++ b/q.c
@@ -918,18 +918,20 @@ int q_main(int argc, char **argv)
archive_write_free(qcctx.archive);
/* now we got the size, put it in the main archive */
- fstat(tfd, &st);
- entry = archive_entry_new();
- archive_entry_set_pathname(entry, "repo.tar.zst");
- archive_entry_set_size(entry, st.st_size);
- archive_entry_set_mtime(entry, qcctx.buildtime, 0);
- archive_entry_set_filetype(entry, AE_IFREG);
- archive_entry_set_perm(entry, 0644);
- archive_write_header(a, entry);
- lseek(tfd, 0, SEEK_SET); /* reposition at the start of
file */
- while ((rlen = read(tfd, buf, sizeof(buf))) > 0)
- archive_write_data(a, buf, rlen);
- archive_entry_free(entry);
+ if (fstat(tfd, &st) >= 0)
+ {
+ entry = archive_entry_new();
+ archive_entry_set_pathname(entry,
"repo.tar.zst");
+ archive_entry_set_size(entry, st.st_size);
+ archive_entry_set_mtime(entry, qcctx.buildtime,
0);
+ archive_entry_set_filetype(entry, AE_IFREG);
+ archive_entry_set_perm(entry, 0644);
+ archive_write_header(a, entry);
+ lseek(tfd, 0, SEEK_SET); /* reposition at the
start of file */
+ while ((rlen = read(tfd, buf, sizeof(buf))) > 0)
+ archive_write_data(a, buf, rlen);
+ archive_entry_free(entry);
+ }
/* TODO: compute and put .sig in here */