summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@codesourcery.com>2006-06-09 20:25:26 +0000
committerNathan Sidwell <nathan@codesourcery.com>2006-06-09 20:25:26 +0000
commit9c6bba82bae872da41406b138f56e4ba8ba98bb8 (patch)
treea43993e41ff29f525a2eb228b391f191552712dc
parent799124aeb74dc2d824847684ecc8d0c3cb273f66 (diff)
downloadgdb-9c6bba82bae872da41406b138f56e4ba8ba98bb8.tar.gz
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.
-rw-r--r--ChangeLog.csl10
-rw-r--r--gdb/doc/gdb.texinfo12
-rw-r--r--gdb/remote-fileio.c41
-rw-r--r--gdb/testsuite/gdb.base/fileio.c4
-rw-r--r--gdb/testsuite/gdb.base/fileio.exp4
5 files changed, 50 insertions, 21 deletions
diff --git a/ChangeLog.csl b/ChangeLog.csl
index 95c26490dd6..bc867d44a90 100644
--- a/ChangeLog.csl
+++ b/ChangeLog.csl
@@ -1,5 +1,15 @@
2006-06-09 Nathan Sidwell <nathan@codesourcery.com>
+ 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.
+
gdb/testsuite/
* gdb.cp/anon-union.cc: Add code at end of function.
* gdb.cp/anon-union.exp: Adjust end of function breakpoint.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index b1a75811214..13dd712095b 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -24564,11 +24564,13 @@ int system(const char *command);
Fsystem,commandptr/len
@exdent 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 hosts
-system return value by calling WEXITSTATUS(retval).
-In case /bin/sh could not be executed, 127 is returned.
+If @var{len} is zero, the return value indicates whether a shell is
+available. Zero indicates it is not available and non-zero indicates
+that it is. Otherwise, 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 hosts system return
+value by calling WEXITSTATUS(retval). In case /bin/sh could not be
+executed, 127 is returned.
@exdent Errors:
@end smallexample
diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c
index c9fbb03fb95..952c31875ab 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,37 @@ 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 not, return
+ 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));
diff --git a/gdb/testsuite/gdb.base/fileio.c b/gdb/testsuite/gdb.base/fileio.c
index f0883c62711..1763f50594f 100644
--- a/gdb/testsuite/gdb.base/fileio.c
+++ b/gdb/testsuite/gdb.base/fileio.c
@@ -385,6 +385,10 @@ test_system ()
ret = system ("wrtzlpfrmpft");
printf ("system 2: ret = %d %s\n", ret, WEXITSTATUS (ret) == 127 ? "OK" : "");
stop ();
+ /* Test for shell */
+ ret = system (NULL);
+ printf ("system 3: ret = %d %s\n", ret, ret != 0 ? "OK" : "");
+ stop ();
}
int
diff --git a/gdb/testsuite/gdb.base/fileio.exp b/gdb/testsuite/gdb.base/fileio.exp
index 1da8b16a158..436afb75eb1 100644
--- a/gdb/testsuite/gdb.base/fileio.exp
+++ b/gdb/testsuite/gdb.base/fileio.exp
@@ -191,6 +191,10 @@ gdb_test continue \
"System with invalid command returns 127"
gdb_test continue \
+"Continuing\\..*system 3:.*OK$stop_msg" \
+"System says shell is available"
+
+gdb_test continue \
"Continuing\\..*rename 1:.*OK$stop_msg" \
"Rename a file"