Re: Problem with system()
Re: Problem with system()
- Subject: Re: Problem with system()
- From: Terry Lambert <email@hidden>
- Date: Fri, 6 Jul 2007 13:38:26 -0700
On Jul 6, 2007, at 12:08 PM, chas williams - CONTRACTOR wrote:
In message <email@hidden
>,Nor
m Green writes:
int rc = system("date >/usr/tmp/tmp.kPCvVa");
If fails with rc == 256 and errno == 0 and prints this to stderr:
sh: line 1: 1: Bad file descriptor
I know the path is OK because the file /usr/tmp/tmp.kPCvVa *IS*
created, but
it has a size of zero.
the shell handles the redirection and creates the output file so its
not really an indicator that your path is ok. its a bad idea to just
call 'date' and not give the full path since some user program called
date (and someone somwhere has probably done this) would interfere
with proper behavior.
For this particular case, you are most likely correct, and it's the
raw "date" that's not being correctly interpreted in his code.
The system() library routine operates by doing a:
execl( "/bin/sh", "-c", "date >/usr/tmp/tmp.kPCvVa", NULL);
_exit(127); /* not reached normally */
Since he is getting back what he is getting back (256 - btw, the
correct way to decode this is using the macros used by waitpid() - see
the man page), then it's most likely a bad fd.
I expect that either "date" is not in the default shell path, or he is
invoking this as root (in which case, security dictates that his path
be cleaned out on him by the shell program), or his default path is
bogus, or he has built and replaced /bin/sh with his own code, or
linked it to another sell program, other than the MacOS X default,
which is a specifically modified "bash".
Probably setting the "date" to "/bin/date" instead would fix this: The
bad fd the shell is complaining about is likely the fd in the fread()
of the popen() of the date command, built into the shell, and the
difference is whether or not stack pages contain "bad garbage" or
"good garbage" in the shell itself (as Justin Walker pointed out might
be the case).
Note that if he is running this program as root, and there are local
accounts, it would be rather trivial to get root on the machine as an
ordinary unprivileged user account using this program as is...
-- Terry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden