bug 9830: fix panic in nt_printer_publish_ads
authorDavid Disseldorp <ddiss@samba.org>
Thu, 25 Apr 2013 14:01:54 +0000 (16:01 +0200)
committerKarolin Seeger <kseeger@samba.org>
Wed, 8 May 2013 08:09:03 +0000 (10:09 +0200)
Check for ads_find_machine_acct() errors, to ensure a NULL LDAPMessage
pointer doesn't get passed to ldap_get_dn().

Signed-off-by: David Disseldorp <ddiss@samba.org>
(cherry picked from commit dd07b3c4973b169f07d227869dba8d0f4a76569a)

source3/printing/nt_printing_ads.c

index 5a0cd24bb4b7bdd3aab5b0d9587f7cb622b9ec15..219124f8021ce96cd78e16a8d97bf931aea82039 100644 (file)
@@ -192,17 +192,23 @@ static WERROR nt_printer_publish_ads(struct messaging_context *msg_ctx,
        DEBUG(5, ("publishing printer %s\n", printer));
 
        /* figure out where to publish */
-       ads_find_machine_acct(ads, &res, global_myname());
+       ads_rc = ads_find_machine_acct(ads, &res, global_myname());
+       if (!ADS_ERR_OK(ads_rc)) {
+               DEBUG(0, ("failed to find machine account for %s\n",
+                         global_myname()));
+               TALLOC_FREE(ctx);
+               return WERR_NOT_FOUND;
+       }
 
        /* We use ldap_get_dn here as we need the answer
         * in utf8 to call ldap_explode_dn(). JRA. */
 
        srv_dn_utf8 = ldap_get_dn((LDAP *)ads->ldap.ld, (LDAPMessage *)res);
+       ads_msgfree(ads, res);
        if (!srv_dn_utf8) {
                TALLOC_FREE(ctx);
                return WERR_SERVER_UNAVAILABLE;
        }
-       ads_msgfree(ads, res);
        srv_cn_utf8 = ldap_explode_dn(srv_dn_utf8, 1);
        if (!srv_cn_utf8) {
                TALLOC_FREE(ctx);