Fixed segmentation fault in command history.
authorDaniel Carl <danielcarl@gmx.de>
Sun, 14 Apr 2013 18:15:34 +0000 (20:15 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Sun, 14 Apr 2013 18:19:24 +0000 (20:19 +0200)
If the history contained any item with printf placeholders like %s we got a
segmentation fault if we print the value to the user. This patch use a
dedicated format string for all user generated contents to be shown with
vb_echo and vb_echo_force.

src/command.c
src/main.c

index fa5ee77..cdfb389 100644 (file)
@@ -247,10 +247,10 @@ gboolean command_input(const Arg *arg)
     ) {
         /* append the current url to the input message */
         char *input = g_strconcat(arg->s, url, NULL);
-        vb_echo_force(VB_MSG_NORMAL, false, input);
+        vb_echo_force(VB_MSG_NORMAL, false, "%s", input);
         g_free(input);
     } else {
-        vb_echo_force(VB_MSG_NORMAL, false, arg->s);
+        vb_echo_force(VB_MSG_NORMAL, false, "%s", arg->s);
     }
 
     vb_set_mode(VB_MODE_COMMAND, false);
@@ -415,7 +415,7 @@ gboolean command_inspect(const Arg *arg)
 
 gboolean command_hints(const Arg *arg)
 {
-    vb_echo_force(VB_MSG_NORMAL, false, arg->s);
+    vb_echo_force(VB_MSG_NORMAL, false, "%s", arg->s);
     /* mode will be set in hints_create - so we don't neet to do it here */
     hints_create(NULL, arg->i, (arg->s ? strlen(arg->s) : 0));
 
@@ -597,7 +597,7 @@ gboolean command_history(const Arg *arg)
         return false;
     }
 
-    vb_echo_force(VB_MSG_NORMAL, false, entry);
+    vb_echo_force(VB_MSG_NORMAL, false, "%s", entry);
     g_free(entry);
 
     return true;
@@ -619,9 +619,9 @@ gboolean command_eval(const Arg *arg)
         webkit_web_view_get_main_frame(vb.gui.webview), arg->s, NULL, &value
     );
     if (success) {
-        vb_echo_force(VB_MSG_NORMAL, false, value);
+        vb_echo_force(VB_MSG_NORMAL, false, "%s", value);
     } else {
-        vb_echo_force(VB_MSG_ERROR, true, value);
+        vb_echo_force(VB_MSG_ERROR, true, "%s", value);
     }
     g_free(value);
     vb_set_mode(VB_MODE_NORMAL, false);
index bfa2683..cb0e14a 100644 (file)
@@ -74,7 +74,7 @@ static void set_status(const StatusType status);
 void inputbox_print(gboolean force, const MessageType type, gboolean hide, const char *message);
 static void destroy_client();
 
-void vb_echo_force(const MessageType type,gboolean hide, const char *error, ...)
+void vb_echo_force(const MessageType type, gboolean hide, const char *error, ...)
 {
     char message[255];
     va_list arg_list;