summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Ch. Eigler <fche@redhat.com>2024-01-15 21:21:24 -0500
committerFrank Ch. Eigler <fche@redhat.com>2024-01-16 16:44:57 -0500
commit7554d41cd3784a321751c9ac430ad123f6c8cc1e (patch)
treeb9ec83a77fe5d4981ec9e71cceeea86786fc18ad
parentc1058da5a450e33e72b72abb53bc3ffd7f6b361b (diff)
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 <fche@redhat.com>
-rw-r--r--debuginfod/debuginfod-client.c2
-rw-r--r--doc/debuginfod_find_debuginfo.35
2 files changed, 5 insertions, 2 deletions
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index dcf05031..0ee7db3d 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 6469a3df..0d553665 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"