8000 gh-64490: Fix bugs in argument clinic varargs processing by colorfulappl · Pull Request #32092 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-64490: Fix bugs in argument clinic varargs processing #32092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6793f38
Fix a bug which allows more than one varargs
colorfulappl Mar 24, 2022
6203962
Fix an array index out-of-bound bug
colorfulappl Mar 24, 2022
03be6f9
Fix a kwarg parse bug
colorfulappl Mar 24, 2022
cefe5e9
Merge branch 'main' into unpack_keywords_bugfix
colorfulappl Aug 11, 2022
45bde03
Regenerate clinic.test
colorfulappl Aug 11, 2022
bfc5241
Replace `pre_buffer` to a more descriptive name `nargs`
colorfulappl Aug 11, 2022
0b1523c
📜🤖 Added by blurb_it.
blurb-it[bot] Aug 11, 2022
411ad37
Replace inline literals with double backticks in news
colorfulappl Aug 11, 2022
c6a5171
Rename news
colorfulappl Aug 11, 2022
42f9273
Merge branch 'main' into unpack_keywords_bugfix
colorfulappl Aug 12, 2022
7fdd501
Simplify news
colorfulappl Aug 12, 2022
0aa4be4
Regenerate clinic.test
colorfulappl Aug 12, 2022
bbad2bb
Add test "allow no more than one vararg"
colorfulappl Aug 15, 2022
f7b6662
Merge branch 'main' into unpack_keywords_bugfix
colorfulappl Aug 15, 2022
4fb66ab
Regenerate clinic.test
8000 colorfulappl Aug 15, 2022
8f11765
Modify news
colorfulappl Aug 15, 2022
de5b2a4
Update 2022-08-11-09-58-15.gh-issue-64490.PjwhM4.rst
erlend-aasland Aug 15, 2022
85f98ca
Sphinx syntax/format fix
erlend-aasland Aug 15, 2022
58a3da5
Missing blank line
erlend-aasland Aug 15, 2022
0afce9d
Merge branch 'main' into unpack_keywords_bugfix
colorfulappl Nov 23, 2022
87314ff
Add Argument Clinic functional test cases
colorfulappl Nov 24, 2022
a48971d
Fix bug
colorfulappl Nov 24, 2022
e6a4e13
Do not generate unused `noptargs`
colorfulappl Nov 24, 2022
8592676
Update news
colorfulappl Nov 24, 2022
4c682bf
Update Lib/test/clinic.test
colorfulappl Nov 24, 2022
c3d6b73
Delete unnecessary function doc
colorfulappl Nov 24, 2022
8b26eb8
Merge branch 'main' into unpack_keywords_bugfix
colorfulappl Nov 24, 2022
3f88c54
Rerun make clinic
colorfulappl Nov 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into unpack_keywords_bugfix
# Conflicts:
#	Lib/test/test_clinic.py
#	Modules/_testclinic.c
#	Modules/clinic/_testclinic.c.h
  • Loading branch information
colorfulappl committed Nov 24, 2022
commit 8b26eb8e3103291020e7dfb137367567e837e98d
20 changes: 20 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,13 @@ def test_posonly_vararg(self):
self.assertEqual(ac_tester.posonly_vararg(1, b=2), (1, 2, ()))
self.assertEqual(ac_tester.posonly_vararg(1, 2, 3, 4), (1, 2, (3, 4)))

def test_vararg_and_posonly(self):
with self.assertRaises(TypeError):
ac_tester.vararg_and_posonly()
with self.assertRaises(TypeError):
ac_tester.vararg_and_posonly(1, b=2)
self.assertEqual(ac_tester.vararg_and_posonly(1, 2, 3, 4), (1, (2, 3, 4)))

def test_vararg(self):
with self.assertRaises(TypeError):
ac_tester.vararg()
Expand Down Expand Up @@ -1265,5 +1272,18 @@ def test_gh_32092_oob(self):
def test_gh_32092_kw_pass(self):
ac_tester.gh_32092_kw_pass(1, 2, 3)

def test_gh_99233_refcount(self):
arg = '*A unique string is not referenced by anywhere else.*'
arg_refcount_origin = sys.getrefcount(arg)
ac_tester.gh_99233_refcount(arg)
arg_refcount_after = sys.getrefcount(arg)
self.assertEqual(arg_refcount_origin, arg_refcount_after)

def test_gh_99240_double_free(self):
expected_error = r'gh_99240_double_free\(\) argument 2 must be encoded string without null bytes, not str'
with self.assertRaisesRegex(TypeError, expected_error):
ac_tester.gh_99240_double_free('a', '\0b')


if __name__ == "__main__":
unittest.main()
59 changes: 59 additions & 0 deletions Modules/_testclinic.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,24 @@ posonly_vararg_impl(PyObject *module, PyObject *a, PyObject *b,
return pack_arguments_newref(3, a, b, args);
}


/*[clinic input]
vararg_and_posonly

a: object
*args: object
/

[clinic start generated code]*/

static PyObject *
vararg_and_posonly_impl(PyObject *module, PyObject *a, PyObject *args)
/*[clinic end generated code: output=42792f799465a14d input=defe017b19ba52e8]*/
{
return pack_arguments_newref(2, a, args);
}


/*[clinic input]
vararg

Expand Down Expand Up @@ -1019,6 +1037,7 @@ vararg_with_only_defaults_impl(PyObject *module, PyObject *args, PyObject *b)
}



/*[clinic input]
gh_32092_oob

Expand Down Expand Up @@ -1061,6 +1080,43 @@ gh_32092_kw_pass_impl(PyObject *module, PyObject *pos, PyObject *args,
}


/*[clinic input]
gh_99233_refcount

*args: object
/

Proof-of-concept of GH-99233 refcount error bug.

[clinic start generated code]*/

static PyObject *
gh_99233_refcount_impl(PyObject *module, PyObject *args)
/*[clinic end generated code: output=585855abfbca9a7f input=85f5fb47ac91a626]*/
{
Py_RETURN_NONE;
}


/*[clinic input]
gh_99240_double_free

a: str(encoding="idna")
b: str(encoding="idna")
/

Proof-of-concept of GH-99240 double-free bug.

[clinic start generated code]*/

static PyObject *
gh_99240_double_free_impl(PyObject *module, char *a, char *b)
/*[clinic end generated code: output=586dc714992fe2ed input=23db44aa91870fc7]*/
{
Py_RETURN_NONE;
}


static PyMethodDef tester_methods[] = {
TEST_EMPTY_FUNCTION_METHODDEF
OBJECTS_CONVERTER_METHODDEF
Expand Down Expand Up @@ -1104,11 +1160,14 @@ static PyMethodDef tester_methods[] = {
POSONLY_OPT_KEYWORDS_OPT_KWONLY_OPT_METHODDEF
KEYWORD_ONLY_PARAMETER_METHODDEF
POSONLY_VARARG_METHODDEF
VARARG_AND_POSONLY_METHODDEF
VARARG_METHODDEF
VARARG_WITH_DEFAULT_METHODDEF
VARARG_WITH_ONLY_DEFAULTS_METHODDEF
GH_32092_OOB_METHODDEF
GH_32092_KW_PASS_METHODDEF
GH_99233_REFCOUNT_METHODDEF
GH_99240_DOUBLE_FREE_METHODDEF
{NULL, NULL}
};

Expand Down
99 changes: 99 additions & 0 deletions Modules/clinic/_testclinic.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

You are viewing a condensed version of this merge commit. You can view the full changes here.
0