mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-21 15:33:33 +08:00
gdb/
* remote-file.io.c (remote_fileio_func_system): Treat zero length string as NULL. Adjust for NULL pointer argument. * doc/gdb.texinfo (system): Document behaviour with zero length string. gdb/testsuite/ * gdb.base/fileio.c: Add system(NULL) test. * gdb.base/fileio.exp: Check it.
This commit is contained in:
parent
e1c2defab5
commit
5600ea19e0
@ -1,3 +1,10 @@
|
||||
2006-06-13 Nathan Sidwell <nathan@codesourcery.com>
|
||||
|
||||
* remote-file.io.c (remote_fileio_func_system): Treat zero length
|
||||
string as NULL. Adjust for NULL pointer argument.
|
||||
* doc/gdb.texinfo (system): Document behaviour with zero length
|
||||
string.
|
||||
|
||||
2006-06-12 Daniel Jacobowitz <dan@codesourcery.com>
|
||||
|
||||
* remote.c (set_remote_protocol_packet_cmd)
|
||||
|
@ -24752,11 +24752,13 @@ int system(const char *command);
|
||||
@samp{Fsystem,@var{commandptr}/@var{len}}
|
||||
|
||||
@item Return value:
|
||||
The value returned is -1 on error and the return status
|
||||
of the command otherwise. Only the exit status of the
|
||||
command is returned, which is extracted from the host's
|
||||
@code{system} return value by calling @code{WEXITSTATUS(retval)}.
|
||||
In case @file{/bin/sh} could not be executed, 127 is returned.
|
||||
If @var{len} is zero, the return value indicates whether a shell is
|
||||
available. A zero return value indicates a shell is not available.
|
||||
For non-zero @var{len}, the value returned is -1 on error and the
|
||||
return status of the command otherwise. Only the exit status of the
|
||||
command is returned, which is extracted from the host's @code{system}
|
||||
return value by calling @code{WEXITSTATUS(retval)}. In case
|
||||
@file{/bin/sh} could not be executed, 127 is returned.
|
||||
|
||||
@item Errors:
|
||||
|
||||
|
@ -1278,16 +1278,7 @@ remote_fileio_func_system (char *buf)
|
||||
{
|
||||
CORE_ADDR ptrval;
|
||||
int ret, length, retlength;
|
||||
char *cmdline;
|
||||
|
||||
/* Check if system(3) has been explicitely allowed using the
|
||||
`set remote system-call-allowed 1' command. If not, return
|
||||
EPERM */
|
||||
if (!remote_fio_system_call_allowed)
|
||||
{
|
||||
remote_fileio_reply (-1, FILEIO_EPERM);
|
||||
return;
|
||||
}
|
||||
char *cmdline = NULL;
|
||||
|
||||
/* Parameter: Ptr to commandline / length incl. trailing zero */
|
||||
if (remote_fileio_extract_ptr_w_len (&buf, &ptrval, &length))
|
||||
@ -1295,19 +1286,38 @@ remote_fileio_func_system (char *buf)
|
||||
remote_fileio_ioerror ();
|
||||
return;
|
||||
}
|
||||
/* Request commandline using 'm' packet */
|
||||
cmdline = alloca (length);
|
||||
retlength = remote_read_bytes (ptrval, (gdb_byte *) cmdline, length);
|
||||
if (retlength != length)
|
||||
|
||||
if (length)
|
||||
{
|
||||
remote_fileio_ioerror ();
|
||||
/* Request commandline using 'm' packet */
|
||||
cmdline = alloca (length);
|
||||
retlength = remote_read_bytes (ptrval, (gdb_byte *) cmdline, length);
|
||||
if (retlength != length)
|
||||
{
|
||||
remote_fileio_ioerror ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if system(3) has been explicitely allowed using the
|
||||
`set remote system-call-allowed 1' command. If length is 0,
|
||||
indicating a NULL parameter to the system call, return zero to
|
||||
indicate a shell is not available. Otherwise fail with EPERM. */
|
||||
if (!remote_fio_system_call_allowed)
|
||||
{
|
||||
if (!length)
|
||||
remote_fileio_return_success (0);
|
||||
else
|
||||
remote_fileio_reply (-1, FILEIO_EPERM);
|
||||
return;
|
||||
}
|
||||
|
||||
remote_fio_no_longjmp = 1;
|
||||
ret = system (cmdline);
|
||||
|
||||
if (ret == -1)
|
||||
if (!length)
|
||||
remote_fileio_return_success (ret);
|
||||
else if (ret == -1)
|
||||
remote_fileio_return_errno (-1);
|
||||
else
|
||||
remote_fileio_return_success (WEXITSTATUS (ret));
|
||||
|
@ -1,5 +1,8 @@
|
||||
2006-06-13 Nathan Sidwell <nathan@codesourcery.com>
|
||||
|
||||
* gdb.base/fileio.c: Add system(NULL) test.
|
||||
* gdb.base/fileio.exp: Check it.
|
||||
|
||||
* gdb.base/break.c: Add 10a breakpoint at }
|
||||
* gdb.base/break.exp: Add test for breakpoint at }
|
||||
* gdb.cp/anon-union.cc: Add code at end of function.
|
||||
|
@ -373,17 +373,21 @@ test_system ()
|
||||
int ret;
|
||||
char sys[512];
|
||||
|
||||
/* Test for shell */
|
||||
ret = system (NULL);
|
||||
printf ("system 1: ret = %d %s\n", ret, ret != 0 ? "OK" : "");
|
||||
stop ();
|
||||
/* This test prepares the directory for test_rename() */
|
||||
sprintf (sys, "mkdir -p %s %s", TESTSUBDIR, TESTDIR2);
|
||||
ret = system (sys);
|
||||
if (ret == 127)
|
||||
printf ("system 1: ret = %d /bin/sh unavailable???\n", ret);
|
||||
printf ("system 2: ret = %d /bin/sh unavailable???\n", ret);
|
||||
else
|
||||
printf ("system 1: ret = %d %s\n", ret, ret == 0 ? "OK" : "");
|
||||
printf ("system 2: ret = %d %s\n", ret, ret == 0 ? "OK" : "");
|
||||
stop ();
|
||||
/* Invalid command (just guessing ;-) ) */
|
||||
ret = system ("wrtzlpfrmpft");
|
||||
printf ("system 2: ret = %d %s\n", ret, WEXITSTATUS (ret) == 127 ? "OK" : "");
|
||||
printf ("system 3: ret = %d %s\n", ret, WEXITSTATUS (ret) == 127 ? "OK" : "");
|
||||
stop ();
|
||||
}
|
||||
|
||||
|
@ -180,14 +180,18 @@ gdb_test continue \
|
||||
"Continuing\\..*isatty 5:.*OK$stop_msg" \
|
||||
"Isatty (open file)"
|
||||
|
||||
send_gdb "set remote system-call-allowed 1\n"; gdb_expect -re ".*$gdb_prompt $"
|
||||
gdb_test continue \
|
||||
"Continuing\\..*system 1:.*OK$stop_msg" \
|
||||
"System says shell is available"
|
||||
|
||||
send_gdb "set remote system-call-allowed 1\n"; gdb_expect -re ".*$gdb_prompt $"
|
||||
gdb_test continue \
|
||||
"Continuing\\..*system 2:.*OK$stop_msg" \
|
||||
"System(3) call"
|
||||
|
||||
# Is this ok? POSIX says system returns a waitpid status?
|
||||
gdb_test continue \
|
||||
"Continuing\\..*system 2:.*OK$stop_msg" \
|
||||
"Continuing\\..*system 3:.*OK$stop_msg" \
|
||||
"System with invalid command returns 127"
|
||||
|
||||
gdb_test continue \
|
||||
|
Loading…
Reference in New Issue
Block a user