public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] ldconfig: Actually ignore dpkg-related temporarily files
@ 2023-10-23 11:09 Florian Weimer
  2023-10-24 11:45 ` Guillem Jover
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Weimer @ 2023-10-23 11:09 UTC (permalink / raw)
  To: libc-alpha; +Cc: Guillem Jover

These files actually end in .dpkg-new and .dpkg-tmp, not .tmp
as I mistakenly assumed.

Fixes commit 2aa0974d2573441bffd59 ("elf: ldconfig should skip
temporary files created by package managers").

---
 elf/ldconfig.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/elf/ldconfig.c b/elf/ldconfig.c
index 02387a169c..4abde26e60 100644
--- a/elf/ldconfig.c
+++ b/elf/ldconfig.c
@@ -661,6 +661,17 @@ struct dlib_entry
   struct dlib_entry *next;
 };
 
+/* Return true if the N bytes at NAME end with with the characters in
+   the string SUFFIX.  (NAME[N + 1] does not have to be a null byte.)
+   Expected to be called with a string literal for SUFFIX.  */
+static inline bool
+endswithn (const char *name, size_t n, const char *suffix)
+{
+  return (n >= strlen (suffix)
+	  && memcmp (name + n - strlen (suffix), suffix,
+		     strlen (suffix)) == 0);
+}
+
 /* Skip some temporary DSO files.  These files may be partially written
    and lead to ldconfig crashes when examined.  */
 static bool
@@ -670,8 +681,7 @@ skip_dso_based_on_name (const char *name, size_t len)
      names like these are never really DSOs we want to look at.  */
   if (len >= sizeof (".#prelink#") - 1)
     {
-      if (strcmp (name + len - sizeof (".#prelink#") + 1,
-		  ".#prelink#") == 0)
+      if (endswithn (name, len, ".#prelink#"))
 	return true;
       if (len >= sizeof (".#prelink#.XXXXXX") - 1
 	  && memcmp (name + len - sizeof (".#prelink#.XXXXXX")
@@ -682,7 +692,8 @@ skip_dso_based_on_name (const char *name, size_t len)
   if (memchr (name, len, ';') != NULL)
     return true;
   /* Skip temporary files created by dpkg.  */
-  if (len > 4 && memcmp (name + len - 4, ".tmp", 4) == 0)
+  if (endswithn (name, len, ".dpkg-new")
+      || endswithn (name, len, ".dpkg-tmp"))
     return true;
   return false;
 }

base-commit: 2aa0974d2573441bffd596b07bff8698b1f2f18c


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-08 21:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-23 11:09 [PATCH] ldconfig: Actually ignore dpkg-related temporarily files Florian Weimer
2023-10-24 11:45 ` Guillem Jover
2024-01-08 21:17   ` Guillem Jover

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).