Bug #3782
closed
ksh93's builtin chown fails with numeric ids
Added by Garrett D'Amore about 9 years ago.
Updated about 1 year ago.
Category:
cmd - userland programs
Description
When I want to chown a file using numeric ids, which don't exist in the passwd file, the builtin chown falls down badly. However, /usr/bin/chown is fine with it. (So is xpg4/chown)
$ chown -h 433:434 /tmp/x
chown: /tmp/x: cannot change owner and group [Invalid argument]
$ ls -lad /tmp/x
lrwxrwxrwx 1 garrett staff 6 May 20 03:37 /tmp/x -> /tmp/g
$ /usr/bin/chown -h 433:434 /tmp/x
$ ls -lad /tmp/x
$ /usr/xpg4/bin/chown -h 433:437 /tmp/x
$ ls -lad /tmp/x
lrwxrwxrwx 1 433 437 6 May 20 03:37 /tmp/x -> /tmp/g
This busts using the builtin chown. This affects folks who want to use these builtins to get a speed boost (no fork/exec), and are using it to do image building (as I am), where the users don't exist in the system files.
Bug passed to upstream. May take a week or two to get feedback because the AST and UWIN projects are currently under lockdown to merge several project branches into the mainline.
- Category set to cmd - userland programs
- Status changed from New to In Progress
- Assignee set to Andy Fiddaman
- Tags deleted (
needs-triage)
This is being caused by libast's struid()
(strgid()
) functions which convert a name to a uid (gid).
When a name is not found, the functions return -1. If the same name is looked up again, they return -2.
The code for the chown/chgrp builtin doesn't expect the -2 return value and tries to use it as the uid/gid.
The first invocation of a number chown/chgrp works, the second with the same UID does not.
bloody% pfksh
af@bloody:~/ksh$ builtin chown
af@bloody:~/ksh$ chown -h 433 bob.3867
af@bloody:~/ksh$ chown -h 433 bob.3867
chown: /tmp/file: cannot change owner [Invalid argument]
chown("/tmp/bob.3867", 433, 0) = 0
chown("/tmp/bob.3867", 4294967294, 0) Err#22 EINVAL
I tested this fix by using the builtin chown to repeatedly apply a number UID, GID and combination of the two.
Without restarting the shell, it is now possible to re-use the same ID where it was not before.
I also ran the ksh testsuite and the results are unchanged between runs before and after this change.
- Status changed from In Progress to Closed
- % Done changed from 0 to 100
git commit 4162633a7c5961f388fdc51bcecb3016104b359f
commit 4162633a7c5961f388fdc51bcecb3016104b359f
Author: Andy Fiddaman <omnios@citrus-it.co.uk>
Date: 2021-03-16T15:24:36.000Z
3782 ksh93's builtin chown fails with numeric ids
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Robert Mustacchi <rm@fingolfin.org>
Approved by: Dan McDonald <danmcd@joyent.com>
Also available in: Atom
PDF