summaryrefslogtreecommitdiff
path: root/libfetch/common.h
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2021-07-16 10:54:08 +0300
committerTimo Teräs <timo.teras@iki.fi>2021-07-26 14:43:35 +0300
commit36048e8fef019c5be938f8a688845b6eef1d46ab (patch)
tree0aa34f757463289276b3ccacc5395fdc5decca85 /libfetch/common.h
parent41a6e4c247e68e906bea1ca7c31f0e8d3b49bc83 (diff)
downloadapk-tools-36048e8fef019c5be938f8a688845b6eef1d46ab.tar.gz
apk-tools-36048e8fef019c5be938f8a688845b6eef1d46ab.tar.bz2
apk-tools-36048e8fef019c5be938f8a688845b6eef1d46ab.tar.xz
apk-tools-36048e8fef019c5be938f8a688845b6eef1d46ab.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.h12
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
*/