]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-fdio: Fix lseek relative from file end
authorAndrei Tatar <andrei@unikraft.io>
Tue, 18 Mar 2025 16:43:38 +0000 (17:43 +0100)
committerUnikraft Bot <monkey@unikraft.io>
Thu, 27 Mar 2025 17:23:26 +0000 (17:23 +0000)
This change fixes a bug in lseek where the file cursor was always set to
the end of file on SEEK_END, ignoring any passed-in offset.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1602

lib/posix-fdio/fdio.c

index 0d4b50b5cc514fcefe72b0280a1ccedec14b74e2..ea07b64803795f4a656ff4efe40bef9ef02470e2 100644 (file)
@@ -417,12 +417,17 @@ off_t uk_sys_lseek(struct uk_ofile *of, off_t offset, int whence)
        _of_lock(of);
        if (whence == SEEK_END) {
                const struct uk_file *f = of->file;
+               ssize_t eof;
 
                if (iolock)
                        uk_file_rlock(f);
-               offset = fdio_get_eof(f);
+               eof = fdio_get_eof(f);
                if (iolock)
                        uk_file_runlock(f);
+               if (eof >= 0)
+                       offset += eof;
+               else
+                       offset = eof;
        } else if (whence == SEEK_CUR) {
                offset += of->pos;
        }