Skip to content

Commit

Permalink
NTLM: add length check to add_security_buffer
Browse files Browse the repository at this point in the history
Especially ntlmv2_response can be very big, so make sure
we not do exceed the size of the phase3 buffer.

Change-Id: Icea931d29e3e504e23e045539b21013b42172664
Signed-off-by: Frank Lichtenheld <[email protected]>
Acked-by: Gert Doering <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg28037.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
flichtenheld authored and cron2 committed Jan 17, 2024
1 parent cedbac7 commit a021de2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/openvpn/ntlm.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,13 @@ unicodize(char *dst, const char *src)

static void
add_security_buffer(int sb_offset, void *data, int length,
unsigned char *msg_buf, int *msg_bufpos)
unsigned char *msg_buf, int *msg_bufpos, size_t msg_bufsize)
{
if (*msg_bufpos + length > msg_bufsize)
{
msg(M_WARN, "NTLM: security buffer too big for message buffer");
return;
}
/* Adds security buffer data to a message and sets security buffer's
* offset and length */
msg_buf[sb_offset] = (unsigned char)length;
Expand Down Expand Up @@ -362,15 +367,15 @@ ntlm_phase_3(const struct http_proxy_info *p, const char *phase_2,

/* NTLMv2 response */
add_security_buffer(0x14, ntlmv2_response, ntlmv2_blob_size + 16,
phase3, &phase3_bufpos);
phase3, &phase3_bufpos, sizeof(phase3));

/* username in ascii */
add_security_buffer(0x24, username, strlen(username), phase3,
&phase3_bufpos);
&phase3_bufpos, sizeof(phase3));

/* Set domain. If <domain> is empty, default domain will be used
* (i.e. proxy's domain) */
add_security_buffer(0x1c, domain, strlen(domain), phase3, &phase3_bufpos);
add_security_buffer(0x1c, domain, strlen(domain), phase3, &phase3_bufpos, sizeof(phase3));

/* other security buffers will be empty */
phase3[0x10] = phase3_bufpos; /* lm not used */
Expand Down

0 comments on commit a021de2

Please sign in to comment.