]> source.dussan.org Git - rspamd.git/commitdiff
Sanitize NULL values for fuzzy backend.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 13 Oct 2015 08:26:40 +0000 (09:26 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 13 Oct 2015 08:26:40 +0000 (09:26 +0100)
src/libserver/fuzzy_backend.c

index dad109819fc4c2ef2228ee880eb55f3188914278..9d1176fe37697e0c0d2d4c54125345bc95a0a4e4 100644 (file)
@@ -536,6 +536,10 @@ rspamd_fuzzy_backend_check (struct rspamd_fuzzy_backend *backend,
                cur_cnt, max_cnt;
        const char *digest;
 
+       if (backend == NULL) {
+               return rep;
+       }
+
        /* Try direct match first of all */
        rc = rspamd_fuzzy_backend_run_stmt (backend, RSPAMD_FUZZY_BACKEND_CHECK,
                        cmd->digest);
@@ -645,6 +649,10 @@ rspamd_fuzzy_backend_add (struct rspamd_fuzzy_backend *backend,
        gint64 id;
        const struct rspamd_fuzzy_shingle_cmd *shcmd;
 
+       if (backend == NULL) {
+               return FALSE;
+       }
+
        rc = rspamd_fuzzy_backend_run_stmt (backend, RSPAMD_FUZZY_BACKEND_CHECK,
                                cmd->digest);
 
@@ -684,6 +692,10 @@ rspamd_fuzzy_backend_del (struct rspamd_fuzzy_backend *backend,
 {
        int rc;
 
+       if (backend == NULL) {
+               return FALSE;
+       }
+
        rc = rspamd_fuzzy_backend_run_stmt (backend, RSPAMD_FUZZY_BACKEND_DELETE,
                        cmd->digest);
 
@@ -702,6 +714,10 @@ rspamd_fuzzy_backend_sync (struct rspamd_fuzzy_backend *backend,
                gint64 number;
        };
 
+       if (backend == NULL) {
+               return FALSE;
+       }
+
        /* Do not do more than 5k ops per step */
        const guint64 max_changes = 5000;
        gboolean ret = FALSE;
@@ -794,7 +810,7 @@ rspamd_fuzzy_backend_sync (struct rspamd_fuzzy_backend *backend,
                        backend, NULL);
        }
        else {
-               msg_warn_fuzzy_backend ("cannot synchronise fuzzy backend: %e", err);
+               msg_warn_fuzzy_backend ("cannot synchronize fuzzy backend: %e", err);
                g_error_free (err);
        }
 
@@ -806,6 +822,9 @@ void
 rspamd_fuzzy_backend_close (struct rspamd_fuzzy_backend *backend)
 {
        if (backend != NULL) {
+               rspamd_fuzzy_backend_run_simple (RSPAMD_FUZZY_BACKEND_TRANSACTION_COMMIT,
+                               backend, NULL);
+
                if (backend->db != NULL) {
                        rspamd_fuzzy_backend_close_stmts (backend);
                        sqlite3_close (backend->db);
@@ -827,11 +846,11 @@ rspamd_fuzzy_backend_close (struct rspamd_fuzzy_backend *backend)
 gsize
 rspamd_fuzzy_backend_count (struct rspamd_fuzzy_backend *backend)
 {
-       return backend->count;
+       return backend != NULL ? backend->count : 0;
 }
 
 gsize
 rspamd_fuzzy_backend_expired (struct rspamd_fuzzy_backend *backend)
 {
-       return backend->expired;
+       return backend != NULL ? backend->expired : 0;
 }