Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8484fbf

Browse files
committed
SF bug 1003471: Python 1.5.2 security vulnerability
This was probably fixed in rev 1.32 of getpath.c, but there are so many paths thru the code that invoke joinpath() it's not at all obvious that it *is* fixed. It doesn't help confidence that a crucial precondition for calling joinpath() was neither documented nor verified. It is now, and joinpath() will barf with a fatal error now rather than overrun the buffer, if the precondition isn't met. Note that this patch only changes the Windows flavor. I attached another patch to the bug report for the POSIX flavor (which I can't test conveniently).
1 parent 59a27f1 commit 8484fbf

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

PC/getpathp.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,15 @@ ismodule(char *filename) /* Is module -- check for .pyc/.pyo too */
133133
return 0;
134134
}
135135

136-
/* guarantees buffer will never overflow MAXPATHLEN+1 bytes */
136+
/* Add a path component, by appending stuff to buffer.
137+
buffer must have at least MAXPATHLEN + 1 bytes allocated, and contain a
138+
NUL-terminated string with no more than MAXPATHLEN characters (not counting
139+
the trailing NUL). It's a fatal error if it contains a string longer than
140+
that (callers must be careful!). If these requirements are met, it's
141+
guaranteed that buffer will still be a NUL-terminated string with no more
142+
than MAXPATHLEN characters at exit. If stuff is too long, only as much of
143+
stuff as fits will be appended.
144+
*/
137145
static void
138146
join(char *buffer, char *stuff)
139147
{
@@ -145,6 +153,8 @@ join(char *buffer, char *stuff)
145153
if (n > 0 && !is_sep(buffer[n-1]) && n < MAXPATHLEN)
146154
buffer[n++] = SEP;
147155
}
156+
if (n > MAXPATHLEN)
157+
Py_FatalError("buffer overflow in getpathp.c's joinpath()");
148158
k = strlen(stuff);
149159
if (n + k > MAXPATHLEN)
150160
k = MAXPATHLEN - n;

0 commit comments

Comments
 (0)