Skip to content

Commit

Permalink
Security: don't pass raw string to cgi_error, it expects a format
Browse files Browse the repository at this point in the history
string, so pass it ("%s", str) instead.  Add test case to verify that %s
makes it through intact.
  • Loading branch information
blong42 committed Nov 29, 2011
1 parent 292a3a5 commit 14d4b94
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/neo_cgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static PyObject * p_cgi_error (PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s:error(str)", &s))
return NULL;

cgi_error (cgi, s);
cgi_error (cgi, "%s", s);
rv = Py_None;
Py_INCREF(rv);
return rv;
Expand Down
10 changes: 10 additions & 0 deletions python/pywrapper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

__author__ = 'blong@google.com (Brandon Long)'

import StringIO
import unittest

import neo_cgi
Expand Down Expand Up @@ -43,6 +44,15 @@ def testCsRenderStrip(self):
def testJsEscape(self):
assert neo_cgi.jsEscape("\x0A \xA9") == "\\x0A \xA9"

def testValidateErrorString(self):
fake_stdin = StringIO.StringIO("")
fake_stdout = StringIO.StringIO()
fake_env = {}
neo_cgi.cgiWrap(fake_stdin, fake_stdout, fake_env)
ncgi = neo_cgi.CGI()
ncgi.error("%s")
assert fake_stdout.getvalue().find("%s") != -1


def suite():
return unittest.makeSuite(ClearsilverPythonWrapperTestCase, 'test')
Expand Down

0 comments on commit 14d4b94

Please sign in to comment.