Subject: cp copying perms of setuid source without -p: is this a bug?
To: None <>
From: Jed Davis <>
List: tech-userlevel
Date: 05/10/2005 03:56:16
It goes something like this:

  hostname# ls -l /dev/null                       
  crw-rw-rw-  1 root  wheel  2, 2 May  9 18:33 /dev/null
  hostname# cp /usr/libexec/ssh-keysign /dev/null
  hostname# ls -l /dev/null                      
  cr-sr-xr-x  1 root  wheel  2, 2 May  9 23:25 /dev/null

The code responsible is in src/bin/cp/utils.c, lines 184-200 in r1.27;
the purpose of that being apparently to handle setuid bits safely.
However, it seems to me that, if pflag==0, then there's no point to any
of this and it should all be skipped --- rather than skipping only the
setfile() and proceeding into the tests for the source's having been
set[ug]id and the ensuing fchmod().

However, that code goes back to the beginning of NetBSD's CVS history, so
I felt I should ask about this first rather than immediately filing a PR.

(let ((C call-with-current-continuation)) (apply (lambda (x y) (x y)) (map
((lambda (r) ((C C) (lambda (s) (r (lambda l (apply (s s) l))))))  (lambda
(f) (lambda (l) (if (null? l) C (lambda (k) (display (car l)) ((f (cdr l))
(C k)))))))    '((#\J #\d #\D #\v #\s) (#\e #\space #\a #\i #\newline)))))