diff options
author | Jim Meyering <meyering@redhat.com> | 2011-02-01 11:21:15 +0100 |
---|---|---|
committer | Andreas Gruenbacher <agruen@linbit.com> | 2011-02-03 22:00:50 +0100 |
commit | 685a78b6052f4df6eac6d625a545cfb54a6ac0e1 (patch) | |
tree | 71794ea7f8a6076a396b10733288aa384e4d360d /src | |
parent | 7fae6755f4194423ba52add76f5cbdbffd26fe04 (diff) | |
download | patch-685a78b6052f4df6eac6d625a545cfb54a6ac0e1.tar.gz |
Do not let a malicious patch create files above current directory
This addresses CVE-2010-4651, reported by Jakub Wilk.
https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2010-4651
* src/util.c (strip_leading_slashes): Reject absolute file names
and file names containing a component of "..".
* tests/bad-filenames: New file. Test for this.
* tests/Makefile.am (TESTS): Add it.
Improvements by Andreas Gruenbacher.
Diffstat (limited to 'src')
-rw-r--r-- | src/pch.c | 2 | ||||
-rw-r--r-- | src/util.c | 13 |
2 files changed, 13 insertions, 2 deletions
@@ -3,7 +3,7 @@ /* Copyright (C) 1986, 1987, 1988 Larry Wall Copyright (C) 1990, 1991, 1992, 1993, 1997, 1998, 1999, 2000, 2001, - 2002, 2003, 2006, 2009, 2010 Free Software Foundation, Inc. + 2002, 2003, 2006, 2009, 2010, 2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -3,7 +3,7 @@ /* Copyright (C) 1986 Larry Wall Copyright (C) 1992, 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2006, - 2009, 2010 Free Software Foundation, Inc. + 2009, 2010, 2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1415,6 +1415,17 @@ strip_leading_slashes (char *name, int strip_leading) n = p+1; } } + if (IS_ABSOLUTE_FILE_NAME (n)) + fatal ("rejecting absolute file name: %s", quotearg (n)); + for (p = n; *p; ) + { + if (*p == '.' && *++p == '.' && ( ! *++p || ISSLASH (*p))) + fatal ("rejecting file name with \"..\" component: %s", quotearg (n)); + while (*p && ! ISSLASH (*p)) + p++; + while (ISSLASH (*p)) + p++; + } if ((strip_leading < 0 || s <= 0) && *n) { memmove (name, n, strlen (n) + 1); |