]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
PR31248: debuginfod_find_*: lseek to the front on returned fds
authorFrank Ch. Eigler <fche@redhat.com>
Tue, 16 Jan 2024 02:21:24 +0000 (21:21 -0500)
committerFrank Ch. Eigler <fche@redhat.com>
Tue, 16 Jan 2024 21:44:57 +0000 (16:44 -0500)
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>
debuginfod/debuginfod-client.c
doc/debuginfod_find_debuginfo.3

index dcf0503163fd73e126a2197d278f363fd6839810..0ee7db3d66380899fc628efda7f339db7b8d6b9c 100644 (file)
@@ -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);
index 6469a3dfb2db7a606d889642232921f27a18b763..0d553665f42bcb8143e89bd18cfee131f5a58a5a 100644 (file)
@@ -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"