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