summaryrefslogtreecommitdiff
path: root/backport-elf-ldconfig-should-skip-temporary-files-created-by-.patch
blob: d7fe8a7cdd0370ac205446dbbfd1b27c5fb3d3cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
From 2aa0974d2573441bffd596b07bff8698b1f2f18c Mon Sep 17 00:00:00 2001
From: Florian Weimer <fweimer@redhat.com>
Date: Fri, 20 Oct 2023 14:29:50 +0200
Subject: [PATCH 1/1] elf: ldconfig should skip temporary files created by
 package managers

This avoids crashes due to partially written files, after a package
update is interrupted.

Reference:https://sourceware.org/git/?p=glibc.git;a=commit;h=2aa0974d2573441bffd596b07bff8698b1f2f18c

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
---
 elf/ldconfig.c | 39 +++++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/elf/ldconfig.c b/elf/ldconfig.c
index 6190e0ea..73b5ef27 100644
--- a/elf/ldconfig.c
+++ b/elf/ldconfig.c
@@ -746,6 +746,31 @@ struct dlib_entry
   struct dlib_entry *next;
 };
 
+/* Skip some temporary DSO files.  These files may be partially written
+   and lead to ldconfig crashes when examined.  */
+static bool
+skip_dso_based_on_name (const char *name, size_t len)
+{
+  /* Skip temporary files created by the prelink program.  Files with
+     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)
+	return true;
+      if (len >= sizeof (".#prelink#.XXXXXX") - 1
+	  && memcmp (name + len - sizeof (".#prelink#.XXXXXX")
+		     + 1, ".#prelink#.", sizeof (".#prelink#.") - 1) == 0)
+	return true;
+    }
+  /* Skip temporary files created by RPM.  */
+  if (memchr (name, len, ';') != NULL)
+    return true;
+  /* Skip temporary files created by dpkg.  */
+  if (len > 4 && memcmp (name + len - 4, ".tmp", 4) == 0)
+    return true;
+  return false;
+}
 
 static void
 search_dir (const struct dir_entry *entry)
@@ -822,18 +847,8 @@ search_dir (const struct dir_entry *entry)
 	continue;
 
       size_t len = strlen (direntry->d_name);
-      /* Skip temporary files created by the prelink program.  Files with
-	 names like these are never really DSOs we want to look at.  */
-      if (len >= sizeof (".#prelink#") - 1)
-	{
-	  if (strcmp (direntry->d_name + len - sizeof (".#prelink#") + 1,
-		      ".#prelink#") == 0)
-	    continue;
-	  if (len >= sizeof (".#prelink#.XXXXXX") - 1
-	      && memcmp (direntry->d_name + len - sizeof (".#prelink#.XXXXXX")
-			 + 1, ".#prelink#.", sizeof (".#prelink#.") - 1) == 0)
-	    continue;
-	}
+      if (skip_dso_based_on_name (direntry->d_name, len))
+       continue;
       len += strlen (entry->path) + 2;
       if (len > file_name_len)
 	{
-- 
2.33.0