]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: fix lseek() parameter order 39715/head
authorLennart Poettering <lennart@poettering.net>
Thu, 13 Nov 2025 13:15:33 +0000 (14:15 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 13 Nov 2025 13:19:29 +0000 (14:19 +0100)
The offset must be specified first, 'whence' second. Fix that.

Except for one case this fix doesn't actually fix any real bug, since
SEEK_SET is defined as 0 anyway, hence the swapped arguments have no
effect.

The one exception is the MTD smartmedia code, which I guess indicates
that noone has been using that hw anymore in a long time?

src/home/homed-home.c
src/import/pull-raw.c
src/login/logind-seat.c
src/test/test-copy.c
src/test/test-process-util.c
src/udev/mtd_probe/probe_smartmedia.c

index a359baea591070c054c8bb42b2a30178c6a05446..e4f3487473a3ce5b8a9b9f76e802a979e2c8a348 100644 (file)
@@ -570,7 +570,7 @@ static int home_parse_worker_stdout(int _fd, UserRecord **ret) {
                 return 0;
         }
 
-        if (lseek(fd, SEEK_SET, 0) < 0)
+        if (lseek(fd, 0, SEEK_SET) < 0)
                 return log_error_errno(errno, "Failed to seek to beginning of memfd: %m");
 
         f = take_fdopen(&fd, "r");
index 80ef38f50a6f4763bc403346fa8a40210e4b3cf9..01a810a9b8c80c911b1107e02117bba919b9311b 100644 (file)
@@ -365,7 +365,7 @@ static int raw_pull_make_local_copy(RawPull *i) {
                 assert(i->raw_job->disk_fd >= 0);
                 assert(i->offset == UINT64_MAX);
 
-                if (lseek(i->raw_job->disk_fd, SEEK_SET, 0) < 0)
+                if (lseek(i->raw_job->disk_fd, 0, SEEK_SET) < 0)
                         return log_error_errno(errno, "Failed to seek to beginning of vendor image: %m");
         }
 
index d30cc6974f451761d9af3ea2101143977a8039e3..3a3148be14fc8b761e6920f60459e675ea40261d 100644 (file)
@@ -570,8 +570,8 @@ int seat_read_active_vt(Seat *s) {
         if (!seat_has_vts(s))
                 return 0;
 
-        if (lseek(s->manager->console_active_fd, SEEK_SET, 0) < 0)
-                return log_error_errno(errno, "lseek on console_active_fd failed: %m");
+        if (lseek(s->manager->console_active_fd, 0, SEEK_SET) < 0)
+                return log_error_errno(errno, "lseek() on console_active_fd failed: %m");
 
         errno = 0;
         k = read(s->manager->console_active_fd, t, sizeof(t)-1);
index 86de5c4b633b196f8b692e4b5f8b51510f0cd3d6..58797b5926c53374617e15656861ba4dda00f0d1 100644 (file)
@@ -124,7 +124,7 @@ TEST(copy_file_fd) {
         assert_se(write_string_file(in_fn, text, WRITE_STRING_FILE_CREATE) == 0);
         assert_se(copy_file_fd("/a/file/which/does/not/exist/i/guess", out_fd, COPY_REFLINK) < 0);
         assert_se(copy_file_fd(in_fn, out_fd, COPY_REFLINK) >= 0);
-        assert_se(lseek(out_fd, SEEK_SET, 0) == 0);
+        assert_se(lseek(out_fd, 0, SEEK_SET) == 0);
 
         assert_se(read(out_fd, buf, sizeof buf) == (ssize_t) strlen(text));
         ASSERT_STREQ(buf, text);
index 5723f2a07416386e04296ede51d83268dbb0eafd..b79784533442ea9962b186d25f5c32815f79d5fa 100644 (file)
@@ -525,7 +525,7 @@ TEST(pid_get_cmdline_harder) {
 #define EXPECT1p "foo $'\\'bar\\'' $'\"bar$\"' $'x y z' $'!``'"
 #define EXPECT1v STRV_MAKE("foo", "'bar'", "\"bar$\"", "x y z", "!``")
 
-        ASSERT_OK_ZERO_ERRNO(lseek(fd, SEEK_SET, 0));
+        ASSERT_OK_ZERO_ERRNO(lseek(fd, 0, SEEK_SET));
         ASSERT_OK_EQ_ERRNO(write(fd, CMDLINE1, sizeof(CMDLINE1)), (ssize_t) sizeof(CMDLINE1));
         ASSERT_OK_ZERO_ERRNO(ftruncate(fd, sizeof(CMDLINE1)));
 
@@ -550,7 +550,7 @@ TEST(pid_get_cmdline_harder) {
 #define EXPECT2p "foo $'\\001\\002\\003'"
 #define EXPECT2v STRV_MAKE("foo", "\1\2\3")
 
-        ASSERT_OK_ZERO_ERRNO(lseek(fd, SEEK_SET, 0));
+        ASSERT_OK_ZERO_ERRNO(lseek(fd, 0, SEEK_SET));
         ASSERT_OK_EQ_ERRNO(write(fd, CMDLINE2, sizeof(CMDLINE2)), (ssize_t) sizeof(CMDLINE2));
         ASSERT_OK_ZERO_ERRNO(ftruncate(fd, sizeof CMDLINE2));
 
index 9ce49b85529c11518a6f6352c911d66ac1e95829..e2c325ac7409482414701cbc31e19ccadb16819a 100644 (file)
@@ -69,7 +69,7 @@ int probe_smart_media(int mtd_fd, mtd_info_t* info) {
         }
 
         for (offset = 0; offset < block_size * spare_count; offset += sector_size) {
-                (void) lseek(mtd_fd, SEEK_SET, offset);
+                (void) lseek(mtd_fd, offset, SEEK_SET);
 
                 if (read(mtd_fd, cis_buffer, SM_SECTOR_SIZE) == SM_SECTOR_SIZE) {
                         cis_found = 1;