Fix more asprintf errors and error code paths.
authorJeremy Allison <jeremy@jeremy-desktop.(none)>
Tue, 23 Dec 2008 19:27:19 +0000 (11:27 -0800)
committerJeremy Allison <jeremy@jeremy-desktop.(none)>
Tue, 23 Dec 2008 19:27:19 +0000 (11:27 -0800)
Jeremy.

source3/libads/ldap.c
source3/libads/ldap_printer.c
source3/printing/nt_printing.c

index cf8a7eb..a598580 100644 (file)
@@ -603,7 +603,10 @@ got_connection:
                /* Must use the userPrincipalName value here or sAMAccountName
                   and not servicePrincipalName; found by Guenther Deschner */
 
-               asprintf(&ads->auth.user_name, "%s$", global_myname() );
+               if (asprintf(&ads->auth.user_name, "%s$", global_myname() ) == -1) {
+                       DEBUG(0,("ads_connect: asprintf fail.\n"));
+                       ads->auth.user_name = NULL;
+               }
        }
 
        if (!ads->auth.realm) {
@@ -619,10 +622,11 @@ got_connection:
        /* this is a really nasty hack to avoid ADS DNS problems. It needs a patch
           to MIT kerberos to work (tridge) */
        {
-               char *env;
-               asprintf(&env, "KRB5_KDC_ADDRESS_%s", ads->config.realm);
-               setenv(env, ads->auth.kdc_server, 1);
-               free(env);
+               char *env = NULL;
+               if (asprintf(&env, "KRB5_KDC_ADDRESS_%s", ads->config.realm) > 0) {
+                       setenv(env, ads->auth.kdc_server, 1);
+                       free(env);
+               }
        }
 #endif
 
index 0a42f00..169c3bb 100644 (file)
@@ -31,7 +31,7 @@
                                       const char *servername)
 {
        ADS_STATUS status;
-       char *srv_dn, **srv_cn, *s;
+       char *srv_dn, **srv_cn, *s = NULL;
        const char *attrs[] = {"*", "nTSecurityDescriptor", NULL};
 
        status = ads_find_machine_acct(ads, res, servername);
                return status;
        }
        if (ads_count_replies(ads, *res) != 1) {
+               if (res) {
+                       ads_msgfree(ads, *res);
+                       *res = NULL;
+               }
                return ADS_ERROR(LDAP_NO_SUCH_OBJECT);
        }
        srv_dn = ldap_get_dn(ads->ldap.ld, *res);
        if (srv_dn == NULL) {
+               if (res) {
+                       ads_msgfree(ads, *res);
+                       *res = NULL;
+               }
                return ADS_ERROR(LDAP_NO_MEMORY);
        }
        srv_cn = ldap_explode_dn(srv_dn, 1);
        if (srv_cn == NULL) {
                ldap_memfree(srv_dn);
+               if (res) {
+                       ads_msgfree(ads, *res);
+                       *res = NULL;
+               }
                return ADS_ERROR(LDAP_INVALID_DN_SYNTAX);
        }
-       ads_msgfree(ads, *res);
+       if (res) {
+               ads_msgfree(ads, *res);
+               *res = NULL;
+       }
 
-       asprintf(&s, "(cn=%s-%s)", srv_cn[0], printer);
+       if (asprintf(&s, "(cn=%s-%s)", srv_cn[0], printer) == -1) {
+               ldap_memfree(srv_dn);
+               return ADS_ERROR(LDAP_NO_MEMORY);
+       }
        status = ads_search(ads, res, s, attrs);
 
        ldap_memfree(srv_dn);
        ldap_value_free(srv_cn);
-       free(s);
+       SAFE_FREE(s);
        return status;  
 }
 
index ba1fb43..2b24fdd 100644 (file)
@@ -3381,7 +3381,7 @@ static WERROR nt_printer_unpublish_ads(ADS_STRUCT *ads,
                                        NT_PRINTER_INFO_LEVEL *printer)
 {
        ADS_STATUS ads_rc;
-       LDAPMessage *res;
+       LDAPMessage *res = NULL;
        char *prt_dn = NULL;
 
        DEBUG(5, ("unpublishing printer %s\n", printer->info_2->printername));
@@ -3390,7 +3390,7 @@ static WERROR nt_printer_unpublish_ads(ADS_STRUCT *ads,
        ads_rc = ads_find_printer_on_server(ads, &res, 
                            printer->info_2->sharename, global_myname());
 
-       if (ADS_ERR_OK(ads_rc) && ads_count_replies(ads, res)) {
+       if (ADS_ERR_OK(ads_rc) && res && ads_count_replies(ads, res)) {
                prt_dn = ads_get_dn(ads, res);
                if (!prt_dn) {
                        ads_msgfree(ads, res);
@@ -3400,7 +3400,9 @@ static WERROR nt_printer_unpublish_ads(ADS_STRUCT *ads,
                ads_memfree(ads, prt_dn);
        }
 
-       ads_msgfree(ads, res);
+       if (res) {
+               ads_msgfree(ads, res);
+       }
        return WERR_OK;
 }