|
|
db89db |
From d36661703e16bd740a3a928041b1e697a6617b98 Mon Sep 17 00:00:00 2001
|
|
|
db89db |
From: Daniel Stenberg <daniel@haxx.se>
|
|
|
db89db |
Date: Thu, 9 Jun 2022 09:27:24 +0200
|
|
|
db89db |
Subject: [PATCH] krb5: return error properly on decode errors
|
|
|
db89db |
|
|
|
db89db |
Bug: https://curl.se/docs/CVE-2022-32208.html
|
|
|
db89db |
CVE-2022-32208
|
|
|
db89db |
Reported-by: Harry Sintonen
|
|
|
db89db |
Closes #9051
|
|
|
db89db |
|
|
|
db89db |
Upstream-commit: 6ecdf5136b52af747e7bda08db9a748256b1cd09
|
|
|
db89db |
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
|
|
|
db89db |
---
|
|
|
db89db |
lib/krb5.c | 18 +++++++++++-------
|
|
|
db89db |
1 file changed, 11 insertions(+), 7 deletions(-)
|
|
|
db89db |
|
|
|
db89db |
diff --git a/lib/krb5.c b/lib/krb5.c
|
|
|
db89db |
index 787137c..6f9e1f7 100644
|
|
|
db89db |
--- a/lib/krb5.c
|
|
|
db89db |
+++ b/lib/krb5.c
|
|
|
db89db |
@@ -146,11 +146,8 @@ krb5_decode(void *app_data, void *buf, int len,
|
|
|
db89db |
enc.value = buf;
|
|
|
db89db |
enc.length = len;
|
|
|
db89db |
maj = gss_unwrap(&min, *context, &enc, &dec, NULL, NULL);
|
|
|
db89db |
- if(maj != GSS_S_COMPLETE) {
|
|
|
db89db |
- if(len >= 4)
|
|
|
db89db |
- strcpy(buf, "599 ");
|
|
|
db89db |
+ if(maj != GSS_S_COMPLETE)
|
|
|
db89db |
return -1;
|
|
|
db89db |
- }
|
|
|
db89db |
|
|
|
db89db |
memcpy(buf, dec.value, dec.length);
|
|
|
db89db |
len = curlx_uztosi(dec.length);
|
|
|
db89db |
@@ -523,6 +520,7 @@ static CURLcode read_data(struct connectdata *conn,
|
|
|
db89db |
{
|
|
|
db89db |
int len;
|
|
|
db89db |
CURLcode result;
|
|
|
db89db |
+ int nread;
|
|
|
db89db |
|
|
|
db89db |
result = socket_read(fd, &len, sizeof(len));
|
|
|
db89db |
if(result)
|
|
|
db89db |
@@ -531,7 +529,10 @@ static CURLcode read_data(struct connectdata *conn,
|
|
|
db89db |
if(len) {
|
|
|
db89db |
/* only realloc if there was a length */
|
|
|
db89db |
len = ntohl(len);
|
|
|
db89db |
- buf->data = Curl_saferealloc(buf->data, len);
|
|
|
db89db |
+ if(len > CURL_MAX_INPUT_LENGTH)
|
|
|
db89db |
+ len = 0;
|
|
|
db89db |
+ else
|
|
|
db89db |
+ buf->data = Curl_saferealloc(buf->data, len);
|
|
|
db89db |
}
|
|
|
db89db |
if(!len || !buf->data)
|
|
|
db89db |
return CURLE_OUT_OF_MEMORY;
|
|
|
db89db |
@@ -539,8 +540,11 @@ static CURLcode read_data(struct connectdata *conn,
|
|
|
db89db |
result = socket_read(fd, buf->data, len);
|
|
|
db89db |
if(result)
|
|
|
db89db |
return result;
|
|
|
db89db |
- buf->size = conn->mech->decode(conn->app_data, buf->data, len,
|
|
|
db89db |
- conn->data_prot, conn);
|
|
|
db89db |
+ nread = conn->mech->decode(conn->app_data, buf->data, len,
|
|
|
db89db |
+ conn->data_prot, conn);
|
|
|
db89db |
+ if(nread < 0)
|
|
|
db89db |
+ return CURLE_RECV_ERROR;
|
|
|
db89db |
+ buf->size = (size_t)nread;
|
|
|
db89db |
buf->index = 0;
|
|
|
db89db |
return CURLE_OK;
|
|
|
db89db |
}
|
|
|
db89db |
--
|
|
|
db89db |
2.35.3
|
|
|
db89db |
|