From: Lennart Poettering Date: Thu, 13 Nov 2025 13:15:33 +0000 (+0100) Subject: tree-wide: fix lseek() parameter order X-Git-Tag: v259-rc1~70^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f5452477d40cfe2f971dbcb5a98f2888d5fac640;p=thirdparty%2Fsystemd.git tree-wide: fix lseek() parameter order 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? --- diff --git a/src/home/homed-home.c b/src/home/homed-home.c index a359baea591..e4f3487473a 100644 --- a/src/home/homed-home.c +++ b/src/home/homed-home.c @@ -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"); diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c index 80ef38f50a6..01a810a9b8c 100644 --- a/src/import/pull-raw.c +++ b/src/import/pull-raw.c @@ -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"); } diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index d30cc6974f4..3a3148be14f 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -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); diff --git a/src/test/test-copy.c b/src/test/test-copy.c index 86de5c4b633..58797b5926c 100644 --- a/src/test/test-copy.c +++ b/src/test/test-copy.c @@ -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); diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index 5723f2a0741..b7978453344 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -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)); diff --git a/src/udev/mtd_probe/probe_smartmedia.c b/src/udev/mtd_probe/probe_smartmedia.c index 9ce49b85529..e2c325ac740 100644 --- a/src/udev/mtd_probe/probe_smartmedia.c +++ b/src/udev/mtd_probe/probe_smartmedia.c @@ -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;