-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
Description
Bug report
Bug description:
Static analysis with scan-build points to a potential use of an uninitialized variable in Objects/unicodeobject.c, specifically within the charmapencode_output function.
The variable unsigned char replace is declared on the stack without initialization. It is passed by reference to charmapencode_lookup(&replace). Later, inside the if (PyLong_Check(rep)) block, replace is cast and assigned to the output buffer:
outstart[(*outpos)++] = (char)replace; // scan-build: Assigned value is uninitializedIf charmapencode_lookup returns a valid PyLong object but fails to update the reference to replace (or purely from a static analysis perspective), this leads to reading uninitialized stack memory.
Suggested Fix:
Either initialize replace upon declaration or retrieve the value directly from the rep object, which is guaranteed to be a PyLong in that scope:
// Instead of using 'replace':
outstart[(*outpos)++] = (char)PyLong_AsLong(rep);CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux