diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2022-09-27 22:23:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-27 22:23:42 (GMT) |
commit | aab01e3524d966dca6e72c718a2c71403a14e47c (patch) | |
tree | 69e30e5354e49bc104177ab61ee8b39ccd24bf22 /Objects/fileobject.c | |
parent | dd53b79de0ea98af6a11481217a961daef4e9774 (diff) | |
download | cpython-aab01e3524d966dca6e72c718a2c71403a14e47c.zip cpython-aab01e3524d966dca6e72c718a2c71403a14e47c.tar.gz cpython-aab01e3524d966dca6e72c718a2c71403a14e47c.tar.bz2 |
gh-96670: Raise SyntaxError when parsing NULL bytes (#97594)
Diffstat (limited to 'Objects/fileobject.c')
-rw-r--r-- | Objects/fileobject.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c index cbc5741..ab67cd2 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -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. |