From: Frank Ch. Eigler Date: Tue, 16 Jan 2024 02:21:24 +0000 (-0500) Subject: PR31248: debuginfod_find_*: lseek to the front on returned fds X-Git-Tag: elfutils-0.191~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7554d41cd3784a321751c9ac430ad123f6c8cc1e;p=thirdparty%2Felfutils.git PR31248: debuginfod_find_*: lseek to the front on returned fds Previous code could return a fd that had its file-offset left at the place where libcurl last used it, namely at the end of the freshly downloaded file. Not good if a client just wants to read it right away! We now ensure (and document) that the fd is pointed to the beginning of the file. Signed-off-by: Frank Ch. Eigler --- diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c index dcf050316..0ee7db3d6 100644 --- a/debuginfod/debuginfod-client.c +++ b/debuginfod/debuginfod-client.c @@ -1771,6 +1771,8 @@ debuginfod_query_server (debuginfod_client *c, /* PR27571: make cache files casually unwriteable; dirs are already 0700 */ (void) fchmod(fd, 0400); + /* PR31248: lseek back to beginning */ + (void) lseek(fd, 0, SEEK_SET); /* rename tmp->real */ rc = rename (target_cache_tmppath, target_cache_path); diff --git a/doc/debuginfod_find_debuginfo.3 b/doc/debuginfod_find_debuginfo.3 index 6469a3dfb..0d553665f 100644 --- a/doc/debuginfod_find_debuginfo.3 +++ b/doc/debuginfod_find_debuginfo.3 @@ -133,8 +133,9 @@ use with all other calls. On error \fBNULL\fP will be returned and If a find family function is successful, the resulting file is saved to the client cache and a file descriptor to that file is returned. -The caller needs to \fBclose\fP() this descriptor. Otherwise, a -negative error code is returned. +The file descriptor points to the beginning of the file. The caller +needs to \fBclose\fP() this descriptor. Otherwise, a negative error +code is returned. .SH "OPTIONAL FUNCTIONS"