diff options
author | Timo Teräs <timo.teras@iki.fi> | 2021-07-16 10:54:08 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2021-07-26 14:43:14 +0300 |
commit | ca1d975e5eae662cfde085338e2e29f8e6fcf64b (patch) | |
tree | 5cbfdf287c45c0d472ddce0d0dcf7201c0bbad80 /libfetch/common.h | |
parent | 003e7135024b08b6f29ba83935b468c8f0b41ad4 (diff) | |
download | apk-tools-ca1d975e5eae662cfde085338e2e29f8e6fcf64b.tar.gz apk-tools-ca1d975e5eae662cfde085338e2e29f8e6fcf64b.tar.bz2 apk-tools-ca1d975e5eae662cfde085338e2e29f8e6fcf64b.tar.xz apk-tools-ca1d975e5eae662cfde085338e2e29f8e6fcf64b.zip |
libfetch: fix range checking for http/ftp protocol parsing
Various parsing of numeric strings were not having adequate range
checking causing information leak or potential crash.
CVE-2021-36159
fixes #10749
Co-authored-by: Ariadne Conill <ariadne@dereferenced.org>
Reported-by: Samanta Navarro <ferivoz@riseup.net>
Diffstat (limited to 'libfetch/common.h')
-rw-r--r-- | libfetch/common.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/libfetch/common.h b/libfetch/common.h index dd5c14c..2c16bf7 100644 --- a/libfetch/common.h +++ b/libfetch/common.h @@ -38,6 +38,8 @@ #define FTP_DEFAULT_PROXY_PORT 21 #define HTTP_DEFAULT_PROXY_PORT 3128 +#include <sys/types.h> +#include <limits.h> #include "openssl-compat.h" #if defined(__GNUC__) && __GNUC__ >= 3 @@ -53,6 +55,14 @@ #define HAVE_SA_LEN #endif +#ifndef IPPORT_MAX +# define IPPORT_MAX 65535 +#endif + +#ifndef OFF_MAX +# define OFF_MAX (((((off_t)1 << (sizeof(off_t) * CHAR_BIT - 2)) - 1) << 1) + 1) +#endif + /* Connection */ typedef struct fetchconn conn_t; @@ -86,6 +96,7 @@ struct fetcherr { void fetch_seterr(struct fetcherr *, int); void fetch_syserr(void); void fetch_info(const char *, ...) LIBFETCH_PRINTFLIKE(1, 2); +uintmax_t fetch_parseuint(const char *p, const char **endptr, int radix, uintmax_t max); int fetch_default_port(const char *); int fetch_default_proxy_port(const char *); int fetch_bind(int, int, const char *); @@ -125,7 +136,6 @@ fetchIO *http_request(struct url *, const char *, fetchIO *ftp_request(struct url *, const char *, const char *, struct url_stat *, struct url *, const char *); - /* * Check whether a particular flag is set */ |