Fixed crash (NULL pointer dereference)
[mirrors/libpurple-core-answerscripts.git] / answerscripts.c
index d562e51..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;
        }
@@ -84,7 +84,7 @@ static void received_im_msg_cb(PurpleAccount *account, char *who, char *buffer,
        */
 
        //Get buddy group
-       const char *from_group = purple_group_get_name(purple_buddy_get_group(buddy));
+       const char *from_group = purple_group_get_name(purple_buddy_get_group(buddy)); //FIXME: returns "\x18" when user does not belong to some group
 
        //Get protocol ID
        const char *protocol_id = purple_account_get_protocol_id(account);
@@ -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.118322 seconds and 4 git commands to generate.