summaryrefslogtreecommitdiff
path: root/uclient-fetch.c
Commit message (Collapse)AuthorAgeFilesLines
* uclient-fetch: document missing optionsBaptiste Jonglez2021-04-031-5/+8
| | | | | | | | Missing ones were: --no-proxy, --quiet, --continue / -c Also improved readability of several options. Signed-off-by: Baptiste Jonglez <git@bitsofnetworks.org>
* uclient-fetch: wolfSSL: fix certificate validationPetr Štetiar2020-12-111-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently wolfSSL doesn't validate any certificates, quoting from README: wolfSSL takes a different approach to certificate verification than OpenSSL does. The default policy for the client is to verify the server, this means that if you don't load CAs to verify the server you'll get a connect error, no signer error to confirm failure (-188). If you want to mimic OpenSSL behavior of having SSL_connect succeed even if verifying the server fails and reducing security you can do this by calling: wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0); before calling wolfSSL_new();. Though it's not recommended. wolfSSL simply behaves differently then OpenSSL so once you set SSL_VERIFY_NONE wolfSSL doesn't care about the certificates anymore so every call to SSL_get_verify_result() is going to succeed (returns X509_V_OK) even for invalid certificates and current OpenSSL based post connection verification logic thus doesn't work. So in order to get the validation working we need to use SSL_VERIFY_PEER for wolfSSL by default and allow disabling it explicitly by new `context_set_require_validation()` call. Fixes: FS#3465 Signed-off-by: Petr Štetiar <ynezz@true.cz>
* uclient-fetch: init_ca_cert: fix memory leakPetr Štetiar2020-12-111-0/+1
| | | | | | | | | | | | | | | | Fixes following memory leak: $ valgrind --quiet --leak-check=full uclient-fetch -q http://127.0.0.1:1922/does-not-exist 51 (16 direct, 35 indirect) bytes in 1 blocks are definitely lost in loss record 4 of 9 at 0x4C31A3F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x4C33D84: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x553C7DF: glob_in_dir (glob.c:1410) by 0x553D5E8: glob@@GLIBC_2.27 (glob.c:1097) by 0x401D62: init_ca_cert (uclient-fetch.c:503) by 0x401D62: main (uclient-fetch.c:741) Signed-off-by: Petr Štetiar <ynezz@true.cz>
* uclient-fetch: fix potential memory leaksPetr Štetiar2020-12-111-2/+2
| | | | | | | | | | | | | Fixes following issue reported by clang-12 static analyzer: uclient-fetch.c:612:25: warning: Potential leak of memory pointed to by 'username' [unix.Malloc] memset(optarg, '*', strlen(optarg)); ^~~~~~~~~~~~~~ uclient-fetch.c:618:25: warning: Potential leak of memory pointed to by 'password' [unix.Malloc] memset(optarg, '*', strlen(optarg)); ^~~~~~~~~~~~~~ Signed-off-by: Petr Štetiar <ynezz@true.cz>
* uclient-fetch: fix statement may fallt hroughPetr Štetiar2020-12-111-0/+1
| | | | | | | | | | | | | Fixes following issue reported by clang-12 static analyzer: uclient-fetch.c:228:6: error: this statement may fall through [-Werror=implicit-fallthrough=] if (sscanf(blobmsg_get_string(tb[H_RANGE]), ^ uclient-fetch.c:236:2: note: here case 204: ^~~~ Signed-off-by: Petr Štetiar <ynezz@true.cz>
* Fix extra compiler warningsPetr Štetiar2020-12-111-15/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes following -Wextra compiler warnings: uclient.c:195:16: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] for (i = 0; i < ARRAY_SIZE(backends); i++) { ~ ^ ~~~~~~~~~~~~~~~~~~~~ uclient-http.c:619:2: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] blobmsg_for_each_attr(cur, uh->headers.head, rem) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ uclient-http.c:619:2: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] blobmsg_for_each_attr(cur, uh->headers.head, rem) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ uclient-http.c:993:16: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] for (i = 0; i < ARRAY_SIZE(request_types); i++) { ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~ uclient.c:195:16: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] for (i = 0; i < ARRAY_SIZE(backends); i++) { ~ ^ ~~~~~~~~~~~~~~~~~~~~ uclient-http.c:619:2: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare] blobmsg_for_each_attr(cur, uh->headers.head, rem) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ uclient-http.c:619:2: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] blobmsg_for_each_attr(cur, uh->headers.head, rem) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ uclient-http.c:993:16: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] for (i = 0; i < ARRAY_SIZE(request_types); i++) { ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~ uclient-fetch.c:551:67: error: missing field 'flag' initializer [-Werror,-Wmissing-field-initializers] [L_NO_CHECK_CERTIFICATE] = { "no-check-certificate", no_argument }, Signed-off-by: Petr Štetiar <ynezz@true.cz>
* uclient-fetch: add option to read POST data from fileGio2020-06-171-2/+29
| | | | | | | | | | | | | Passing post data in command line is convenient but has limited size, and may become tricky to correctly escape passed data especially in scripts. This patch add the option --post-file so the data to post can be read from a file. Tested on x86/64. Acked-by: Jo-Philipp Wich <jo@mein.io> Signed-off-by: Gioacchino Mazzurco <gio@eigenlab.org> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* uclient-fetch: support specifying advertised TLS ciphersJo-Philipp Wich2020-02-151-0/+12
| | | | | | | | | | | Introduce a new `--ciphers` option which allows specifying a colon separated list of usable TLS ciphers. Depending on the underlying ustream-ssl provider, the list either follows OpenSSL's cipher string format or, in case of mbedTLS, is a simple colon separated cipher whitelist. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* uclient-fetch: Check for nullpointer returned by uclient_get_url_filenameTobias Schramm2018-02-201-0/+6
| | | | | | | uclient_get_url_filename may return a null ptr resulting in a null ptr dereference by fprintf and open Signed-off-by: Tobias Schramm <tobleminer@gmail.com>
* uclient-fetch: use package name pattern in message for missing SSL libraryMichael Heimpold2018-02-121-1/+1
| | | | | | | | | | | | | When faced with this error message, I did not directly know what package(s) to install. I first grepped the package list for packages named libustream-ssl... found nothing, and finally realized, that here only the library name was mentioned. But when we mention the certificate packages, why not also directly mention the SSL/TLS packages with a pattern. That will save one step next time when stumbling here - at least for me ;-) Signed-off-by: Michael Heimpold <mhei@heimpold.de>
* uclient-fetch: fix overloading of output_file variableFelix Fietkau2017-11-021-3/+4
| | | | | | | | | | | | | When uclient-fetch is called with multiple URL's, it derives the first filename from the URL. It then sets the global output_file variable, causing a use-after-free bug on an attempt to use it as output file for the next file. Fix this by avoiding the overwrite entirely by only setting a local variable Reported-by: Philip Prindeville <philipp@redfish-solutions.com> Signed-off-by: Felix Fietkau <nbd@nbd.name>
* uclient-fetch: read_data_cb: fix a potential buffer overflowAlexander Couzens2017-06-111-1/+1
| | | | | | | | When a backend->read() is not implement or returns -1, This -1 is interpreted as unsigned int resulting in an access far behind the buffer. Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
* Fix unused results warningsFlorian Fainelli2016-12-091-5/+11
| | | | | | | | | | | | | | | | | | Fixes: uclient-http.c:385:8: error: ignoring return value of 'fread', declared with attribute warn_unused_result [-Werror=unused-result] fread(&val, sizeof(val), 1, f); ^ uclient-fetch.c: In function 'main': uclient-fetch.c:664:12: error: ignoring return value of 'asprintf', declared with attribute warn_unused_result [-Werror=unused-result] asprintf(&auth_str, "%s:%s", username, password); ^ uclient-fetch.c: In function 'read_data_cb': uclient-fetch.c:269:9: error: ignoring return value of 'write', declared with attribute warn_unused_result [-Werror=unused-result] write(output_fd, buf, len); Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
* Fix printf format in previous commit.Jo-Philipp Wich2016-07-301-1/+1
| | | | Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* Make missing SSL support message more explicit.Jo-Philipp Wich2016-07-301-1/+6
| | | | Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* uclient-fetch: add support for --quietFelix Fietkau2016-07-051-0/+5
| | | | Signed-off-by: Felix Fietkau <nbd@nbd.name>
* uclient-fetch: fix inconsistencies in help text (thx, Hannu Nyman)Felix Fietkau2016-02-081-7/+7
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* http: add support for specifying ipv4/ipv6 preferenceFelix Fietkau2016-01-251-2/+15
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: truncate output files (unless resuming)Felix Fietkau2016-01-231-1/+1
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: fix progress bar initialization with -O-Felix Fietkau2016-01-231-1/+3
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* http: add proper error handling to uclient_http_redirect()Felix Fietkau2016-01-231-5/+15
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: allow overwriting files if -O was usedFelix Fietkau2016-01-211-1/+4
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: fix short command line option for timeoutFelix Fietkau2016-01-201-1/+1
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: add missing newline after final progress bar updateFelix Fietkau2016-01-191-0/+1
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: add progress bar supportFelix Fietkau2016-01-171-13/+50
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: add support for setting output directoryFelix Fietkau2016-01-161-1/+9
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: ignore SIGPIPEFelix Fietkau2016-01-161-0/+2
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: add proxy supportFelix Fietkau2016-01-161-3/+56
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-http: make username/password variables localFelix Fietkau2016-01-161-2/+2
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: add support for resuming downloadsFelix Fietkau2016-01-161-7/+105
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: clean up output file selectionFelix Fietkau2016-01-161-11/+11
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: add support for --timeoutFelix Fietkau2016-01-161-0/+13
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: add support for --spiderFelix Fietkau2016-01-161-3/+16
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: add support for --post-dataFelix Fietkau2016-01-161-1/+13
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: only add default CA entries if no certificate was supplied ↵Felix Fietkau2016-01-161-1/+1
| | | | | | and verify was requested Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: add support for setting the user agentFelix Fietkau2016-01-161-1/+14
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: add support for fetching multiple urlsFelix Fietkau2016-01-161-17/+38
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: add user/password to command line helpFelix Fietkau2016-01-161-0/+2
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* uclient-fetch: load CA certificatesFelix Fietkau2016-01-161-1/+19
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* support for connection timeoutRafał Miłecki2015-01-181-0/+4
| | | | Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
* fetch: fix segfault after destination was not reachedLuka Perkov2014-07-071-6/+28
| | | | Signed-off-by: Luka Perkov <luka@openwrt.org>
* uclient-fetch: define _GNU_SOURCE (used for asprintf)Felix Fietkau2014-05-091-0/+1
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* fetch: print the URL while connectingFelix Fietkau2014-05-081-1/+4
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* fetch: add support for --user and --passwordFelix Fietkau2014-05-081-1/+27
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* fetch: always use O_EXCL when creating output files, use unlink if -O is ↵Felix Fietkau2014-05-081-5/+2
| | | | | | specified Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* fetch: print download statusFelix Fietkau2014-05-081-0/+10
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* fetch: indicate an error if the connection was terminated prematurelyFelix Fietkau2014-05-071-0/+5
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* add uclient_get_url_filename helper functionFelix Fietkau2014-05-061-22/+6
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* fetch: print error messages on http error codesFelix Fietkau2014-05-061-0/+2
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* fetch: remove http header outputFelix Fietkau2014-05-061-10/+0
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>