msg165053 - (view) |
Author: (do1) |
Date: 2012-07-09 02:15 |
os.chown() can not change uid/gid to valid but high number.
# chown 4294967294.4294967294 a
# ls -l a
-rw-r--r-- 1 4294967294 4294967294 0 Jul 9 05:22 a
# python
Python 2.7.3 (default, Jun 24 2012, 06:19:44)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.chown("a", 4294967294, 4294967294)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C long
|
msg165054 - (view) |
Author: (do1) |
Date: 2012-07-09 02:26 |
I can add that system is x86_32. Same code in x86_64 result in no error even on older Python version 2.6.6
|
msg165425 - (view) |
Author: Mark Shannon (Mark.Shannon) * |
Date: 2012-07-13 23:22 |
Larry, you're the expert on this.
Looks to me like the format character in PyArg_ParseTuple in posix_fchown and kin should be 'k' (unsigned long) rather than 'l' (signed long).
|
msg165427 - (view) |
Author: Ned Deily (ned.deily) * |
Date: 2012-07-13 23:34 |
Possible duplicate of Issue4591?
|
msg165428 - (view) |
Author: Larry Hastings (larry) * |
Date: 2012-07-14 00:15 |
I don't think "k" is the right answer.
POSIX defines the user and group parameters as uid_t and gid_t respectively; in turn, uid_t and gid_t are defined as "integers", pointedly omitting the either of the words "signed" or "unsigned". So POSIX makes no guarantee that uid_t and gid_t are unsigned.
On the other hand: chown takes special values defined as "(uid_t)-1" and "(gid_t)-1" to indicate "don't change this value". If we change chown to use "k" for uid and gid, then in order to use this value you'd have to pass in the equivalent unsigned value. And that'd require you to know the size of an int on the local platform. Yuck!
If this is a genuine problem, then I think we have to take "O" (or "O!") and convert the long by hand. If it's -1, use "(uid_t)-1" (etc), otherwise convert as unsigned. On the other hand, if this is only a theoretical problem then I'd prefer to wontfix and keep the code simple.
p.s. find uid_t / gid_t here: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/types.h.html
chown here:
http://pubs.opengroup.org/onlinepubs/009695399/functions/chown.html
|
msg165429 - (view) |
Author: (do1) |
Date: 2012-07-14 00:22 |
Problem emerged when well-known backup software (rdiff-backup) is 'crashed' (as in no backups). So I think this is not that theoretical.
|
msg165430 - (view) |
Author: Larry Hastings (larry) * |
Date: 2012-07-14 00:37 |
Thinking about it some more, maybe we need to be smart about whether uid_t/gid_t are signed or unsigned.
I'm no good with configure hackery--could anyone here enhance the configure script so it could tell us whether or not uid_t and gid_t were signed or unsigned?
|
msg165431 - (view) |
Author: Ned Deily (ned.deily) * |
Date: 2012-07-14 00:40 |
There is a proposed patch by haypo with Issue4591.
|
msg165433 - (view) |
Author: Larry Hastings (larry) * |
Date: 2012-07-14 06:17 |
That patch from Victor looks pretty good. I'll try to get it in for beta 2, however I'm on the road right now. I'm back Sunday night and will try to do it then.
If someone else wants to jump in that's fine with me.
|
msg165477 - (view) |
Author: Larry Hastings (larry) * |
Date: 2012-07-15 00:48 |
It looks like #1747858 is another duplicate. Though arguably all these "dups" aren't really dups because I rewrote chown's argument parsing for 3.3.
|
msg165481 - (view) |
Author: Larry Hastings (larry) * |
Date: 2012-07-15 01:14 |
Here's a first cut at a patch. It's really just an update of Victor's patch to #4591 (done with his blessing). I tweaked it slightly; the parsing functions are now O& converter functions.
I also added a reasonable unit test. Note however that the unit test is only run if you run the test as root.
I don't think this needs any documentation, just a Misc/NEWS entry.
If someone can give me quick turnaround on a review (or two) maybe we can get this in before beta 2 tomorrow.
I'm adding Antoine and MvL as they were in on the earliest known bug of this class.
|
msg182088 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) * |
Date: 2013-02-14 11:24 |
Similar test was committed for issue4591 and it fixes this issue. There are only two differences with Larry's patch: tests and handling of non-integers.
Here is a patch based on Larry's patch which extends tests for *chown().
|
msg182089 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) * |
Date: 2013-02-14 11:33 |
And here is a patch which uses __index__ for uid and gid conversion. decimal.Decimal should be added to the list of wrong types in the test.
I'm not sure about the last patch, whether to consider it as a bugfix or as a new feature?
|
msg182533 - (view) |
Author: Roundup Robot (python-dev) |
Date: 2013-02-20 17:53 |
New changeset 9b37e53838eb by Serhiy Storchaka in branch '2.7':
Issue #15301: Enhance os.*chown() testing. Based on patch by Larry Hastings.
http://hg.python.org/cpython/rev/9b37e53838eb
New changeset a0baf5347cd1 by Serhiy Storchaka in branch '3.2':
Issue #15301: Enhance os.*chown() testing. Based on patch by Larry Hastings.
http://hg.python.org/cpython/rev/a0baf5347cd1
New changeset e97b6394848b by Serhiy Storchaka in branch '3.3':
Issue #15301: Enhance os.*chown() testing. Based on patch by Larry Hastings.
http://hg.python.org/cpython/rev/e97b6394848b
New changeset d4bf997a34e9 by Serhiy Storchaka in branch 'default':
Issue #15301: Enhance os.*chown() testing. Based on patch by Larry Hastings.
http://hg.python.org/cpython/rev/d4bf997a34e9
|
msg186862 - (view) |
Author: Mark Dickinson (mark.dickinson) * |
Date: 2013-04-13 21:58 |
+1 on using PyNumber_Index.
|
msg186909 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) * |
Date: 2013-04-14 10:54 |
Thank you, Mark. There is only one question. For what version is it appropriate? Only for 3.4 or for all maintained?
|
msg186913 - (view) |
Author: Larry Hastings (larry) * |
Date: 2013-04-14 11:30 |
Oh...! Serhiy, I thought you already checked in the AsIndex stuff. Guess I was asleep at the switch.
Certainly the patch should go in for trunk. I'd be comfortable with it going in for 3.3 as a bugfix but that's ultimately Georg's call.
I'll give you a comment or two on the diff.
|
msg186970 - (view) |
Author: Larry Hastings (larry) * |
Date: 2013-04-15 10:01 |
Okay, I got inspired and (in the words of Barry Warsaw) JFDI. Attached is my revised patch. I took Serhiy's patch and reworked it quite a bit:
* I think it's now easier to follow. In particular:
* The most common case (no overflow) is now first. In Serhiy's patch
the most common case is buried in the middle of the second "if".
* I removed some extraneous tests.
* I changed the error messages to call the values "uid" and "gid", to match the names of the parameters.
* I noticed that _fd_converter had the same bad-idea PyFloat_Check, so I changed it to use PyNumber_Index instead.
In the process I also noticed that Serhiy's approach had a resource leak: it never decref'd the result of PyNumber_Index() when successful.
To make sure I duplicated Serhiy's semantics, I had a test harness that ran both his and mine and ensured they returned the same thing (or both threw an error). Obviously I removed all that before cutting the patch.
|
msg186971 - (view) |
Author: Mark Dickinson (mark.dickinson) * |
Date: 2013-04-15 10:53 |
To answer Serhiy's question: I'd say that this level of cleanup is probably only appropriate for 3.4. Larry?
|
msg186974 - (view) |
Author: Larry Hastings (larry) * |
Date: 2013-04-15 11:17 |
See my comment above (dated 2013-04-14 04:30). I'm passing the buck.
|
msg187019 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) * |
Date: 2013-04-15 19:26 |
>* The most common case (no overflow) is now first. In Serhiy's patch
> the most common case is buried in the middle of the second "if".
It's because my implementation is a simplified version of more complicated patch for issue2005, which supports signed uid_t and sizeof(uid_t) > sizeof(long). And this support can be added if necessary.
|
msg187075 - (view) |
Author: Larry Hastings (larry) * |
Date: 2013-04-16 12:36 |
Whoops, forgot to write something here. Updated patch (in previous edit to the issue) incorporating Serhiy's suggestions from Rietveld.
|
msg187576 - (view) |
Author: Larry Hastings (larry) * |
Date: 2013-04-22 18:05 |
Can I get an LGTM?
|
msg187579 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) * |
Date: 2013-04-22 18:33 |
New tests needed (with Decimal and Fraction). And what is purpose of changing Py_TYPE(o) to o->ob_type?
|
msg187580 - (view) |
Author: Larry Hastings (larry) * |
Date: 2013-04-22 19:07 |
Latest patch incorporating Serihy's comments.
|
msg187581 - (view) |
Author: Larry Hastings (larry) * |
Date: 2013-04-22 19:10 |
Whoops, meant to throw in a Fraction too. Added that. Also hoisted the imports out of the function call, just to be a good guy.
|
msg187677 - (view) |
Author: Larry Hastings (larry) * |
Date: 2013-04-23 23:32 |
Serhiy: Oh, I get it, your critique was about the "Note:" part at the bottom. It would have been helpful if you had inserted your feedback there, instead of at the top. Yeah, you're right, the note was incorrect.
I considered adding a note saying that the code was wrong if sizeof(uid_t) > sizeof(long) but thought better of it ;-)
New patch attached.
|
msg187689 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) * |
Date: 2013-04-24 07:03 |
Yes, it is what I had in mean. Sorry for indistinctness.
As far as you change _fd_converter() it will be good to add also a test for float/decimal/fractional fd. Otherwise the patch LGTM.
|
msg192193 - (view) |
Author: Scott Leerssen (Scott.Leerssen) |
Date: 2013-07-02 12:50 |
Regarding whether or not to include the fix in 2.7, I'd like to suggest that it be included there as well. It will be quite some time before the project on which I work moves to Python 3, and I just hit the same issue.
|
msg194534 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) * |
Date: 2013-08-06 11:56 |
Let's push.
|
msg194645 - (view) |
Author: Larry Hastings (larry) * |
Date: 2013-08-08 06:44 |
Benjamin, do you want my elaborate fix in for 2.7? It means adding two new converters, one for pid and one for gid, and switching everything that takes pid/gid arguments to use those.
|
msg194646 - (view) |
Author: Roundup Robot (python-dev) |
Date: 2013-08-08 07:23 |
New changeset f871f8662509 by Larry Hastings in branch 'default':
Issue #15301: Parsing fd, uid, and gid parameters for builtins
http://hg.python.org/cpython/rev/f871f8662509
|
msg194647 - (view) |
Author: Larry Hastings (larry) * |
Date: 2013-08-08 07:23 |
Now fixed in trunk. I am waiting to hear from Georg and the only-recently-pinged Benjamin to see if they want these fixes in 3.3 or 2.7.
|
msg194649 - (view) |
Author: Benjamin Peterson (benjamin.peterson) * |
Date: 2013-08-08 07:32 |
I think we should leave 2.7 at rest for the moment.
|
msg194650 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) * |
Date: 2013-08-08 07:35 |
The original issue was fixed in issue4591. Larry's patch only adds support of PyNumber_Index() and refactors already existing uid/gid converters.
|
msg194654 - (view) |
Author: Georg Brandl (georg.brandl) * |
Date: 2013-08-08 08:39 |
Looks like an unnecessary change for the maintenance releases then.
|
msg194655 - (view) |
Author: Larry Hastings (larry) * |
Date: 2013-08-08 09:34 |
Okay then, closing.
|
msg194763 - (view) |
Author: Antoine Pitrou (pitrou) * |
Date: 2013-08-09 20:15 |
The Windows buildbots are broken:
======================================================================
ERROR: test_chown_uid_gid_arguments_must_be_index (test.test_os.MakedirTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "E:\Data\buildslave\cpython\3.x.snakebite-win2k3r2sp2-x86\build\lib\test\test_os.py", line 875, in test_chown_uid_gid_arguments_must_be_index
self.assertRaises(TypeError, os.chown, support.TESTFN, value, gid)
AttributeError: 'module' object has no attribute 'chown'
|
msg194857 - (view) |
Author: Roundup Robot (python-dev) |
Date: 2013-08-11 00:59 |
New changeset 9b0e9e9812f8 by Terry Jan Reedy in branch 'default':
Issue #15301: skip new test method so Windows builtbots stop failing.
http://hg.python.org/cpython/rev/9b0e9e9812f8
|
msg194858 - (view) |
Author: Terry J. Reedy (terry.reedy) * |
Date: 2013-08-11 01:03 |
This was the only failure on 2 of 4 buildbots when I last looked.
test_os has several methods like this:
def test_dup2(self):
if hasattr(os, "dup2"):
self.check(os.dup2, 20)
Should the hasattr be moved to skipUnless for all of these?
They now 'pass' without the needed os method.
|
msg194860 - (view) |
Author: Benjamin Peterson (benjamin.peterson) * |
Date: 2013-08-11 01:55 |
Likely they were written before the invention of unittest test
skpping. They could be converted.
2013/8/10 Terry J. Reedy <report@bugs.python.org>:
>
> Terry J. Reedy added the comment:
>
> This was the only failure on 2 of 4 buildbots when I last looked.
>
> test_os has several methods like this:
>
> def test_dup2(self):
> if hasattr(os, "dup2"):
> self.check(os.dup2, 20)
>
> Should the hasattr be moved to skipUnless for all of these?
> They now 'pass' without the needed os method.
>
> ----------
> nosy: +terry.reedy
> status: open -> closed
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue15301>
> _______________________________________
|
msg194865 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) * |
Date: 2013-08-11 06:18 |
> Likely they were written before the invention of unittest test
skpping. They could be converted.
See issue18702.
|
|
Date |
User |
Action |
Args |
2022-04-11 14:57:32 | admin | set | github: 59506 |
2013-08-11 06:18:31 | serhiy.storchaka | set | messages:
+ msg194865 |
2013-08-11 01:55:05 | benjamin.peterson | set | messages:
+ msg194860 |
2013-08-11 01:03:15 | terry.reedy | set | status: open -> closed nosy:
+ terry.reedy messages:
+ msg194858
|
2013-08-11 00:59:19 | python-dev | set | messages:
+ msg194857 |
2013-08-09 20:15:18 | pitrou | set | status: closed -> open
messages:
+ msg194763 |
2013-08-08 09:34:00 | larry | set | status: open -> closed resolution: fixed messages:
+ msg194655
stage: patch review -> resolved |
2013-08-08 08:39:59 | georg.brandl | set | messages:
+ msg194654 |
2013-08-08 07:35:03 | serhiy.storchaka | set | messages:
+ msg194650 |
2013-08-08 07:32:29 | benjamin.peterson | set | messages:
+ msg194649 |
2013-08-08 07:23:59 | larry | set | messages:
+ msg194647 |
2013-08-08 07:23:02 | python-dev | set | messages:
+ msg194646 |
2013-08-08 06:44:55 | larry | set | nosy:
+ benjamin.peterson messages:
+ msg194645
|
2013-08-06 11:56:51 | serhiy.storchaka | set | messages:
+ msg194534 |
2013-07-02 12:50:34 | Scott.Leerssen | set | nosy:
+ Scott.Leerssen messages:
+ msg192193
|
2013-04-24 07:03:22 | serhiy.storchaka | set | messages:
+ msg187689 |
2013-04-23 23:32:46 | larry | set | files:
+ larry.chown.unsigned.uid.gid.6.diff
messages:
+ msg187677 |
2013-04-22 19:10:17 | larry | set | files:
+ larry.chown.unsigned.uid.gid.5.diff
messages:
+ msg187581 |
2013-04-22 19:07:19 | larry | set | files:
+ larry.chown.unsigned.uid.gid.4.diff
messages:
+ msg187580 |
2013-04-22 18:33:40 | serhiy.storchaka | set | messages:
+ msg187579 |
2013-04-22 18:05:48 | larry | set | messages:
+ msg187576 |
2013-04-16 12:36:13 | larry | set | messages:
+ msg187075 |
2013-04-16 12:35:32 | larry | set | files:
+ larry.chown.unsigned.uid.gid.3.diff |
2013-04-15 19:26:24 | serhiy.storchaka | set | messages:
+ msg187019 |
2013-04-15 11:17:46 | larry | set | messages:
+ msg186974 |
2013-04-15 10:53:50 | mark.dickinson | set | messages:
+ msg186971 |
2013-04-15 10:01:47 | larry | set | files:
+ larry.chown.unsigned.uid.gid.2.diff
messages:
+ msg186970 |
2013-04-14 11:30:26 | larry | set | nosy:
+ georg.brandl messages:
+ msg186913
|
2013-04-14 10:54:38 | serhiy.storchaka | set | messages:
+ msg186909 |
2013-04-13 21:58:30 | mark.dickinson | set | nosy:
+ mark.dickinson messages:
+ msg186862
|
2013-02-20 17:53:44 | python-dev | set | nosy:
+ python-dev messages:
+ msg182533
|
2013-02-18 21:57:07 | serhiy.storchaka | set | stage: patch review |
2013-02-14 11:33:08 | serhiy.storchaka | set | files:
+ posix_uid_gid_conv_index.patch versions:
+ Python 3.2, Python 3.3, Python 3.4 nosy:
+ skrah
messages:
+ msg182089
|
2013-02-14 11:24:36 | serhiy.storchaka | set | files:
+ posix_uid_gid_conv_tests.patch nosy:
+ serhiy.storchaka messages:
+ msg182088
|
2012-07-15 01:14:41 | larry | set | files:
+ larry.chown.unsigned.uid.gid.1.diff
nosy:
+ loewis, pitrou messages:
+ msg165481
keywords:
+ patch |
2012-07-15 00:48:08 | larry | set | messages:
+ msg165477 |
2012-07-14 06:17:23 | larry | set | assignee: larry messages:
+ msg165433 |
2012-07-14 00:40:00 | ned.deily | set | messages:
+ msg165431 |
2012-07-14 00:37:53 | larry | set | messages:
+ msg165430 |
2012-07-14 00:29:46 | Arfrever | set | nosy:
+ Arfrever
|
2012-07-14 00:22:00 | do1 | set | messages:
+ msg165429 |
2012-07-14 00:15:51 | larry | set | messages:
+ msg165428 |
2012-07-13 23:34:22 | ned.deily | set | nosy:
+ vstinner, ned.deily messages:
+ msg165427
|
2012-07-13 23:22:08 | Mark.Shannon | set | nosy:
+ Mark.Shannon, larry type: behavior messages:
+ msg165425
|
2012-07-09 02:26:35 | do1 | set | messages:
+ msg165054 |
2012-07-09 02:15:39 | do1 | create | |