diff options
author | Lysandros Nikolaou <lisandrosnik@gmail.com> | 2023-05-07 10:12:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-07 10:12:04 (GMT) |
commit | a09d3901a5329fd58a29f730ae5f48fb38f66320 (patch) | |
tree | a8504553d8184a6281dc8099503559f494482d22 /Objects | |
parent | c5dafeaa6d2dddd1d9e611424d8abf3a934880c6 (diff) | |
download | cpython-a09d3901a5329fd58a29f730ae5f48fb38f66320.zip cpython-a09d3901a5329fd58a29f730ae5f48fb38f66320.tar.gz cpython-a09d3901a5329fd58a29f730ae5f48fb38f66320.tar.bz2 |
[3.11] gh-96670: Raise SyntaxError when parsing NULL bytes (GH-97594) (#104195)
Diffstat (limited to 'Objects')
-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 8dba5b9..ffe55eb 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. |