[Python-checkins] r52253 - in python/branches/release24-maint: Doc/lib/libos.tex Lib/test/test_posix.py Misc/NEWS Modules/posixmodule.c
martin.v.loewis
python-checkins at python.org
Mon Oct 9 21:29:07 CEST 2006
Author: martin.v.loewis
Date: Mon Oct 9 21:29:06 2006
New Revision: 52253
Modified:
python/branches/release24-maint/Doc/lib/libos.tex
python/branches/release24-maint/Lib/test/test_posix.py
python/branches/release24-maint/Misc/NEWS
python/branches/release24-maint/Modules/posixmodule.c
Log:
Backport r45505, r45573, r45576
- reset errno before calling confstr - use confstr() doc to simplify
checks afterwards
- Correct implementation and documentation of os.confstr. Add a simple
test case. I've yet to figure out how to provoke a None return I can test.
- Address issues brought up by MvL on python-checkins.
I tested this with valgrind on amd64.
The man pages I found for diff architectures are inconsistent on this.
I'm not entirely sure this change is correct for all architectures
either.
Perhaps we should just over-allocate and not worry about it?
The change to return None instead of "" in case of unconfigured
values has not been backported.
Modified: python/branches/release24-maint/Doc/lib/libos.tex
==============================================================================
--- python/branches/release24-maint/Doc/lib/libos.tex (original)
+++ python/branches/release24-maint/Doc/lib/libos.tex Mon Oct 9 21:29:06 2006
@@ -1773,7 +1773,7 @@
string which is the name of a defined system value; these names are
specified in a number of standards (\POSIX, \UNIX{} 95, \UNIX{} 98, and
others). Some platforms define additional names as well. The names
-known to the host operating system are given in the
+known to the host operating system are given as the keys of the
\code{confstr_names} dictionary. For configuration variables not
included in that mapping, passing an integer for \var{name} is also
accepted.
Modified: python/branches/release24-maint/Lib/test/test_posix.py
==============================================================================
--- python/branches/release24-maint/Lib/test/test_posix.py (original)
+++ python/branches/release24-maint/Lib/test/test_posix.py Mon Oct 9 21:29:06 2006
@@ -73,6 +73,11 @@
finally:
fp.close()
+ def test_confstr(self):
+ if hasattr(posix, 'confstr'):
+ self.assertRaises(ValueError, posix.confstr, "CS_garbage")
+ self.assertEqual(len(posix.confstr("CS_PATH")) > 0, True)
+
def test_dup2(self):
if hasattr(posix, 'dup2'):
fp1 = open(test_support.TESTFN)
Modified: python/branches/release24-maint/Misc/NEWS
==============================================================================
--- python/branches/release24-maint/Misc/NEWS (original)
+++ python/branches/release24-maint/Misc/NEWS Mon Oct 9 21:29:06 2006
@@ -73,6 +73,8 @@
Extension Modules
-----------------
+- Fix buffer handling in posix.confstr.
+
- Bug #1572832: fix a bug in ISO-2022 codecs which may cause segfault
when encoding non-BMP unicode characters.
Modified: python/branches/release24-maint/Modules/posixmodule.c
==============================================================================
--- python/branches/release24-maint/Modules/posixmodule.c (original)
+++ python/branches/release24-maint/Modules/posixmodule.c Mon Oct 9 21:29:06 2006
@@ -6599,12 +6599,13 @@
{
PyObject *result = NULL;
int name;
- char buffer[64];
+ char buffer[256];
if (PyArg_ParseTuple(args, "O&:confstr", conv_confstr_confname, &name)) {
- int len = confstr(name, buffer, sizeof(buffer));
+ int len;
errno = 0;
+ len = confstr(name, buffer, sizeof(buffer));
if (len == 0) {
if (errno != 0)
posix_error();
@@ -6612,13 +6613,13 @@
result = PyString_FromString("");
}
else {
- if (len >= sizeof(buffer)) {
- result = PyString_FromStringAndSize(NULL, len);
+ if ((unsigned int)len >= sizeof(buffer)) {
+ result = PyString_FromStringAndSize(NULL, len-1);
if (result != NULL)
- confstr(name, PyString_AS_STRING(result), len+1);
+ confstr(name, PyString_AS_STRING(result), len);
}
else
- result = PyString_FromString(buffer);
+ result = PyString_FromStringAndSize(buffer, len-1);
}
}
return result;
More information about the Python-checkins
mailing list