summaryrefslogtreecommitdiffstats
path: root/source/script-dialog.c
diff options
context:
space:
mode:
authorQC <qball@gmpclient.org>2014-11-22 21:39:34 +0100
committerQC <qball@gmpclient.org>2014-11-22 21:39:34 +0100
commit18c6186501db5a729851ead5c5fcf38935f52a05 (patch)
tree7fd478f2667dc4c2805ebd9f746f091b9371d57a /source/script-dialog.c
parent66349a00dcb116e945250b633c4cc2793affe7bf (diff)
Possible fix for issue #90.
* Escape the argument passed to the script. * Escape '\"
Diffstat (limited to 'source/script-dialog.c')
-rw-r--r--source/script-dialog.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/source/script-dialog.c b/source/script-dialog.c
index 0e6009bd..fe487035 100644
--- a/source/script-dialog.c
+++ b/source/script-dialog.c
@@ -99,12 +99,49 @@ static char **get_script_output ( char *command, unsigned int *length )
return retv;
}
+// There should be a glib version for this.
+// Fixing.
+char *escape_string ( const char *string )
+{
+ int new_length = 0;
+ int length = strlen ( string );
+
+ // Characters to escape
+ const char echars[] = "'\\ \"";
+ const char num_echars = sizeof ( echars ) / sizeof ( char );
+
+ // Count strings, Calculate new length.
+ for ( int i = 0; i < length; i++ ) {
+ for ( int j = 0; j < num_echars; j++ ) {
+ if ( echars[j] == string[i] ) {
+ new_length++;
+ }
+ }
+ new_length++;
+ }
+ // Create escaped string.
+ char *retv = g_malloc0 ( ( new_length + 1 ) * sizeof ( char ) );
+ new_length = 0;
+ for ( int i = 0; i < length; i++ ) {
+ for ( int j = 0; j < num_echars; j++ ) {
+ if ( echars[j] == string[i] ) {
+ retv[new_length++] = '\\';
+ }
+ }
+ retv[new_length++] = string[i];
+ }
+ return retv;
+}
+
char **execute_executor ( ScriptOptions *options, const char *result, unsigned int *length )
{
- char **retv = NULL;
- char *command = g_strdup_printf ( "%s '%s'", options->script_path, result );
+ char **retv = NULL;
+
+ char *arg = escape_string ( result );
+ char *command = g_strdup_printf ( "%s %s", options->script_path, arg );
retv = get_script_output ( command, length );
g_free ( command );
+ g_free ( arg );
return retv;
}