Skip to content

Commit

Permalink
Fix some invalid use of sscanf
Browse files Browse the repository at this point in the history
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 #22961)

(cherry picked from commit 322517d)
  • Loading branch information
mattcaswell committed Dec 12, 2023
1 parent 952088a commit c579c99
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/errstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int errstr_main(int argc, char **argv)
/* All remaining arg are error code. */
ret = 0;
for (argv = opt_rest(); *argv != NULL; argv++) {
if (sscanf(*argv, "%lx", &l) == 0) {
if (sscanf(*argv, "%lx", &l) <= 0) {
ret++;
} else {
ERR_error_string_n(l, buf, sizeof(buf));
Expand Down
2 changes: 1 addition & 1 deletion crypto/http/http_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c579c99

Please sign in to comment.