/*
* Manually create an EAP Identity request
*/
- p = talloc_array(vp, uint8_t, 5);
+ MEM(fr_pair_value_mem_alloc(vp, &p, 5, false) == 0);
p[0] = FR_EAP_CODE_REQUEST;
p[1] = 0; /* ID */
p[2] = 0;
p[3] = 5; /* length */
p[4] = FR_EAP_METHOD_IDENTITY;
- fr_pair_value_memsteal(vp, p, false);
return RLM_MODULE_HANDLED;
} /* end of handling EAP-Start */
return XLAT_ACTION_FAIL;
}
- MEM(ciphertext = talloc_array(ctx, uint8_t, ciphertext_len));
+ MEM(vb = fr_value_box_alloc_null(ctx));
+ MEM(fr_value_box_mem_alloc(vb, &ciphertext, vb, NULL, ciphertext_len, false) == 0);
if (EVP_PKEY_encrypt(xt->evp_encrypt_ctx, ciphertext, &ciphertext_len,
(unsigned char const *)plaintext, plaintext_len) <= 0) {
fr_tls_log_error(request, "Failed encrypting plaintext");
+ talloc_free(vb);
return XLAT_ACTION_FAIL;
}
RHEXDUMP3(ciphertext, ciphertext_len, "Ciphertext (%zu bytes)", ciphertext_len);
-
- if (ciphertext_len != talloc_array_length(ciphertext)) {
- uint8_t *n;
-
- n = talloc_realloc_size(ctx, ciphertext, ciphertext_len);
- if (unlikely(!n)) {
- REDEBUG("Failed shrinking ciphertext buffer");
- talloc_free(ciphertext);
- return XLAT_ACTION_FAIL;
- }
- talloc_set_type(n, uint8_t);
-
- ciphertext = n;
- }
-
- MEM(vb = fr_value_box_alloc_null(ctx));
- fr_value_box_memsteal(vb, vb, NULL, ciphertext, false);
+ MEM(fr_value_box_mem_realloc(vb, NULL, vb, ciphertext_len) == 0);
fr_cursor_append(out, vb);
return XLAT_ACTION_DONE;
return XLAT_ACTION_FAIL;
}
- MEM(sig = talloc_array(ctx, uint8_t, sig_len));
+ MEM(vb = fr_value_box_alloc_null(ctx));
+ MEM(fr_value_box_mem_alloc(vb, &sig, vb, NULL, sig_len, false) == 0);
if (EVP_PKEY_sign(xt->evp_sign_ctx, sig, &sig_len, xt->digest_buff, (size_t)digest_len) <= 0) {
fr_tls_log_error(request, "Failed signing message digest");
+ talloc_free(vb);
return XLAT_ACTION_FAIL;
}
-
- /*
- * Fixup the output buffer
- */
- if (sig_len != talloc_array_length(sig)) {
- uint8_t *n;
-
- n = talloc_realloc_size(ctx, sig, sig_len);
- if (unlikely(!n)) {
- REDEBUG("Failed shrinking signature buffer");
- talloc_free(sig);
- return XLAT_ACTION_FAIL;
- }
- talloc_set_type(n, uint8_t);
-
- sig = n;
- }
-
- MEM(vb = fr_value_box_alloc_null(ctx));
- fr_value_box_memsteal(vb, vb, NULL, sig, false);
+ MEM(fr_value_box_mem_realloc(vb, NULL, vb, sig_len) == 0);
fr_cursor_append(out, vb);
return XLAT_ACTION_DONE;
size_t ciphertext_len;
char *plaintext;
- size_t plaintext_len_est, plaintext_len;
+ size_t plaintext_len;
fr_value_box_t *vb;
* Decrypt the ciphertext
*/
RHEXDUMP3(ciphertext, ciphertext_len, "Ciphertext (%zu bytes)", ciphertext_len);
- if (EVP_PKEY_decrypt(xt->evp_decrypt_ctx, NULL, &plaintext_len_est, ciphertext, ciphertext_len) <= 0) {
+ if (EVP_PKEY_decrypt(xt->evp_decrypt_ctx, NULL, &plaintext_len, ciphertext, ciphertext_len) <= 0) {
fr_tls_log_error(request, "Failed getting length of cleartext");
return XLAT_ACTION_FAIL;
}
- plaintext_len = plaintext_len_est;
MEM(vb = fr_value_box_alloc_null(ctx));
- MEM(fr_value_box_bstr_alloc(vb, &plaintext, vb, NULL, plaintext_len_est, true) == 0);
+ MEM(fr_value_box_bstr_alloc(vb, &plaintext, vb, NULL, plaintext_len, true) == 0);
if (EVP_PKEY_decrypt(xt->evp_decrypt_ctx, (unsigned char *)plaintext, &plaintext_len,
ciphertext, ciphertext_len) <= 0) {
fr_tls_log_error(request, "Failed decrypting ciphertext");
* RADIUS protocol code will calculate the correct value later...
*/
MEM(pair_update_reply(&vp, attr_message_authenticator) >= 0);
- fr_pair_value_memsteal(vp, talloc_zero_array(vp, uint8_t, RADIUS_AUTH_VECTOR_LENGTH), false);
+ MEM(fr_pair_value_mem_alloc(vp, NULL, RADIUS_AUTH_VECTOR_LENGTH, false) == 0);
return RLM_MODULE_UPDATED;
}
int ccode;
uint8_t *p;
size_t length;
- char *q;
if (!fr_cond_assert(eap_session->inst)) return 0;
fr_pair_value_memdup(auth_challenge, data->auth_challenge, MSCHAPV2_CHALLENGE_LEN, false);
MEM(pair_update_request(&cpw, attr_ms_chap2_cpw) >= 0);
- p = talloc_array(cpw, uint8_t, 68);
+ MEM(fr_pair_value_mem_alloc(cpw, &p, 68, false) == 0);
p[0] = 7;
p[1] = mschap_id;
memcpy(p + 2, eap_round->response->type.data + 520, 66);
- fr_pair_value_memsteal(cpw, p, false);
/*
* break the encoded password into VPs (3 of them)
if (to_copy > 243) to_copy = 243;
MEM(pair_add_request(&nt_enc, attr_ms_chap_nt_enc_pw) >= 0);
- p = talloc_array(nt_enc, uint8_t, 4 + to_copy);
+ MEM(fr_pair_value_mem_alloc(nt_enc, &p, 4 + to_copy, false) == 0);
p[0] = 6;
p[1] = mschap_id;
p[2] = 0;
p[3] = seq++;
memcpy(p + 4, eap_round->response->type.data + 4 + copied, to_copy);
- fr_pair_value_memsteal(nt_enc, p, false);
copied += to_copy;
}
fr_pair_value_memdup(auth_challenge, data->auth_challenge, MSCHAPV2_CHALLENGE_LEN, false);
MEM(pair_update_request(&response, attr_ms_chap2_response) >= 0);
- p = talloc_array(response, uint8_t, MSCHAPV2_RESPONSE_LEN);
+ MEM(fr_pair_value_mem_alloc(response, &p, MSCHAPV2_RESPONSE_LEN, false) == 0);
p[0] = eap_round->response->type.data[1];
p[1] = eap_round->response->type.data[5 + MSCHAPV2_RESPONSE_LEN];
memcpy(p + 2, &eap_round->response->type.data[5], MSCHAPV2_RESPONSE_LEN - 2);
* the challenge sent by the client.
*/
if (data->has_peer_challenge) memcpy(p + 2, data->peer_challenge, MSCHAPV2_CHALLENGE_LEN);
- fr_pair_value_memsteal(response, p, false);
/*
* MS-Length - MS-Value - 5.
*/
MEM(pair_update_request(&name, attr_ms_chap_user_name) >= 0);
- name->vp_tainted = true;
- name->vp_length = length - 49 - 5;
- name->vp_strvalue = q = talloc_array(name, char, name->vp_length + 1);
- memcpy(q, &eap_round->response->type.data[4 + MSCHAPV2_RESPONSE_LEN], name->vp_length);
- q[name->vp_length] = '\0';
-
+ MEM(fr_pair_value_bstrndup(name, (char const *)&eap_round->response->type.data[4 + MSCHAPV2_RESPONSE_LEN],
+ length - 49 - 5, true) == 0);
packet_ready:
#ifdef WITH_PROXY
* Get a random challenge.
*/
MEM(auth_challenge = fr_pair_afrom_da(eap_session, attr_ms_chap_challenge));
- p = talloc_array(auth_challenge, uint8_t, MSCHAPV2_CHALLENGE_LEN);
+ MEM(fr_pair_value_mem_alloc(auth_challenge, &p, MSCHAPV2_CHALLENGE_LEN, false) == 0);
for (i = 0; i < MSCHAPV2_CHALLENGE_LEN; i++) p[i] = fr_rand();
- fr_pair_value_memsteal(auth_challenge, p, false);
}
RDEBUG2("Issuing Challenge");
/*
* Hand-build an EAP packet from the crap in PEAP version 0.
*/
- p = talloc_array(vp, uint8_t, EAP_HEADER_LEN + total);
+ MEM(fr_pair_value_mem_alloc(vp, &p, EAP_HEADER_LEN + total, false) == 0);
p[0] = FR_EAP_CODE_RESPONSE;
p[1] = eap_round->response->id;
p[2] = (data_len + EAP_HEADER_LEN) >> 8;
p[3] = (data_len + EAP_HEADER_LEN) & 0xff;
memcpy(p + EAP_HEADER_LEN, data, total);
- fr_pair_value_memsteal(vp, p, false);
fr_cursor_init(&cursor, &head);
fr_cursor_append(&cursor, vp);
t->status = PEAP_STATUS_PHASE2;
MEM(vp = fr_pair_afrom_da(fake->packet, attr_eap_message));
-
- q = talloc_array(vp, uint8_t, len);
+ MEM(fr_pair_value_mem_alloc(vp, &q, len, false) == 0);
q[0] = FR_EAP_CODE_RESPONSE;
q[1] = eap_round->response->id;
q[2] = (len >> 8) & 0xff;
q[4] = FR_EAP_METHOD_IDENTITY;
memcpy(q + EAP_HEADER_LEN + 1,
t->username->vp_strvalue, t->username->vp_length);
-
- fr_pair_value_memsteal(vp, q, false);
fr_pair_add(&fake->packet->vps, vp);
}
break;
* cleartext password as it avoids unicode hassles.
*/
MEM(pair_update_request(&new_hash, attr_ms_chap_new_nt_password) >= 0);
- MEM(q = talloc_array(new_hash, uint8_t, NT_DIGEST_LENGTH));
- fr_pair_value_memsteal(new_hash, q, false);
+ MEM(fr_pair_value_mem_alloc(new_hash, &q, NT_DIGEST_LENGTH, false) == 0);
fr_md4_calc(q, p, passlen);
/*
VALUE_PAIR *nt_password;
MEM(nt_password = fr_pair_afrom_da(request, attr_nt_password));
- MEM(p = talloc_array(nt_password, uint8_t, NT_DIGEST_LENGTH));
- fr_pair_value_memsteal(nt_password, p, false);
-
+ MEM(fr_pair_value_mem_alloc(nt_password, &p, NT_DIGEST_LENGTH, false) == 0);
ret = mschap_nt_password_hash(p, password->vp_strvalue);
if (ret < 0) {
* continue with the authentication.
*/
MEM(pair_update_request(&response, attr_ms_chap2_response) >= 0);
- MEM(p = talloc_array(response, uint8_t, 50));
+ MEM(fr_pair_value_mem_alloc(response, &p, 50, cpw->vp_tainted) == 0);
/* ident & flags */
p[0] = cpw->vp_octets[1];
p[1] = 0;
/* peer challenge and client NT response */
memcpy(p + 2, cpw->vp_octets + 18, 48);
-
- fr_pair_value_memsteal(response, p, false);
}
challenge = fr_pair_find_by_da(request->packet->vps, attr_ms_chap_challenge, TAG_ANY);
RDEBUG2("SIM auth vector %i", i);
RINDENT();
MEM(vp = fr_pair_afrom_da(request, attr_eap_aka_sim_rand));
- fr_pair_value_memsteal(vp, vec->sim.rand, true);
+ MEM(fr_pair_value_memdup_buffer(vp, vec->sim.rand, true) == 0);
+ TALLOC_FREE(vec->sim.rand);
RDEBUG2("&control:%pP", vp);
fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(request, attr_eap_aka_sim_sres));
- fr_pair_value_memsteal(vp, vec->sim.sres, true);
+ MEM(fr_pair_value_memdup_buffer(vp, vec->sim.sres, true) == 0);
+ TALLOC_FREE(vec->sim.sres);
RDEBUG2("&control:%pP", vp);
fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(request, attr_eap_aka_sim_kc));
- fr_pair_value_memsteal(vp, vec->sim.kc, true);
+ MEM(fr_pair_value_memdup_buffer(vp, vec->sim.kc, true) == 0);
+ TALLOC_FREE(vec->sim.kc);
RDEBUG2("&control:%pP", vp);
fr_cursor_append(&cursor, vp);
REXDENT();
RDEBUG2("UMTS auth vector %i", i);
RINDENT();
MEM(vp = fr_pair_afrom_da(request, attr_eap_aka_sim_rand));
- fr_pair_value_memsteal(vp, vec->umts.rand, true);
+ MEM(fr_pair_value_memdup_buffer(vp, vec->umts.rand, true) == 0);
+ TALLOC_FREE(vec->umts.rand);
RDEBUG2("&control:%pP", vp);
fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(request, attr_eap_aka_sim_xres));
- fr_pair_value_memsteal(vp, vec->umts.xres, true);
+ MEM(fr_pair_value_memdup_buffer(vp, vec->umts.xres, true) == 0);
+ TALLOC_FREE(vec->umts.xres);
RDEBUG2("&control:%pP", vp);
fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(request, attr_eap_aka_sim_ck));
- fr_pair_value_memsteal(vp, vec->umts.ck, true);
+ MEM(fr_pair_value_memdup_buffer(vp, vec->umts.ck, true) == 0);
+ TALLOC_FREE(vec->umts.ck);
RDEBUG2("&control:%pP", vp);
fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(request, attr_eap_aka_sim_ik));
- fr_pair_value_memsteal(vp, vec->umts.ik, true);
+ MEM(fr_pair_value_memdup_buffer(vp, vec->umts.ik, true) == 0);
+ TALLOC_FREE(vec->umts.ik);
RDEBUG2("&control:%pP", vp);
fr_cursor_append(&cursor, vp);
MEM(vp = fr_pair_afrom_da(request, attr_eap_aka_sim_autn));
- fr_pair_value_memsteal(vp, vec->umts.authn, true);
+ MEM(fr_pair_value_memdup_buffer(vp, vec->umts.authn, true) == 0);
+ TALLOC_FREE(vec->umts.authn);
RDEBUG2("&control:%pP", vp);
fr_cursor_append(&cursor, vp);
REXDENT();
RDEBUG2("SoH adding NAP marker to DHCP reply");
/* client probe; send "NAP" in the reply */
MEM(vp = fr_pair_afrom_da(request->reply, attr_dhcp_vendor));
- MEM(p = talloc_array(vp, uint8_t, 5));
+ MEM(fr_pair_value_mem_alloc(vp, &p, 5, false) == 0);
p[0] = 220;
p[1] = 3;
p[4] = 'N';
p[3] = 'A';
p[2] = 'P';
- fr_pair_value_memsteal(vp, p, false);
fr_pair_add(&request->reply->vps, vp);
} else {
vp = fr_pair_afrom_da(ctx, parent);
if (!vp) return -1;
- p = talloc_array(vp, uint8_t, total);
- if (!p) {
- fr_pair_list_free(&vp);
+ if (!fr_pair_value_mem_alloc(vp, &p, total, true)) {
+ talloc_free(vp);
return -1;
}
- fr_pair_value_memsteal(vp, p, true);
ptr = data;
while (ptr < end) {