Author Oren Milman
Recipients Oren Milman
Date 2016-09-23.20:16:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1474661815.38.0.12357433446.issue28261@psf.upfronthosting.co.za>
In-reply-to
Content
------------ current state ------------
In few places in the codebase, PyArg_ParseTuple is called in order to parse a normal tuple (instead of the usual case of parsing the arguments tuple of a function).
In some of these places, failure of PyArg_ParseTuple is handled simply by cleanup (if needed) and returning an error code, and so an exception with the generic error message is raised.
The generic error message is appropriate in case the parsed tuple is the arguments tuple of a function, but might be really wrong in case it is a normal tuple.

For example, such case in Modules/socketmodule.c in socket_getnameinfo leads to the following:
    >>> import socket
    >>> socket.getnameinfo(tuple(), 1)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: function takes at least 2 arguments (0 given)
    >>>


------------ proposed changes ------------
In each of these places, add to the format string (which is passed to PyArg_ParseTuple) a ';', followed by an appropriate error message, as already done in Modules/audioop.c in audioop_ratecv_impl:
        if (!PyArg_ParseTuple(state,
                        "iO!;audioop.ratecv: illegal state argument",
                        &d, &PyTuple_Type, &samps))
            goto exit;


------------ diff ------------
The proposed patches diff file is attached.


------------ tests ------------
I wrote an ugly script to verify the wrong error messages on CPython without my patches, and to test the patches on CPython with my patches. The script is attached (but it might fail on a non-Windows machine).

In addition, I ran 'python_d.exe -m test -j3' (on my 64-bit Windows 10) with and without the patches, and got quite the same output.
The outputs of both runs are attached.
History
Date User Action Args
2016-09-23 20:16:55Oren Milmansetrecipients: + Oren Milman
2016-09-23 20:16:55Oren Milmansetmessageid: <1474661815.38.0.12357433446.issue28261@psf.upfronthosting.co.za>
2016-09-23 20:16:55Oren Milmanlinkissue28261 messages
2016-09-23 20:16:54Oren Milmancreate