clang -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ipa_kdb_mkey.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/10.0.0 -D HAVE_CONFIG_H -I . -I ../.. -I . -I ../../util -D PREFIX="/usr/local" -D BINDIR="/usr/local/bin" -D LIBDIR="/usr/local/lib" -D LIBEXECDIR="/usr/local/libexec" -D DATADIR="/usr/local/share" -D LDAPIDIR="/run" -I /usr/include/samba-4.0 -D _GNU_SOURCE=1 -D HAVE_IMMEDIATE_STRUCTURES=1 -I /usr/include/nss3 -I /usr/include/nspr4 -I /usr/include/nspr4 -I /usr/include/nss3 -I /usr/include/nspr4 -D __STDC_WANT_LIB_EXT1__=1 -D _DEFAULT_SOURCE=1 -D _POSIX_C_SOURCE=200809L -D PIC -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/10.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/heimes/redhat/freeipa/daemons/ipa-kdb -ferror-limit 19 -fmessage-length 0 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -analyzer-output=html -faddrsig -o /home/heimes/redhat/freeipa/report/2020-06-05-101548-295465-1 -x c ipa_kdb_mkey.c
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | #include "ipa_kdb.h" |
| 24 | |
| 25 | static char *krbmkey_attrs[] = { |
| 26 | "krbMKey", |
| 27 | NULL |
| 28 | }; |
| 29 | |
| 30 | krb5_error_code ipadb_fetch_master_key(krb5_context kcontext, |
| 31 | krb5_principal mname, |
| 32 | krb5_keyblock *key, |
| 33 | krb5_kvno *kvno, |
| 34 | char *db_args) |
| 35 | { |
| 36 | struct ipadb_context *ipactx; |
| 37 | LDAPMessage *res = NULL; |
| 38 | LDAPMessage *first; |
| 39 | struct berval **vals = NULL; |
| 40 | BerElement *be = NULL; |
| 41 | krb5_error_code kerr; |
| 42 | krb5_keyblock k; |
| 43 | int mkvno; |
| 44 | int ret; |
| 45 | int i; |
| 46 | |
| 47 | ipactx = ipadb_get_context(kcontext); |
| 48 | if (!ipactx) { |
| 1 | Assuming 'ipactx' is non-null | |
|
| |
| 49 | return KRB5_KDB_DBNOTINITED; |
| 50 | } |
| 51 | |
| 52 | if (!ipactx->lcontext) { |
| 3 | | Assuming field 'lcontext' is non-null | |
|
| |
| 53 | ret = ipadb_get_connection(ipactx); |
| 54 | if (ret != 0) { |
| 55 | kerr = KRB5_KDB_SERVER_INTERNAL_ERR; |
| 56 | goto done; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | be = ber_alloc_t(LBER_USE_DER); |
| 61 | if (!be) { |
| 5 | | Assuming 'be' is non-null | |
|
| |
| 62 | kerr = ENOMEM; |
| 63 | goto done; |
| 64 | } |
| 65 | |
| 66 | kerr = ipadb_simple_search(ipactx, ipactx->realm_base, LDAP_SCOPE_BASE, |
| 67 | "(krbMKey=*)", krbmkey_attrs, &res); |
| 68 | if (kerr) { |
| |
| |
| 69 | goto done; |
| 70 | } |
| 71 | |
| 72 | first = ldap_first_entry(ipactx->lcontext, res); |
| 73 | if (!first) { |
| 9 | | Assuming 'first' is non-null | |
|
| |
| 74 | kerr = KRB5_KDB_NOENTRY; |
| 75 | goto done; |
| 76 | } |
| 77 | |
| 78 | mkvno = 0; |
| 79 | k.contents = NULL; |
| 80 | vals = ldap_get_values_len(ipactx->lcontext, first, "krbmkey"); |
| 81 | for (i = 0; vals[i]; i++) { |
| 11 | | Loop condition is true. Entering loop body | |
|
| 20 | | Loop condition is true. Entering loop body | |
|
| 82 | struct berval *mkey; |
| 83 | ber_tag_t tag; |
| 84 | ber_int_t tvno; |
| 85 | ber_int_t ttype; |
| 86 | |
| 87 | ber_init2(be, vals[i], LBER_USE_DER); |
| 88 | |
| 89 | tag = ber_scanf(be, "{i{iO}}", &tvno, &ttype, &mkey); |
| 90 | if (tag == LBER_ERROR) { |
| 12 | | Assuming the condition is false | |
|
| |
| 21 | | Assuming the condition is true | |
|
| |
| 91 | kerr = KRB5_KDB_SERVER_INTERNAL_ERR; |
| 23 | | Potential leak of memory pointed to by 'k.contents' |
|
| 92 | goto done; |
| 93 | } |
| 94 | |
| 95 | if (tvno > mkvno) { |
| 14 | | Assuming 'tvno' is > 'mkvno' | |
|
| |
| 96 | mkvno = tvno; |
| 97 | k.enctype = ttype; |
| 98 | k.length = mkey->bv_len; |
| 99 | if (k.contents) { |
| |
| 100 | free(k.contents); |
| 101 | } |
| 102 | k.contents = malloc(k.length); |
| |
| 103 | if (!k.contents) { |
| 18 | | Assuming field 'contents' is non-null | |
|
| |
| 104 | kerr = ENOMEM; |
| 105 | goto done; |
| 106 | } |
| 107 | memcpy(k.contents, mkey->bv_val, k.length); |
| 108 | } |
| 109 | ber_bvfree(mkey); |
| 110 | } |
| 111 | |
| 112 | if (mkvno == 0) { |
| 113 | kerr = KRB5_KDB_NOENTRY; |
| 114 | goto done; |
| 115 | } |
| 116 | |
| 117 | *kvno = mkvno; |
| 118 | key->magic = KV5M_KEYBLOCK; |
| 119 | key->enctype = k.enctype; |
| 120 | key->length = k.length; |
| 121 | key->contents = k.contents; |
| 122 | |
| 123 | kerr = 0; |
| 124 | |
| 125 | done: |
| 126 | if (be) { |
| 127 | ber_free(be, 0); |
| 128 | } |
| 129 | ldap_value_free_len(vals); |
| 130 | ldap_msgfree(res); |
| 131 | return kerr; |
| 132 | } |
| 133 | |
| 134 | krb5_error_code ipadb_store_master_key_list(krb5_context kcontext, |
| 135 | char *db_arg, |
| 136 | krb5_principal mname, |
| 137 | krb5_keylist_node *keylist, |
| 138 | char *master_pwd) |
| 139 | { |
| 140 | struct ipadb_context *ipactx; |
| 141 | BerElement *be = NULL; |
| 142 | krb5_keyblock k = { 0, 0, 0, NULL }; |
| 143 | struct berval mkey; |
| 144 | ber_int_t tvno; |
| 145 | ber_int_t ttype; |
| 146 | LDAPMod **mods = NULL; |
| 147 | krb5_error_code kerr; |
| 148 | int ret; |
| 149 | |
| 150 | ipactx = ipadb_get_context(kcontext); |
| 151 | if (!ipactx) { |
| 152 | return KRB5_KDB_DBNOTINITED; |
| 153 | } |
| 154 | |
| 155 | |
| 156 | if (!keylist || keylist->next) { |
| 157 | return EINVAL; |
| 158 | } |
| 159 | |
| 160 | if (!ipactx->lcontext) { |
| 161 | ret = ipadb_get_connection(ipactx); |
| 162 | if (ret != 0) { |
| 163 | kerr = KRB5_KDB_SERVER_INTERNAL_ERR; |
| 164 | goto done; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | be = ber_alloc_t(LBER_USE_DER); |
| 169 | if (!be) { |
| 170 | kerr = ENOMEM; |
| 171 | goto done; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | tvno = keylist->kvno; |
| 176 | ttype = keylist->keyblock.enctype; |
| 177 | mkey.bv_len = keylist->keyblock.length; |
| 178 | mkey.bv_val = (void *)keylist->keyblock.contents; |
| 179 | |
| 180 | ret = ber_printf(be, "{i{iO}}", tvno, ttype, &mkey); |
| 181 | if (ret == -1) { |
| 182 | kerr = KRB5_KDB_INTERNAL_ERROR; |
| 183 | goto done; |
| 184 | } |
| 185 | |
| 186 | mods = calloc(2, sizeof(LDAPMod *)); |
| 187 | if (!mods) { |
| 188 | kerr = ENOMEM; |
| 189 | goto done; |
| 190 | } |
| 191 | mods[0] = calloc(1, sizeof(LDAPMod)); |
| 192 | if (!mods[0]) { |
| 193 | kerr = ENOMEM; |
| 194 | goto done; |
| 195 | } |
| 196 | mods[0]->mod_op = LDAP_MOD_ADD | LDAP_MOD_BVALUES; |
| 197 | mods[0]->mod_type = strdup("krbMKey"); |
| 198 | if (!mods[0]->mod_type) { |
| 199 | kerr = ENOMEM; |
| 200 | goto done; |
| 201 | } |
| 202 | mods[0]->mod_bvalues = calloc(2, sizeof(struct berval *)); |
| 203 | if (!mods[0]->mod_bvalues) { |
| 204 | kerr = ENOMEM; |
| 205 | goto done; |
| 206 | } |
| 207 | |
| 208 | ret = ber_flatten(be, &mods[0]->mod_bvalues[0]); |
| 209 | if (ret == -1) { |
| 210 | kerr = KRB5_KDB_INTERNAL_ERROR; |
| 211 | goto done; |
| 212 | } |
| 213 | |
| 214 | kerr = ipadb_simple_modify(ipactx, ipactx->realm_base, mods); |
| 215 | |
| 216 | kerr = 0; |
| 217 | |
| 218 | done: |
| 219 | if (be) { |
| 220 | ber_free(be, 1); |
| 221 | } |
| 222 | krb5_free_keyblock_contents(kcontext, &k); |
| 223 | ldap_mods_free(mods, 1); |
| 224 | return kerr; |
| 225 | } |