Lines 1-78
Link Here
|
1 |
This patch fixes a buffer overflow vulnerability in the NTLM auth |
|
|
2 |
helper which was reported by iDefense on the 07th June 2004. |
3 |
Original advisory: |
4 |
<http://www.idefense.com/application/poi/display?id=107&type=vulnerabilities&flashstatus=false> |
5 |
CVE-ID: CAN-2004-0541 |
6 |
Patch and correction obtained from: |
7 |
<http://www.squid-cache.org/~wessels/patch/libntlmssp.c.patch> |
8 |
<http://www.squid-cache.org/bugs/show_bug.cgi?id=998> |
9 |
|
10 |
--- helpers/ntlm_auth/SMB/libntlmssp.c.orig Fri Nov 30 10:50:06 2001 |
11 |
+++ helpers/ntlm_auth/SMB/libntlmssp.c Fri Jun 18 13:17:35 2004 |
12 |
@@ -161,7 +161,10 @@ make_challenge(char *domain, char *domai |
13 |
#define min(A,B) (A<B?A:B) |
14 |
|
15 |
int ntlm_errno; |
16 |
-static char credentials[1024]; /* we can afford to waste */ |
17 |
+#define MAX_USERNAME_LEN 255 |
18 |
+#define MAX_DOMAIN_LEN 255 |
19 |
+#define MAX_PASSWD_LEN 31 |
20 |
+static char credentials[MAX_USERNAME_LEN+MAX_DOMAIN_LEN+2]; /* we can afford to waste */ |
21 |
|
22 |
|
23 |
/* Fetches the user's credentials from the challenge. |
24 |
@@ -197,7 +200,7 @@ char * |
25 |
ntlm_check_auth(ntlm_authenticate * auth, int auth_length) |
26 |
{ |
27 |
int rv; |
28 |
- char pass[25] /*, encrypted_pass[40] */; |
29 |
+ char pass[MAX_PASSWD_LEN+1]; |
30 |
char *domain = credentials; |
31 |
char *user; |
32 |
lstring tmp; |
33 |
@@ -215,6 +218,11 @@ ntlm_check_auth(ntlm_authenticate * auth |
34 |
ntlm_errno = NTLM_LOGON_ERROR; |
35 |
return NULL; |
36 |
} |
37 |
+ if (tmp.l > MAX_DOMAIN_LEN) { |
38 |
+ debug("Domain string exceeds %d bytes, rejecting\n", MAX_DOMAIN_LEN); |
39 |
+ ntlm_errno = NTLM_LOGON_ERROR; |
40 |
+ return NULL; |
41 |
+ } |
42 |
memcpy(domain, tmp.str, tmp.l); |
43 |
user = domain + tmp.l; |
44 |
*user++ = '\0'; |
45 |
@@ -226,20 +234,30 @@ ntlm_check_auth(ntlm_authenticate * auth |
46 |
ntlm_errno = NTLM_LOGON_ERROR; |
47 |
return NULL; |
48 |
} |
49 |
+ if (tmp.l > MAX_USERNAME_LEN) { |
50 |
+ debug("Username string exceeds %d bytes, rejecting\n", MAX_USERNAME_LEN); |
51 |
+ ntlm_errno = NTLM_LOGON_ERROR; |
52 |
+ return NULL; |
53 |
+ } |
54 |
memcpy(user, tmp.str, tmp.l); |
55 |
*(user + tmp.l) = '\0'; |
56 |
|
57 |
|
58 |
- /* Authenticating against the NT response doesn't seem to work... */ |
59 |
+ /* Authenticating against the NT response doesn't seem to work... */ |
60 |
tmp = ntlm_fetch_string((char *) auth, auth_length, &auth->lmresponse); |
61 |
if (tmp.str == NULL || tmp.l == 0) { |
62 |
fprintf(stderr, "No auth at all. Returning no-auth\n"); |
63 |
ntlm_errno = NTLM_LOGON_ERROR; |
64 |
return NULL; |
65 |
} |
66 |
- |
67 |
+ if (tmp.l > MAX_PASSWD_LEN) { |
68 |
+ debug("Password string exceeds %d bytes, rejecting\n", MAX_PASSWD_LEN); |
69 |
+ ntlm_errno = NTLM_LOGON_ERROR; |
70 |
+ return NULL; |
71 |
+ } |
72 |
+ |
73 |
memcpy(pass, tmp.str, tmp.l); |
74 |
- pass[25] = '\0'; |
75 |
+ pass[min(MAX_PASSWD_LEN,tmp.l)] = '\0'; |
76 |
|
77 |
#if 1 |
78 |
debug ("Empty LM pass detection: user: '%s', ours:'%s', his: '%s'" |