Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 329705 - dev-lang/python - 61_all_process_data.patch/posixmodule.c makes G, GE, GEN, etc. environment inaccessible
Summary: dev-lang/python - 61_all_process_data.patch/posixmodule.c makes G, GE, GEN, e...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All All
: Highest major (vote)
Assignee: Python Gentoo Team
URL:
Whiteboard: 2.6.5_p20100801, 2.7_p20100801, 3.1.2...
Keywords: InVCS
Depends on:
Blocks:
 
Reported: 2010-07-24 15:04 UTC by C.Blake
Modified: 2010-08-02 19:29 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Fix strncmp bug that matches any variable that is a prefix to target vars (posixmodule.patch,564 bytes, patch)
2010-07-24 17:06 UTC, C.Blake
Details | Diff
Entire all_process_data replacement for strncmp bug in Python env vars skipping (61_all_process_data.patch,3.74 KB, patch)
2010-07-24 17:07 UTC, C.Blake
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description C.Blake 2010-07-24 15:04:42 UTC
This patch uses an strncmp to not incorporate gentoo python-wrapper related environment variables into the os.environ, namely GENTOO_PYTHON_PROCESS_NAME, GENTOO_PYTHON_TARGET_SCRIPT_PATH, GENTOO_PYTHON_WRAPPER_SCRIPT_PATH.

As written it is broken, and blocks incorporating many other variables which breaks environment set up in posixmodule.so in an impossible to work around way.

Any environment variable that begins with G, GE, GEN, GENT, GENTO, etc. is blocked from incorporation. For example, try G=1 python2 -c 'import os; print os.environ["G"]'.

This is because the length of the new variable (p - *e) in the code, will be 1, 2, 3, 4, 5, etc. respectively.  The strncmp will then yield zero (equality) since the prefix matches.

You can fix this easily safely, and securely by first checking that the length matches, i.e.  (p - *e == 26 && strncmp("GENTOO_PYTHON_PROCESS_NAME"...)) || ... with 32 and 33 for the other variables. { This also represents a tiny, unimportant in context optimization since by boolean short-circuit rules the strncmp will not be called unless the lengths match. }

If the hard coded constants strike you as too fragile, you can use strlen. I believe gcc can compile-time optimize that to the constants.

It's surprising that gentoo developers don't need to receive variables in python with a GENTOO prefix. :)  But really everyone should be allowed to get variables like $G, $GEN, $GENT.
Comment 1 C.Blake 2010-07-24 17:06:06 UTC
Created attachment 240011 [details, diff]
Fix strncmp bug that matches any variable that is a prefix to target vars

This is a fix for just the posixmodule.c portion of 61_all_process_data.patch.

I will also attach an entire 61_all_process_data.patch in case that is helpful.
Comment 2 C.Blake 2010-07-24 17:07:17 UTC
Created attachment 240013 [details, diff]
Entire all_process_data replacement for strncmp bug in Python env vars skipping

This is the same as the last patch, but is the entire replacement file.
Comment 3 Arfrever Frehtes Taifersar Arahesis (RETIRED) gentoo-dev 2010-08-02 17:09:58 UTC
Fixed in r367.
Comment 4 Arfrever Frehtes Taifersar Arahesis (RETIRED) gentoo-dev 2010-08-02 19:29:31 UTC
Fixed in 2.6.5_p20100801, 2.7_p20100801, 3.1.2_p20100801 and 3.2_pre20100801.