Subject: | Net::Server::Daemonize::set_uid() sets uid and gid in wrong order for FreeBSD |
Below is an email that I sent to the Author back in May of 2002. I was going through my old patches today and discovered that it looks like this still hasn't been patched or responded to:
Date: Wed, 1 May 2002 18:01:18 -0400 (EDT)
To: <paul@seamons.com>
Subject: Net::Server::Daemonize patch
Mr. Seamons,
Attached is a very simple diff which I have applied to my local install of Net::Server::Daemonize version 0.04. I'm sending it to you for your
consideration.
The problem with the standard distribution version, that that the following line in set_uid:
$< = $> = $uid;
does not appear to work under my OS (FreeBSD 4.3). For proof of concept,
consider the following two segments of code run by user 'root' (uid 0)
attempting to setuid to 'nobody' (uid 65534):
perl5
$< = $> = 65534;
print " $< $> \n";
0 65534
---
perl5
$< = 65534;
$> = 65534;
print " $< $> \n";
65534 65534
It turns out that in FreeBSD, you have to alter your real id BEFORE altering your effective id. Otherwise, the setuid will fail.
The patch I sent you should fix this, and hopefully will not cause a conflict for any other operating systems.
Thank you for your time in considering this solution.
Sincerely,
Daniel J. Wright
202c202,203
< $< = $> = $uid;
---
> $< = $uid;
> $> = $uid;