Skip to content

Commit 2fe36a5

Browse files
committed
audit: fix a race in the file timestamp
Before that the code was setting the timestamp of the file on the http server to the compressed file but never to the uncompressed one but to decide if a new version should be fetched pkg gets the mtime from the uncompressed file. Reported by: dvl
1 parent d1d9a3f commit 2fe36a5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

libpkg/pkg_audit.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ pkg_audit_fetch(const char *src, const char *dest)
201201
struct stat st;
202202
struct pkg_audit_extract_cbdata cbdata;
203203
int dfd = -1;
204+
struct timeval tm[2] = {
205+
{
206+
.tv_usec = 0
207+
},
208+
{
209+
.tv_usec = 0
210+
}
211+
};
204212

205213
if (src == NULL) {
206214
src = pkg_object_string(pkg_config_get("VULNXML_SITE"));
@@ -254,9 +262,13 @@ pkg_audit_fetch(const char *src, const char *dest)
254262
cbdata.fname = tmp;
255263
cbdata.out = outfd;
256264
cbdata.dest = dest;
265+
fstat(fd, &st);
257266

258267
/* Call sandboxed */
259268
retcode = pkg_emit_sandbox_call(pkg_audit_sandboxed_extract, fd, &cbdata);
269+
tm[0].tv_sec = st.st_mtim.tv_sec;
270+
tm[1].tv_sec = st.st_mtim.tv_sec;
271+
futimes(outfd, tm);
260272

261273
cleanup:
262274
unlink(tmp);

0 commit comments

Comments
 (0)