diff options
author | Alessandro Ghedini <alessandro@ghedini.me> | 2015-04-22 10:25:34 +0200 |
---|---|---|
committer | Alessandro Ghedini <alessandro@ghedini.me> | 2015-04-22 10:25:34 +0200 |
commit | 7b1fa5a0c5daf3831b9857c8fa678aaa6679d618 (patch) | |
tree | fd89ac2d30f1dcf60c769ec994177e1ae09fa3fa /src/tool_metalink.c | |
parent | a8501fab9f2f579a6951c1cfcbc8f60b3d39af7f (diff) |
Imported Upstream version 7.42.0
Diffstat (limited to 'src/tool_metalink.c')
-rw-r--r-- | src/tool_metalink.c | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/src/tool_metalink.c b/src/tool_metalink.c index 3573b058..5873adf6 100644 --- a/src/tool_metalink.c +++ b/src/tool_metalink.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -29,14 +29,9 @@ # include <fcntl.h> #endif -#ifdef USE_SSLEAY -# ifdef USE_OPENSSL -# include <openssl/md5.h> -# include <openssl/sha.h> -# else -# include <md5.h> -# include <sha.h> -# endif +#ifdef USE_OPENSSL +# include <openssl/md5.h> +# include <openssl/sha.h> #elif defined(USE_GNUTLS_NETTLE) # include <nettle/md5.h> # include <nettle/sha.h> @@ -381,7 +376,7 @@ static void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx) sha256_finish(ctx, digest); } -#elif defined(_WIN32) && !defined(USE_SSLEAY) +#elif defined(_WIN32) && !defined(USE_OPENSSL) static void win32_crypto_final(struct win32_crypto_hash *ctx, unsigned char *digest, @@ -626,6 +621,10 @@ static int check_hash(const char *filename, } result = malloc(digest_def->dparams->digest_resultlen); + if(!result) { + close(fd); + return -1; + } while(1) { unsigned char buf[4096]; ssize_t len = read(fd, buf, sizeof(buf)); @@ -681,12 +680,17 @@ static metalink_checksum *new_metalink_checksum_from_hex_digest size_t i; size_t len = strlen(hex_digest); digest = malloc(len/2); + if(!digest) + return 0; + for(i = 0; i < len; i += 2) { digest[i/2] = hex_to_uint(hex_digest+i); } chksum = malloc(sizeof(metalink_checksum)); - chksum->digest_def = digest_def; - chksum->digest = digest; + if(chksum) { + chksum->digest_def = digest_def; + chksum->digest = digest; + } return chksum; } @@ -694,8 +698,14 @@ static metalink_resource *new_metalink_resource(const char *url) { metalink_resource *res; res = malloc(sizeof(metalink_resource)); - res->next = NULL; - res->url = strdup(url); + if(res) { + res->next = NULL; + res->url = strdup(url); + if(!res->url) { + free(res); + return NULL; + } + } return res; } @@ -720,8 +730,15 @@ static metalinkfile *new_metalinkfile(metalink_file_t *fileinfo) { metalinkfile *f; f = (metalinkfile*)malloc(sizeof(metalinkfile)); + if(!f) + return NULL; + f->next = NULL; f->filename = strdup(fileinfo->name); + if(!f->filename) { + free(f); + return NULL; + } f->checksum = NULL; f->resource = NULL; if(fileinfo->checksums) { @@ -822,8 +839,10 @@ int parse_metalink(struct OperationConfig *config, struct OutStruct *outs, url = new_getout(config); if(url) { - metalinkfile *mlfile; - mlfile = new_metalinkfile(*files); + metalinkfile *mlfile = new_metalinkfile(*files); + if(!mlfile) + break; + if(!mlfile->checksum) { warnings = TRUE; fprintf(config->global->errors, |