aboutsummaryrefslogtreecommitdiff
path: root/gdb/remote-fileio.c
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@codesourcery.com>2006-06-13 08:55:22 +0000
committerNathan Sidwell <nathan@codesourcery.com>2006-06-13 08:55:22 +0000
commit5600ea19e0ff645c85a8719648655c2e7b2e4717 (patch)
tree606de62b7a27178ba351bec8d579244edb0c0ac1 /gdb/remote-fileio.c
parente1c2defab5219dd0aa2a64d865e78d9ac736d0ac (diff)
downloadgdb-5600ea19e0ff645c85a8719648655c2e7b2e4717.zip
gdb-5600ea19e0ff645c85a8719648655c2e7b2e4717.tar.gz
gdb-5600ea19e0ff645c85a8719648655c2e7b2e4717.tar.bz2
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.
Diffstat (limited to 'gdb/remote-fileio.c')
-rw-r--r--gdb/remote-fileio.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c
index d445d40..6089926 100644
--- a/gdb/remote-fileio.c
+++ b/gdb/remote-fileio.c
@@ -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));