Project

General

Profile

Actions

Bug #3782

closed

ksh93's builtin chown fails with numeric ids

Added by Garrett D'Amore over 8 years ago. Updated 7 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
cmd - userland programs
Start date:
2013-05-22
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

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.

Actions #1

Updated by Irek Szczesniak over 8 years ago

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.

Actions #2

Updated by Andy Fiddaman 8 months ago

  • Category set to cmd - userland programs
  • Status changed from New to In Progress
  • Assignee set to Andy Fiddaman
  • Tags deleted (needs-triage)
Actions #3

Updated by Electric Monk 8 months ago

  • Gerrit CR set to 1318
Actions #4

Updated by Andy Fiddaman 8 months ago

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
Actions #5

Updated by Andy Fiddaman 7 months ago

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.

Actions #6

Updated by Electric Monk 7 months ago

  • 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>

Actions

Also available in: Atom PDF