]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/fulltext/serv_fulltext.c
Check for NULL pointer before passing it into qsort & free
[citadel.git] / citadel / modules / fulltext / serv_fulltext.c
index e2dfd146614a429fc81da8584f888ca007e661a4..3fa22d781618b3cb3ba93a13336ee71372daccaf 100644 (file)
@@ -143,7 +143,7 @@ void ft_index_message(long msgnum, int op) {
        msgtext = CC->redirect_buffer;
        CC->redirect_buffer = NULL;
        syslog(LOG_DEBUG, "Wordbreaking message %ld...", msgnum);
-       if (StrLength(CC->redirect_buffer) == 0) {
+       if ((msgtext == NULL) || (StrLength(msgtext) == 0)) {
                syslog(LOG_ALERT, "This message has a zero length.  Probable data corruption.");
        }
        txt = SmashStrBuf(&msgtext);
@@ -415,7 +415,8 @@ void ft_search(int *fts_num_msgs, long **fts_msgs, const char *search_string) {
 
                }
                free(tokens);
-               qsort(all_msgs, num_all_msgs, sizeof(long), longcmp);
+               if (all_msgs != NULL)
+                       qsort(all_msgs, num_all_msgs, sizeof(long), longcmp);
 
                /*
                 * At this point, if a message appears num_tokens times in the
@@ -435,8 +436,8 @@ void ft_search(int *fts_num_msgs, long **fts_msgs, const char *search_string) {
 
                        }
                }
-
-               free(all_msgs);
+               if (all_msgs != NULL)
+                       free(all_msgs);
        }
 
        *fts_num_msgs = num_ret_msgs;
@@ -508,6 +509,6 @@ CTDL_MODULE_INIT(fulltext)
                CtdlRegisterCleanupHook(noise_word_cleanup);
                CtdlRegisterSessionHook(do_fulltext_indexing, EVT_TIMER);
        }
-       /* return our Subversion id for the Log */
+       /* return our module name for the log */
        return "fulltext";
 }