@@ -40,8 +40,9 @@ as constants in the fcntl module, using the same names as used in
40
40
the relevant C header files. The argument arg is optional, and
41
41
defaults to 0; it may be an int or a string. If arg is given as a string,
42
42
the return value of fcntl is a string of that length, containing the
43
- resulting value put in the arg buffer by the operating system. If the arg
44
- given is an integer or if none is specified, the result value is an integer
43
+ resulting value put in the arg buffer by the operating system. The length
44
+ of the arg string is not allowed to exceed 1024 bytes. If the arg given
45
+ is an integer or if none is specified, the result value is an integer
45
46
corresponding to the return value of the fcntl call in the C code.
46
47
[clinic start generated code]*/
47
48
@@ -53,6 +54,7 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
53
54
int ret ;
54
55
char * str ;
55
56
Py_ssize_t len ;
57
+ //char buf[1024];
56
58
int async_err = 0 ;
57
59
58
60
if (PySys_Audit ("fcntl.fcntl" , "iiO" , fd , code , arg ? arg : Py_None ) < 0 ) {
@@ -63,11 +65,22 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
63
65
int parse_result ;
64
66
65
67
if (PyArg_Parse (arg , "s#" , & str , & len )) {
66
- PyObject * o = PyBytes_FromStringAndSize (NULL , len );
68
+ /*if ((size_t)len > sizeof buf) {
69
+ PyErr_SetString(PyExc_ValueError,
70
+ "fcntl string arg too long");
71
+ return NULL;
72
+ }*/
73
+ char * buf = malloc ((size_t )len );
74
+ PyObject * buf_ret ;
75
+ if (buf == NULL ) {
76
+ PyErr_NoMemory ();
77
+ return NULL ;
78
+ }
79
+ /*PyObject *o = PyBytes_FromStringAndSize(NULL, len);
67
80
if (o == NULL) {
68
81
return NULL;
69
82
}
70
- char * buf = PyBytes_AS_STRING (o );
83
+ char *buf = PyBytes_AS_STRING(o);*/
71
84
72
85
memcpy (buf , str , len );
73
86
do {
@@ -76,9 +89,13 @@ fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg)
76
89
Py_END_ALLOW_THREADS
77
90
} while (ret == -1 && errno == EINTR && !(async_err = PyErr_CheckSignals ()));
78
91
if (ret < 0 ) {
92
+ free (buf );
79
93
return !async_err ? PyErr_SetFromErrno (PyExc_OSError ) : NULL ;
80
94
}
81
- return PyBytes_FromStringAndSize (buf , len );
95
+ //return PyBytes_FromStringAndSize(buf, len);
96
+ buf_ret = PyBytes_FromStringAndSize (buf , len );
97
+ free (buf );
98
+ return (buf_ret );
82
99
}
83
100
84
101
PyErr_Clear ();
0 commit comments