1be9590732117dade95446615215a156ff219de2
[debian/pax] / debian / patches / fix_FTBFS4Hurd.diff
1 diff -ur pax-20090728/file_subs.c pax-20090728.modified/file_subs.c
2 --- pax-20090728/file_subs.c    2009-07-28 17:38:28.000000000 +0000
3 +++ pax-20090728.modified/file_subs.c   2011-10-31 17:39:17.000000000 +0000
4 @@ -351,7 +351,7 @@
5         int pass = 0;
6         mode_t file_mode;
7         struct stat sb;
8 -       char target[MAXPATHLEN];
9 +       char *target = NULL;
10         char *nm = arcn->name;
11         int len;
12  
13 @@ -374,8 +374,15 @@
14                         if (strcmp(NM_TAR, argv0) == 0 && Lflag) {
15                                 while (lstat(nm, &sb) == 0 &&
16                                     S_ISLNK(sb.st_mode)) {
17 +                                       target = malloc(sb.st_size + 1);
18 +                                       if (target == NULL) {
19 +                                               oerrno = ENOMEM;
20 +                                               syswarn(1, oerrno,
21 +                                                   "Insufficient memory");
22 +                                               return(-1);
23 +                                       }
24                                         len = readlink(nm, target,
25 -                                           sizeof target - 1);
26 +                                           sb.st_size + 1);
27                                         if (len == -1) {
28                                                 syswarn(0, errno,
29                                                    "cannot follow symlink %s in chain for %s",
30 @@ -383,6 +390,14 @@
31                                                 res = -1;
32                                                 goto badlink;
33                                         }
34 +                                       if (len > sb.st_size) {
35 +                                               syswarn(0, errno,
36 +                                                  "symlink %s increased in size between lstat() and readlink() for %s",
37 +                                                   nm, arcn->name);
38 +
39 +                                               res = -1;
40 +                                               goto badlink;
41 +                                       }
42                                         target[len] = '\0';
43                                         nm = target;
44                                 }
45 @@ -411,6 +426,7 @@
46                         paxwarn(0,
47                             "%s skipped. Sockets cannot be copied or extracted",
48                             nm);
49 +                       free(target);
50                         return(-1);
51                 case PAX_SLK:
52                         res = symlink(arcn->ln_name, nm);
53 @@ -425,6 +441,7 @@
54                          */
55                         paxwarn(0, "%s has an unknown file type, skipping",
56                                 nm);
57 +                       free(target);
58                         return(-1);
59                 }
60  
61 @@ -440,14 +457,17 @@
62                  * we failed to make the node
63                  */
64                 oerrno = errno;
65 -               if ((ign = unlnk_exist(nm, arcn->type)) < 0)
66 +               if ((ign = unlnk_exist(nm, arcn->type)) < 0) {
67 +                       free(target);
68                         return(-1);
69 +               }
70  
71                 if (++pass <= 1)
72                         continue;
73  
74                 if (nodirs || chk_path(nm,arcn->sb.st_uid,arcn->sb.st_gid) < 0) {
75                         syswarn(1, oerrno, "Could not create: %s", nm);
76 +                       free(target);
77                         return(-1);
78                 }
79         }
80 @@ -465,8 +485,10 @@
81         /*
82          * symlinks are done now.
83          */
84 -       if (arcn->type == PAX_SLK)
85 +       if (arcn->type == PAX_SLK) {
86 +               free(target);
87                 return(0);
88 +       }
89  
90         /*
91          * IMPORTANT SECURITY NOTE:
92 @@ -517,6 +539,7 @@
93  
94         if (patime || pmtime)
95                 set_ftime(nm, arcn->sb.st_mtime, arcn->sb.st_atime, 0);
96 +       free(target);
97         return(0);
98  }
99  
100 diff -ur pax-20090728/tables.c pax-20090728.modified/tables.c
101 --- pax-20090728/tables.c       2009-07-28 17:38:28.000000000 +0000
102 +++ pax-20090728.modified/tables.c      2011-10-31 17:17:26.000000000 +0000
103 @@ -55,6 +55,7 @@
104  #include "pax.h"
105  #include "tables.h"
106  #include "extern.h"
107 +#include <unistd.h>
108  
109  /*
110   * Routines for controlling the contents of all the different databases pax
111 @@ -1126,13 +1127,21 @@
112  add_dir(char *name, struct stat *psb, int frc_mode)
113  {
114         DIRDATA *dblk;
115 +#if (_POSIX_VERSION >= 200809L)
116 +       char *rp = NULL;
117 +#else
118         char realname[MAXPATHLEN], *rp;
119 +#endif
120  
121         if (dirp == NULL)
122                 return;
123  
124         if (havechd && *name != '/') {
125 +#if (_POSIX_VERSION >= 200809L)
126 +               if ((rp = realpath(name, NULL)) == NULL) {
127 +#else
128                 if ((rp = realpath(name, realname)) == NULL) {
129 +#endif
130                         paxwarn(1, "Cannot canonicalize %s", name);
131                         return;
132                 }
133 @@ -1143,6 +1152,9 @@
134                 if (dblk == NULL) {
135                         paxwarn(1, "Unable to store mode and times for created"
136                             " directory: %s", name);
137 +#if (_POSIX_VERSION >= 200809L)
138 +                       free(rp);
139 +#endif
140                         return;
141                 }
142                 dirp = dblk;
143 @@ -1152,6 +1164,9 @@
144         if ((dblk->name = strdup(name)) == NULL) {
145                 paxwarn(1, "Unable to store mode and times for created"
146                     " directory: %s", name);
147 +#if (_POSIX_VERSION >= 200809L)
148 +               free(rp);
149 +#endif
150                 return;
151         }
152         dblk->mode = psb->st_mode & 0xffff;
153 @@ -1159,6 +1174,9 @@
154         dblk->atime = psb->st_atime;
155         dblk->frc_mode = frc_mode;
156         ++dircnt;
157 +#if (_POSIX_VERSION >= 200809L)
158 +       free(rp);
159 +#endif
160  }
161  
162  /*