This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Canot send real string from c api to module (corrupted string)
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Yhojann Aguilera, serhiy.storchaka
Priority: normal Keywords:

Created on 2018-10-25 20:20 by Yhojann Aguilera, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg328484 - (view) Author: Yhojann Aguilera (Yhojann Aguilera) Date: 2018-10-25 20:20
The functios like as PyUnicode_FromString use a printf format in char array argument. Example: PyUnicode_FromString("a%22b"); in module interprete the %22 as 22 blank spaces. A double quote in module add a backslash. Poc:

Y try send a string from c++ to python string using:

PyObject* pyString = PyUnicode_FromString("/abc/def.html/a%22.php?abc=&def=%22;%00s%01");
....
PyObject* pyArgs = Py_BuildValue("(z)", pyString);
...
PyObject_CallObject(pFunc, pyArgs);

But in script the string is bad:

function(data):
    print(data)

The result is:

/abc/def.html/a              bogus %pp?abc=&def=                    %;(null)%
msg328537 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-26 11:01
PyUnicode_FromString() doesn't interpret %. Did you use PyUnicode_FromFormat()?
History
Date User Action Args
2022-04-11 14:59:07adminsetgithub: 79252
2018-10-26 11:01:02serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg328537
2018-10-25 20:20:14Yhojann Aguileracreate