lib: Make callers of base64_encode_data_blob check for success
authorVolker Lendecke <vl@samba.org>
Tue, 3 May 2016 13:54:07 +0000 (15:54 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 3 May 2016 23:28:23 +0000 (01:28 +0200)
Quite a few callers already did check for !=NULL. With the current code this is
pointless due to a SMB_ASSERT in base64_encode_data_blob() itself. Make the
callers consistently check, so that we can remove SMB_ASSERT from base64.c.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/libnet/libnet_dssync_passdb.c
source3/libnet/libnet_samsync_passdb.c
source3/rpc_server/samr/srv_samr_util.c
source3/utils/ntlm_auth.c
source4/utils/ntlm_auth.c

index 561777688ed87d98bbb7b7ce161988989388c06a..62ce0745cb4e3d1385e3f892cc2e646834da77bf 100644 (file)
@@ -1240,10 +1240,14 @@ static NTSTATUS sam_account_from_object(struct samu *account,
        }
 
        if (userParameters.data) {
-               char *newstr;
+               char *newstr = NULL;
                old_string = pdb_get_munged_dial(account);
-               newstr = (userParameters.length == 0) ? NULL :
-                       base64_encode_data_blob(talloc_tos(), userParameters);
+
+               if (userParameters.length != 0) {
+                       newstr = base64_encode_data_blob(talloc_tos(),
+                                                        userParameters);
+                       SMB_ASSERT(newstr != NULL);
+               }
 
                if (STRING_CHANGED_NC(old_string, newstr))
                        pdb_set_munged_dial(account, newstr, PDB_CHANGED);
index cf5bef18675058eed6fd20ee2f174aaa84b839e9..51857226fc19b643d85da17099a77d8e1419d852 100644 (file)
@@ -126,12 +126,15 @@ static NTSTATUS sam_account_from_delta(struct samu *account,
 
        if (r->parameters.array) {
                DATA_BLOB mung;
-               char *newstr;
+               char *newstr = NULL;
                old_string = pdb_get_munged_dial(account);
                mung.length = r->parameters.length * 2;
                mung.data = (uint8_t *) r->parameters.array;
-               newstr = (mung.length == 0) ? NULL :
-                       base64_encode_data_blob(talloc_tos(), mung);
+
+               if (mung.length != 0) {
+                       newstr = base64_encode_data_blob(talloc_tos(), mung);
+                       SMB_ASSERT(newstr != NULL);
+               }
 
                if (STRING_CHANGED_NC(old_string, newstr))
                        pdb_set_munged_dial(account, newstr, PDB_CHANGED);
index d052846b2e5b756488f207affae3ba678e2263dd..4c2307d4ffcf6dfa3a7939abcd63e25dddb8ba63 100644 (file)
@@ -305,8 +305,6 @@ void copy_id18_to_sam_passwd(struct samu *to,
 void copy_id20_to_sam_passwd(struct samu *to,
                             struct samr_UserInfo20 *from)
 {
-       const char *old_string;
-       char *new_string;
        DATA_BLOB mung;
 
        if (from == NULL || to == NULL) {
@@ -314,11 +312,18 @@ void copy_id20_to_sam_passwd(struct samu *to,
        }
 
        if (from->parameters.array) {
+               const char *old_string;
+               char *new_string = NULL;
                old_string = pdb_get_munged_dial(to);
                mung = data_blob_const(from->parameters.array,
                                       from->parameters.length);
-               new_string = (mung.length == 0) ?
-                       NULL : base64_encode_data_blob(talloc_tos(), mung);
+
+               if (mung.length != 0) {
+                       new_string = base64_encode_data_blob(talloc_tos(),
+                                                            mung);
+                       SMB_ASSERT(new_string != NULL);
+               }
+
                DEBUG(10,("INFO_20 PARAMETERS: %s -> %s\n",
                        old_string, new_string));
                if (STRING_CHANGED_NC(old_string,new_string)) {
@@ -496,14 +501,17 @@ void copy_id21_to_sam_passwd(const char *log_prefix,
 
        if ((from->fields_present & SAMR_FIELD_PARAMETERS) &&
            (from->parameters.array)) {
-               char *newstr;
+               char *newstr = NULL;
                DATA_BLOB mung;
                old_string = pdb_get_munged_dial(to);
 
                mung = data_blob_const(from->parameters.array,
                                       from->parameters.length);
-               newstr = (mung.length == 0) ?
-                       NULL : base64_encode_data_blob(talloc_tos(), mung);
+
+               if (mung.length != 0) {
+                       newstr = base64_encode_data_blob(talloc_tos(), mung);
+                       SMB_ASSERT(newstr != NULL);
+               }
                DEBUG(10,("%s SAMR_FIELD_PARAMETERS: %s -> %s\n", l,
                        old_string, newstr));
                if (STRING_CHANGED_NC(old_string,newstr)) {
index 1b27a88ec1b0c7f93446e1e461441aa981efaec3..7bce5caa67b08b7bd0476493858a8536a9cf3ef5 100644 (file)
@@ -1452,6 +1452,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
                        return;
                } else {
                        base64_key = base64_encode_data_blob(state, session_key);
+                       SMB_ASSERT(base64_key != NULL);
                        x_fprintf(x_stdout, "GK %s\n", base64_key);
                        talloc_free(base64_key);
                }
@@ -1481,6 +1482,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
 
        if (out.length) {
                out_base64 = base64_encode_data_blob(mem_ctx, out);
+               SMB_ASSERT(out_base64 != NULL);
        } else {
                out_base64 = NULL;
        }
index 08160247745cb4d6417d46c4fa97d063b3f890eb..6d0e259259dfbc921b28acecb49cbf580ced7e69 100644 (file)
@@ -621,6 +621,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
                        return;
                } else {
                        base64_key = base64_encode_data_blob(state, session_key);
+                       SMB_ASSERT(base64_key != NULL);
                        mux_printf(mux_id, "GK %s\n", base64_key);
                        talloc_free(base64_key);
                }
@@ -648,6 +649,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
 
        if (out.length) {
                out_base64 = base64_encode_data_blob(mem_ctx, out);
+               SMB_ASSERT(out_base64 != NULL);
        } else {
                out_base64 = NULL;
        }