mirror of https://github.com/python/cpython.git
gh-122431: Disallow negative values in `readline.append_history_file` (#122469)
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
67b9a5331a
commit
208b0fb645
|
@ -114,6 +114,14 @@ def test_write_read_append(self):
|
||||||
# write_history_file can create the target
|
# write_history_file can create the target
|
||||||
readline.write_history_file(hfilename)
|
readline.write_history_file(hfilename)
|
||||||
|
|
||||||
|
# Negative values should be disallowed
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
readline.append_history_file(-42, hfilename)
|
||||||
|
|
||||||
|
# See gh-122431, using the minimum signed integer value caused a segfault
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
readline.append_history_file(-2147483648, hfilename)
|
||||||
|
|
||||||
def test_nonascii_history(self):
|
def test_nonascii_history(self):
|
||||||
readline.clear_history()
|
readline.clear_history()
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
:func:`readline.append_history_file` now raises a :exc:`ValueError` when given a negative value.
|
|
@ -351,6 +351,12 @@ readline_append_history_file_impl(PyObject *module, int nelements,
|
||||||
PyObject *filename_obj)
|
PyObject *filename_obj)
|
||||||
/*[clinic end generated code: output=5df06fc9da56e4e4 input=784b774db3a4b7c5]*/
|
/*[clinic end generated code: output=5df06fc9da56e4e4 input=784b774db3a4b7c5]*/
|
||||||
{
|
{
|
||||||
|
if (nelements < 0)
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_ValueError, "nelements must be positive");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
PyObject *filename_bytes;
|
PyObject *filename_bytes;
|
||||||
const char *filename;
|
const char *filename;
|
||||||
int err;
|
int err;
|
||||||
|
|
Loading…
Reference in New Issue