Iustin Pop [Fri, 1 May 2015 01:00:35 +0000 (03:00 +0200)]
Make the code -Wconversion ready: explicit casts only
This patch, while adding lots of extra boilerplate, converts all code
to explicit casts only; it now builds with `-Wconversion` cleanly,
although that's a bit too strong to turn on by default (for now).
Iustin Pop [Thu, 30 Apr 2015 23:02:59 +0000 (01:02 +0200)]
Fix a few int/size_t conversion issues
From https://bugzilla.redhat.com/show_bug.cgi?id=1127310: the
'#'-variats of parsing (s#, et#, etc.) take a size_t if
PY_SSIZE_T_CLEAN is defined (which the code does). On some
architectures (little-endian only?) this doesn't seem to be a problem,
but on PPC this is a failure in unit tests (at least yay).
The patch changes the type of bufsize to Py_ssize_t, and does an
explicit cast to size_t with underflow check in order to make the code
safer (assuming this is the right thing to do). This should result in
no unexpected conversion issues.
Iustin Pop [Thu, 30 Apr 2015 22:52:52 +0000 (00:52 +0200)]
Improve error checking in get_all()
After getting a too big value via ERANGE, making the call with the
proper length could still fail due to other issues, and this check is
missing. A negative value here would be changed into something weird
in the realloc call (which takes size_t), so the error reporting would
be bogus.
Iustin Pop [Thu, 30 Apr 2015 22:43:16 +0000 (00:43 +0200)]
Fix memory leak on get_all OutOfMemory handling path
It's unlikely that the situation is recoverable when failing to
allocate memory, but the current code is clearly buggy: PyMem_Realloc
doesn't clobber the existing buffer on failure, so not deallocating it
will result in a leak.
SELinux systems may have the security.selinux attribute defined for
temporary files upon creation. This can cause problems for the tests,
which assumed that new files have no attributes. Similar problems can
arise in other cases where temporary files created by python start out
with attributes.
To work around this, a comma-separated list of attributes to ignore can
be specified in the environment variable "TEST_IGNORE_XATTRS". Any
attributes specified in this way will be filtered out by tests.
ari edelkind [Tue, 17 Sep 2013 18:20:33 +0000 (14:20 -0400)]
Better handling of files without xattrs
Return an empty list immediately if a file has no xattrs (as most would
not on most systems). The number of system calls for files with no
extended attributes is reduced by (at least) half.
Jonas Borgström [Thu, 13 Jun 2013 20:17:32 +0000 (22:17 +0200)]
Use "surrogateescape" error handler when encoding unicode paths.
On Python 3 functions like os.listdir() always returns unicode
paths. "invalid" byte paths are decoded using the "surrogateescape" error
handler which must also be used when decoding.
See os.fsencodefs() and os.fsdecode().
Iustin Pop [Thu, 3 Jan 2013 20:36:36 +0000 (21:36 +0100)]
Fix string/unicode buffer size parsing
It seems that CPython allows passing "wrong" pointers for et#
(Py_ssize_t instead of int), but PyPy has problems with this, and
wrongly casts the pointers, leading to unsigned/signed conversion
failures.
This bug was introduced in commits 433c5852 and 8aa6fd81; I'm no
longer sure why bufsize was changed from int to Py_ssize_t as well,
but passing an int value to a C function expecting an ssize_t should
be safe as the compiler should do the required conversions behind the
scenes (as long as it has correct information about the types).
Iustin Pop [Tue, 15 May 2012 19:24:04 +0000 (21:24 +0200)]
Rework parsing of the namespace argument
In Python 3, we cannot accept (easily) bytes or None, so we have to
change how we accept the namespace argument.
Previously, if the argument was not passed or it was None, it was
considered missing. Since the None option is no longer possible, we
change it so that if not passed or passed as an empty string, it is
considered missing. This changes the behaviour somewhat, but I hope
that empty namespaces are not used (that's what I understand from
reading various pages on the internet).
Iustin Pop [Mon, 14 May 2012 20:32:07 +0000 (22:32 +0200)]
Fix bugs reported by cpychecker
Thanks to Dave Malcolm's cpychecker tool, this patch fixes a number of
serious issues. All issues that were not deemed false-positives were
fixed; some other issues in the same category that were found only by
a high number of refcount checks are also fixed (I should
split/simplify some parts of the code…).
Iustin Pop [Sun, 14 Dec 2008 20:12:43 +0000 (21:12 +0100)]
Fix a size_t/ssize_t mismatch
ACL library functions return a ssize_t, so all variables that hold
return values from such return types must be ssize_t, otherwise
comparisons with -1 will fail.
Iustin Pop [Sun, 14 Dec 2008 17:47:51 +0000 (18:47 +0100)]
Add python 3 support
This big patch does a few things (which are hard to split):
- uniformize all function w.r.t. the error exit path (all functions
now use only one exit point)
- move from 's' to 'et' format in ParseArgs so that we can accept both
binary and text, in both 2.x and 3.0
- update the unittest for py3k
Iustin Pop [Sun, 14 Dec 2008 17:46:01 +0000 (18:46 +0100)]
Initialize local variables
This patch prepares for the "et" format conversion by initializing the
local variables; it also adds a new "res" object for returns and adds a
few style fixes.
Iustin Pop [Sun, 14 Dec 2008 17:41:34 +0000 (18:41 +0100)]
Add a new field to the target_t structure
The patch extends the target_t structure with a new PyObject field and
adds a cleanup function for it. This field is needed for properly
handling unicode input arguments with Py3K.
Iustin Pop [Mon, 30 Jun 2008 19:17:08 +0000 (21:17 +0200)]
unittests: enhance symlink tests
The patch adds support for testing the behaviour of non-dangling
symlinks; we test that indeed attributes set on the target file are not
visible on the symlink when using nofollow.
Iustin Pop [Mon, 30 Jun 2008 05:16:53 +0000 (07:16 +0200)]
Implement changes needed for PEP 353 compliance
It seems the coded wrongly mixed ssize_t and ints in a couple of places,
plus not properly using Py_ssize_t as needed. Fix these and ensure
backwards compat with python 2.4.
Iustin Pop [Sun, 29 Jun 2008 21:26:10 +0000 (23:26 +0200)]
Change the match_ns function syntax
This patch changes the order of the two arguments and makes the function
return either NULL (failure) or a pointer to the (possibly shortened)
name, so that getting the short name is easier.
Iustin Pop [Sun, 29 Jun 2008 17:00:42 +0000 (19:00 +0200)]
Convert to object protocol
This patch changes the hardcoded if-then-else constructs for selecting
the type of function (file-descriptor, symlink, normal path) into a
generic framework.