summaryrefslogtreecommitdiff
path: root/archivers/gsharutils/patches/patch-ai
blob: 9c434355a7e59d6dcb24e186f4e114db8af07db6 (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
$NetBSD: patch-ai,v 1.3 2005/03/31 14:17:05 salo Exp $

--- src/uudecode.c.orig	1995-12-02 04:14:14.000000000 +0100
+++ src/uudecode.c	2005-03-31 15:51:27.000000000 +0200
@@ -81,6 +81,9 @@
 /* Single character decode.  */
 #define	DEC(Char) (((Char) - ' ') & 077)
 
+#if !defined S_ISLNK && defined S_IFLNK
+# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
+#endif
 
 static int
 read_stduu (inname)
@@ -279,6 +282,7 @@
   char buf[2 * BUFSIZ];
   char *outname;
   int do_base64 = 0;
+  struct stat attr;
 
   /* Search for header line.  */
 
@@ -337,6 +341,23 @@
 	}
     }
 
+  /* Check out file if it exists */
+  if (strcmp (outname, "/dev/stdout") != 0 && strcmp (outname, "-") != 0
+      && !access(outname, F_OK)) {
+    if (lstat(outname, &attr) == -1) {
+      error (0, errno, _("cannot access %s"), outname);
+      return 1;
+    }
+    if (S_ISFIFO(attr.st_mode)){
+      error (0, errno, _("denied writing FIFO (%s)"), outname);
+      return 1;
+    }
+    if (S_ISLNK(attr.st_mode)) {
+      error (0, errno, _("not following symlink (%s)"), outname);
+      return 1;
+    }
+  }
+
   /* Create output file and set mode.  */
 
   if (strcmp (outname, "/dev/stdout") != 0 && strcmp (outname, "-") != 0