Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in target_name decoding #91

Merged
merged 2 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/ntlm.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ static int ntlm_decode_u16l_str_hdr(struct ntlm_ctx *ctx,
safefree(out);
} else {
/* make sure to terminate output string */
out[outlen] = '\0';
if (out) {
out[outlen] = '\0';
}
}

*str = out;
Expand Down
47 changes: 47 additions & 0 deletions tests/ntlmssptest.c
Original file line number Diff line number Diff line change
Expand Up @@ -3132,6 +3132,48 @@ int test_debug(void)
return 0;
}

int test_bad_challenge(struct ntlm_ctx *ctx)
{
struct ntlm_buffer challenge = { T_ServerChallenge, 8 };
struct ntlm_buffer message = { 0 };
struct wire_chal_msg *msg;
uint32_t type;
uint32_t flags;
char *target_name = NULL;
uint8_t chal[8];
struct ntlm_buffer rchallenge = { chal, 8 };
int ret;

/* check we can decode encode/decode NULL target_name */
flags = T_NTLMv1.ChallengeFlags &
~(NTLMSSP_TARGET_TYPE_SERVER | NTLMSSP_TARGET_TYPE_DOMAIN);
flags |= NTLMSSP_NEGOTIATE_UNICODE;

ret = ntlm_encode_chal_msg(ctx, flags, NULL,
&challenge, NULL, &message);
if (ret) return ret;

/* Doctor the message to set back NTLMSSP_TARGET_TYPE_SERVER */
msg = (struct wire_chal_msg *)message.data;
msg->neg_flags |= NTLMSSP_TARGET_TYPE_SERVER;

ret = ntlm_decode_msg_type(ctx, &message, &type);
if (ret) return ret;
if (type != 2) return EINVAL;

ret = ntlm_decode_chal_msg(ctx, &message, &flags, &target_name,
&rchallenge, NULL);
if (ret) return ret;

if (target_name != NULL) {
ret = EINVAL;
free(target_name);
}
free(message.data);

return ret;
}

int main(int argc, const char *argv[])
{
struct ntlm_ctx *ctx;
Expand Down Expand Up @@ -3367,6 +3409,11 @@ int main(int argc, const char *argv[])
fprintf(stderr, "Test: %s\n", (ret ? "FAIL":"SUCCESS"));
if (ret) gret++;

fprintf(stderr, "Test Bad Challenge Message\n");
ret = test_bad_challenge(ctx);
fprintf(stderr, "Test: %s\n", (ret ? "FAIL":"SUCCESS"));
if (ret) gret++;

fprintf(stderr, "Test Acquired cred from with no name\n");
ret = test_ACQ_NO_NAME();
fprintf(stderr, "Test: %s\n", (ret ? "FAIL":"SUCCESS"));
Expand Down