diff options
author | Timo Teräs <timo.teras@iki.fi> | 2020-10-05 12:58:46 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2020-10-05 12:58:46 +0300 |
commit | 6cedfe27ac566e7de7d0c24778c4280e8311bbec (patch) | |
tree | 3d217fe42e9e7095954c3279eda778cc26fd4552 /src/print.c | |
parent | 8a794021c42baf8e1c12ae5e8e8313b66443002e (diff) | |
download | apk-tools-6cedfe27ac566e7de7d0c24778c4280e8311bbec.tar.gz apk-tools-6cedfe27ac566e7de7d0c24778c4280e8311bbec.tar.bz2 apk-tools-6cedfe27ac566e7de7d0c24778c4280e8311bbec.tar.xz apk-tools-6cedfe27ac566e7de7d0c24778c4280e8311bbec.zip |
db: mask password component of printed URLs
fixes #10710
Diffstat (limited to 'src/print.c')
-rw-r--r-- | src/print.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/print.c b/src/print.c index 0b79752..38dad1c 100644 --- a/src/print.c +++ b/src/print.c @@ -211,3 +211,27 @@ void apk_log_err(const char *prefix, const char *format, ...) log_internal(stderr, prefix, format, va); va_end(va); } + +void apk_url_parse(struct apk_url_print *urlp, const char *url) +{ + const char *authority, *path_or_host, *pw; + + *urlp = (struct apk_url_print) { + .url = "", + .pwmask = "", + .url_or_host = url, + }; + + if (!(authority = strstr(url, "://"))) return; + authority += 3; + path_or_host = strpbrk(authority, "/@"); + if (!path_or_host || *path_or_host == '/') return; + pw = strpbrk(authority, "@:"); + if (!pw || *pw == '@') return; + *urlp = (struct apk_url_print) { + .url = url, + .pwmask = "*", + .url_or_host = path_or_host, + .len_before_pw = pw - url + 1, + }; +} |