gdb/
authorNathan Sidwell <nathan@codesourcery.com>
Tue, 13 Jun 2006 08:55:22 +0000 (08:55 +0000)
committerNathan Sidwell <nathan@codesourcery.com>
Tue, 13 Jun 2006 08:55:22 +0000 (08:55 +0000)
* 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/ChangeLog
gdb/doc/gdb.texinfo
gdb/remote-fileio.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/fileio.c
gdb/testsuite/gdb.base/fileio.exp

index 1e9ccc4..a33484f 100644 (file)
@@ -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)
index 47e8d2c..6935d82 100644 (file)
@@ -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:
 
index d445d40..6089926 100644 (file)
@@ -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));
index 7695bca..4e4fb35 100644 (file)
@@ -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.
index f0883c6..3910da5 100644 (file)
@@ -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 ();
 }
 
index 1da8b16..01eff55 100644 (file)
@@ -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 \