Magellan Linux

Contents of /trunk/coreutils/patches-5.3.0/coreutils-5.3.0-pathname-off-by-one.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 44 - (show annotations) (download)
Thu Oct 13 21:17:16 2005 UTC (18 years, 7 months ago) by niro
File size: 3093 byte(s)
patch set for coretutils-5.3.0

1 http://bugs.gentoo.org/105639
2
3 2005-01-25 Jim Meyering <jim@meyering.net>
4
5 * path-concat.c: Don't include assert.h.
6 (path_concat): Remove assertion that would have triggered
7 for ABASE starting with more than one slash.
8 Reported by Andreas Schwab.
9
10 * path-concat.c (path_concat): Set *BASE_IN_RESULT
11 properly when ABASE is an absolute file name.
12 Correct the description of this function.
13 Include <assert.h>.
14 Add an assertion and a test driver.
15 This fixes a bug introduced on 2004-07-02.
16 Andreas Schwab reported the resulting failure of cp --parents:
17 http://lists.gnu.org/archive/html/bug-coreutils/2005-01/msg00130.html
18
19 Index: path-concat.c
20 ===================================================================
21 RCS file: /cvsroot/coreutils/coreutils/lib/Attic/path-concat.c,v
22 retrieving revision 1.21
23 retrieving revision 1.23
24 diff -u -p -r1.21 -r1.23
25 --- lib/path-concat.c 5 Jul 2004 08:41:13 -0000 1.21
26 +++ lib/path-concat.c 25 Jan 2005 12:30:01 -0000 1.23
27 @@ -1,6 +1,6 @@
28 /* path-concat.c -- concatenate two arbitrary pathnames
29
30 - Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free
31 + Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free
32 Software Foundation, Inc.
33
34 This program is free software; you can redistribute it and/or modify
35 @@ -54,8 +54,10 @@ longest_relative_suffix (char const *f)
36 Arrange for a directory separator if necessary between DIR and BASE
37 in the result, removing any redundant separators.
38 In any case, if BASE_IN_RESULT is non-NULL, set
39 - *BASE_IN_RESULT to point to the copy of BASE in the returned
40 - concatenation.
41 + *BASE_IN_RESULT to point to the copy of ABASE in the returned
42 + concatenation. However, if ABASE begins with more than one slash,
43 + set *BASE_IN_RESULT to point to the sole corresponding slash that
44 + is copied into the result buffer.
45
46 Report an error if memory is exhausted. */
47
48 @@ -78,10 +80,47 @@ path_concat (char const *dir, char const
49 p += needs_separator;
50
51 if (base_in_result)
52 - *base_in_result = p;
53 + *base_in_result = p - IS_ABSOLUTE_FILE_NAME (abase);
54
55 p = mempcpy (p, base, baselen);
56 *p = '\0';
57
58 return p_concat;
59 }
60 +
61 +#ifdef TEST_PATH_CONCAT
62 +#include <stdlib.h>
63 +#include <stdio.h>
64 +int
65 +main ()
66 +{
67 + static char const *const tests[][3] =
68 + {
69 + {"a", "b", "a/b"},
70 + {"a/", "b", "a/b"},
71 + {"a/", "/b", "a/b"},
72 + {"a", "/b", "a/b"},
73 +
74 + {"/", "b", "/b"},
75 + {"/", "/b", "/b"},
76 + {"/", "/", "/"},
77 + {"a", "/", "a/"}, /* this might deserve a diagnostic */
78 + {"/a", "/", "/a/"}, /* this might deserve a diagnostic */
79 + {"a", "//b", "a/b"},
80 + };
81 + size_t i;
82 + bool fail = false;
83 + for (i = 0; i < sizeof tests / sizeof tests[0]; i++)
84 + {
85 + char *base_in_result;
86 + char const *const *t = tests[i];
87 + char *res = path_concat (t[0], t[1], &base_in_result);
88 + if (strcmp (res, t[2]) != 0)
89 + {
90 + printf ("got %s, expected %s\n", res, t[2]);
91 + fail = true;
92 + }
93 + }
94 + exit (fail ? EXIT_FAILURE : EXIT_SUCCESS);
95 +}
96 +#endif