Fixed crash (NULL pointer dereference)
[mirrors/libpurple-core-answerscripts.git] / answerscripts.c
index a85717e..54b7576 100755 (executable)
@@ -40,7 +40,7 @@ typedef struct {
 
 int answerscripts_process_message_cb(answerscripts_job *job) {
        int i;
-       char response[ANSWERSCRIPTS_LINE_LENGTH+1];
+       char response[ANSWERSCRIPTS_LINE_LENGTH+1]; response[0]='\0';
        FILE *pipe = job->pipe;
        PurpleConversation *conv = job->conv;
 
@@ -50,7 +50,7 @@ int answerscripts_process_message_cb(answerscripts_job *job) {
                ) return 1;
 
                for(i=0;response[i];i++) if(response[i]=='\n') response[i]=0;
-               purple_conv_im_send(purple_conversation_get_im_data(conv), response);
+               if(response[0]!='\0') purple_conv_im_send(purple_conversation_get_im_data(conv), response);
 
                if(!feof(pipe)) return 1;
        }
@@ -117,6 +117,10 @@ static void received_im_msg_cb(PurpleAccount *account, char *who, char *buffer,
        //Launch job on background
        answerscripts_job *job = (answerscripts_job*) malloc(sizeof(answerscripts_job));
        job->pipe = popen(hook_script, "r");
+       if(job->pipe == NULL) {
+               fprintf(stderr,"Can't execute %s\n", hook_script);
+               return;
+       }
        job->conv = conv;
 
        #ifndef __WIN32__
This page took 0.11078 seconds and 4 git commands to generate.