mirror of
https://github.com/python/cpython.git
synced 2025-07-28 21:55:21 +00:00
gh-96670: Raise SyntaxError when parsing NULL bytes (#97594)
This commit is contained in:
parent
dd53b79de0
commit
aab01e3524
10 changed files with 65 additions and 21 deletions
|
@ -230,16 +230,8 @@ _PyLong_FileDescriptor_Converter(PyObject *o, void *ptr)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Py_UniversalNewlineFgets is an fgets variation that understands
|
||||
** all of \r, \n and \r\n conventions.
|
||||
** The stream should be opened in binary mode.
|
||||
** The fobj parameter exists solely for legacy reasons and must be NULL.
|
||||
** Note that we need no error handling: fgets() treats error and eof
|
||||
** identically.
|
||||
*/
|
||||
char *
|
||||
Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj)
|
||||
_Py_UniversalNewlineFgetsWithSize(char *buf, int n, FILE *stream, PyObject *fobj, size_t* size)
|
||||
{
|
||||
char *p = buf;
|
||||
int c;
|
||||
|
@ -265,11 +257,28 @@ Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj)
|
|||
}
|
||||
FUNLOCKFILE(stream);
|
||||
*p = '\0';
|
||||
if (p == buf)
|
||||
if (p == buf) {
|
||||
return NULL;
|
||||
}
|
||||
*size = p - buf;
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
** Py_UniversalNewlineFgets is an fgets variation that understands
|
||||
** all of \r, \n and \r\n conventions.
|
||||
** The stream should be opened in binary mode.
|
||||
** The fobj parameter exists solely for legacy reasons and must be NULL.
|
||||
** Note that we need no error handling: fgets() treats error and eof
|
||||
** identically.
|
||||
*/
|
||||
|
||||
char *
|
||||
Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj) {
|
||||
size_t size;
|
||||
return _Py_UniversalNewlineFgetsWithSize(buf, n, stream, fobj, &size);
|
||||
}
|
||||
|
||||
/* **************************** std printer ****************************
|
||||
* The stdprinter is used during the boot strapping phase as a preliminary
|
||||
* file like object for sys.stderr.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue