LP#1436047: make srfsh --safe act as if "! command" doesn't exist
authorGalen Charlton <gmc@esilibrary.com>
Tue, 24 Mar 2015 21:00:57 +0000 (21:00 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Wed, 3 Jun 2015 17:34:02 +0000 (17:34 +0000)
This patch make srfsh treat attempting to run an external
command via "! command" as a parsing error if --safe is
supplied.  It also suppress mention of "! commands" from
the internal help.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>

src/srfsh/srfsh.c

index aed9536..753180b 100644 (file)
@@ -376,8 +376,10 @@ static int process_request( const char* request ) {
                ret_val = handle_close( cmd_array );
 
        else if ( request[0] == '!') {
-               if (!no_bang) system( request + 1 );
-               ret_val = 1;
+               if (!no_bang) {
+                       system( request + 1 );
+                       ret_val = 1;
+               }
        }
 
        osrfStringArrayFree( cmd_array );
@@ -985,8 +987,12 @@ static int print_help( void ) {
                        "---------------------------------------------------------------------------------\n"
                        "General commands:\n"
                        "---------------------------------------------------------------------------------\n"
-                       "help                   - Display this message\n"
-                       "!<command> [args]      - Forks and runs the given command in the shell\n"
+                       "help                   - Display this message\n",
+                       stdout );
+       if (!no_bang) fputs(
+                       "!<command> [args]      - Forks and runs the given command in the shell\n",
+                       stdout );
+       fputs(
                /*
                        "time                   - Prints the current time\n"
                        "time <timestamp>       - Formats seconds since epoch into readable format\n"