Fixed crash (NULL pointer dereference)
[mirrors/libpurple-core-answerscripts.git] / answerscripts.c
index 7938538..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;
        }
@@ -65,8 +65,6 @@ static void received_im_msg_cb(PurpleAccount *account, char *who, char *buffer,
 
        //Get message
        message = purple_markup_strip_html(buffer);
-       //printf("\nHarvie received: %s: %s\n", who, message); //debug
-       //purple_conv_im_send(purple_conversation_get_im_data(conv), ":-*"); //debug
 
        /* Here are prototypes of some functions interesting to implement github feature request #3
 
@@ -86,11 +84,11 @@ 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);
-       if(!strncmp(protocol_id,PROTOCOL_PREFIX,strlen(PROTOCOL_PREFIX))) protocol_id += strlen(PROTOCOL_PREFIX); //trim out protocol prefix (eg.: "prpl-irc" => "irc")
+       if(!strncmp(protocol_id,PROTOCOL_PREFIX,strlen(PROTOCOL_PREFIX))) protocol_id += strlen(PROTOCOL_PREFIX); //trim out PROTOCOL_PREFIX (eg.: "prpl-irc" => "irc")
 
        //Get status
        PurpleStatus *status = purple_account_get_active_status(account);
@@ -119,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.104561 seconds and 4 git commands to generate.