r16392: Klockwork #1168. Protect against null deref.
authorJeremy Allison <jra@samba.org>
Tue, 20 Jun 2006 01:25:31 +0000 (01:25 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:18:51 +0000 (11:18 -0500)
Jeremy.
(This used to be commit cab256d72a91f59432e28e9623c10384d9ca2b5e)

source3/printing/printing_db.c

index adea10dfa691b5277152a65f1e63ad1f5a5e3677..c62409c8908223b6bbcfaf5cad7e30ecc3ca5651 100644 (file)
@@ -55,7 +55,9 @@ struct tdb_print_db *get_print_db_byname(const char *printername)
        /* Not found. */
        if (num_open >= MAX_PRINT_DBS_OPEN) {
                /* Try and recycle the last entry. */
-               DLIST_PROMOTE(print_db_head, last_entry);
+               if (print_db_head && last_entry) {
+                       DLIST_PROMOTE(print_db_head, last_entry);
+               }
 
                for (p = print_db_head; p; p = p->next) {
                        if (p->ref_count)
@@ -72,7 +74,7 @@ struct tdb_print_db *get_print_db_byname(const char *printername)
                        memset(p->printer_name, '\0', sizeof(p->printer_name));
                        break;
                }
-               if (p) {
+               if (p && print_db_head) {
                        DLIST_PROMOTE(print_db_head, p);
                        p = print_db_head;
                }