summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2023-12-06 11:51:01 +0000
committerMatt Caswell <matt@openssl.org>2023-12-12 16:13:08 +0000
commit70c11b5e3bf6e29c12255ea276e5a5ace11e5ee6 (patch)
treedd24ffec1d9fa4b714dc4a740a706fd86ff0e5f4 /crypto
parent4d4002852b2a8b877050288355a388413e6bdd90 (diff)
Fix some invalid use of sscanf
sscanf can return -1 on an empty input string. We need to appropriately handle such an invalid case. The instance in OSSL_HTTP_parse_url could cause an uninitialised read of sizeof(unsigned int) bytes (typically 4). In many cases this uninit read will immediately fail on the following check (i.e. if the read value >65535). If the top 2 bytes of a 4 byte unsigned int are zero then the value will be <=65535 and the uninitialised value will be returned to the caller and could represent arbitrary data on the application stack. The OpenSSL security team has assessed this issue and consider it to be a bug only (i.e. not a CVE). Reviewed-by: Todd Short <todd.short@me.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/22961) (cherry picked from commit 322517d817ecb5c1a3a8b0e7e038fa146857b4d4)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/http/http_lib.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/crypto/http/http_lib.c b/crypto/http/http_lib.c
index e45f60b722..30c1cd04fc 100644
--- a/crypto/http/http_lib.c
+++ b/crypto/http/http_lib.c
@@ -118,7 +118,7 @@ int OSSL_parse_url(const char *url, char **pscheme, char **puser, char **phost,
port = ++p;
/* remaining port spec handling is also done for the default values */
/* make sure a decimal port number is given */
- if (!sscanf(port, "%u", &portnum) || portnum > 65535) {
+ if (sscanf(port, "%u", &portnum) <= 0 || portnum > 65535) {
ERR_raise_data(ERR_LIB_HTTP, HTTP_R_INVALID_PORT_NUMBER, "%s", port);
goto err;
}