]> git.pld-linux.org Git - packages/glibc.git/blob - glibc-LD-path.c
update git patch (fixes CVE-2024-2961); rel 3
[packages/glibc.git] / glibc-LD-path.c
1 /*
2  * Copyright (c) 2004, 2005 Elan Ruusamäe <glen@pld-linux.org>.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *        This product includes software developed by Elan Ruusamäe
16  * 4. Neither the name of the author nor the names of any co-contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY ELAN RUUSAMÄE AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32
33 /*
34  * Usage
35  * ~~~~~
36  *
37  * This simple program is aimed to be used as a workaround when installing over
38  * glibc which has placed glibc.so into /lib/i686.
39  *
40  * For example, in glibc.spec:
41  *
42  * %post -p /sbin/postshell
43  * /sbin/glibc-postinst /%{_lib}/%{_host_cpu}
44  * /sbin/ldconfig /%{_lib} %{_prefix}/%{_lib}
45  *
46  * Patches and bugreports are welcome, direct them to Elan Ruusamäe
47  * <glen@pld-linux.org>.
48  */
49
50
51 #include <sys/stat.h>
52 #include <unistd.h>
53 #include <stdio.h>
54 #include <errno.h>
55 #include <string.h>
56 #include <stdlib.h>
57
58 #define error(msg) write(2, msg, strlen(msg))
59 #define warn(msg) write(2, msg, strlen(msg))
60
61 int main (int argc, char *argv[])
62 {
63 struct stat st;
64 int i, rv = 0;
65
66         if (argc == 1) {
67                 error("This program is intended to be used by glibc postinstall stage.\n");
68                 exit(1);
69         }
70
71         for (i = 1; i < argc; i++) {
72                 char *path = argv[i];
73
74                 if (stat(path, &st) == -1) {
75                         // doesn't exist. good. next please.
76                         if (errno == ENOENT) {
77                                 continue;
78                         }
79                         perror("stat");
80                         exit(1);
81                 }
82
83                 if (S_ISDIR(st.st_mode)) {
84                         int l = strlen(path);
85                         char p[l + sizeof(".rpmsave") + 1];
86
87                         strcpy(p, path);
88                         strcpy(p + l, ".rpmsave");
89                         warn("Renaming "); warn(path); warn(" to "); warn(p); warn("\n");
90                         if (rename(path, p) == -1) {
91                                 perror("rename");
92                                 rv = 1;
93                         }
94                 }
95         }
96
97         exit(rv);
98 }
This page took 0.059203 seconds and 4 git commands to generate.