]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Always check lockf64 return value
authorH.J. Lu <hjl.tools@gmail.com>
Sun, 15 Jun 2025 03:01:30 +0000 (11:01 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 16 Jun 2025 06:48:45 +0000 (14:48 +0800)
On x86-64, when GCC 14.2.1 is used to build:

commit f3c82fc1b41261f582f5f9fa12f74af9bcbc88f9
Author: Radko Krkos <krkos@mail.muni.cz>
Date:   Sat Jun 14 11:07:40 2025 +0200

    io: Mark lockf() __wur [BZ #32800]

    In commit 0476597b28 flock() was marked __wur in posix/unistd.h, but not
    in io/fcntl.h, the declarations must match.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
I got

programs/locarchive.c: In function ‘open_archive’:
programs/locarchive.c:641:18: error: ignoring return value of ‘lockf64’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
  641 |           (void) lockf64 (fd, F_ULOCK, sizeof (struct locarhead));
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
programs/locarchive.c:653:14: error: ignoring return value of ‘lockf64’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
  653 |       (void) lockf64 (fd, F_ULOCK, sizeof (struct locarhead));
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
programs/locarchive.c:660:14: error: ignoring return value of ‘lockf64’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
  660 |       (void) lockf64 (fd, F_ULOCK, sizeof (struct locarhead));
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
programs/locarchive.c:679:14: error: ignoring return value of ‘lockf64’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
  679 |       (void) lockf64 (fd, F_ULOCK, sizeof (struct locarhead));
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Update locarchive.c to always check lockf64 return value.  This fixes
BZ #33089.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
locale/programs/locarchive.c

index 2c19f4fd295fbde57e2975feeec13b7cf348d824..ad025a819b26589bbab93e672dca580922435dd1 100644 (file)
@@ -638,7 +638,8 @@ open_archive (struct locarhandle *ah, bool readonly)
          || st.st_dev != st2.st_dev
          || st.st_ino != st2.st_ino)
        {
-         (void) lockf64 (fd, F_ULOCK, sizeof (struct locarhead));
+         if (lockf64 (fd, F_ULOCK, sizeof (struct locarhead)) != 0)
+           error (EXIT_FAILURE, errno, _("cannot unlock archive header"));
          close (fd);
          continue;
        }
@@ -650,14 +651,17 @@ open_archive (struct locarhandle *ah, bool readonly)
   /* Read the header.  */
   if (TEMP_FAILURE_RETRY (read (fd, &head, sizeof (head))) != sizeof (head))
     {
-      (void) lockf64 (fd, F_ULOCK, sizeof (struct locarhead));
-      error (EXIT_FAILURE, errno, _("cannot read archive header"));
+      int errval = errno;
+      if (lockf64 (fd, F_ULOCK, sizeof (struct locarhead)) != 0)
+       error (EXIT_FAILURE, errno, _("cannot unlock archive header"));
+      error (EXIT_FAILURE, errval, _("cannot read archive header"));
     }
 
   /* Check the magic value */
   if (GET (head.magic) != AR_MAGIC)
     {
-      (void) lockf64 (fd, F_ULOCK, sizeof (struct locarhead));
+      if (lockf64 (fd, F_ULOCK, sizeof (struct locarhead)) != 0)
+       error (EXIT_FAILURE, errno, _("cannot unlock archive header"));
       error (EXIT_FAILURE, 0, _("bad magic value in archive header"));
     }
 
@@ -676,8 +680,10 @@ open_archive (struct locarhandle *ah, bool readonly)
                     MAP_SHARED | xflags, fd, 0);
   if (ah->addr == MAP_FAILED)
     {
-      (void) lockf64 (fd, F_ULOCK, sizeof (struct locarhead));
-      error (EXIT_FAILURE, errno, _("cannot map archive header"));
+      int errval = errno;
+      if (lockf64 (fd, F_ULOCK, sizeof (struct locarhead)) != 0)
+       error (EXIT_FAILURE, errno, _("cannot unlock archive header"));
+      error (EXIT_FAILURE, errval, _("cannot map archive header"));
     }
   ah->reserved = reserved;
   ah->mmap_base = mmap_base;