#include "connection.h"
#include <arpa/inet.h>
+#include <assert.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
+#include <limits.h>
#if GNUTLS_VERSION_NUMBER <= 0x020b00
/* Necessary for GnuTLS when used with threads. */
free(global_proxy_host);
free(global_proxy_port);
+ free(global_http_digest_authorization);
return EXIT_FAILURE;
}
while ((option = getopt(argc, argv, "a:d:p:t:uh?")) != -1) {
switch (option) {
case 'a': {
- http_digest_authorization = slurp_text_file(optarg);
- if (http_digest_authorization == NULL) {
+ global_http_digest_authorization = slurp_text_file(optarg);
+ if (global_http_digest_authorization == NULL) {
fprintf(stderr, "failed to open authorization file '%s': ",
optarg);
perror("");
exit(EXIT_FAILURE);
- } else if (strlen(http_digest_authorization) == 0) {
+ } else if (strlen(global_http_digest_authorization) == 0) {
fprintf(stderr, "empty authorization file '%s'\n",
optarg);
exit(EXIT_FAILURE);
}
/* Just in case the file has a trailing newline. */
- strtok(http_digest_authorization, "\r\n");
+ strtok(global_http_digest_authorization, "\r\n");
break;
}
gnutls_datum_t dh_parameters_datum;
/* Recent versions of GnuTLS automatically initialize the cryptography layer
- * in gnutls_global_init(). */
+ * in gnutls_global_init(), including a thread-safe setup. */
#if GNUTLS_VERSION_NUMBER <= 0x020b00
gcry_error_t error;
}
#endif
+ if (gnutls_check_version(GNUTLS_VERSION) == NULL) {
+ fprintf(stderr, "gnutls_check_version(): version mismatch, "
+ "expected at least '" GNUTLS_VERSION "'\n");
+ exit(EXIT_FAILURE);
+ }
+
/* Initialize GnuTLS. */
result = gnutls_global_init();
GNUTLS_ERROR_EXIT(result, "gnutls_global_init()");
exit(EXIT_FAILURE);
}
dh_parameters_datum.data = (unsigned char *)dh_parameters;
- dh_parameters_datum.size = strlen(dh_parameters);
+ assert(strlen(dh_parameters) <= UINT_MAX);
+ dh_parameters_datum.size = (unsigned int)(strlen(dh_parameters));
result = gnutls_dh_params_init(&global_tls_dh_params);
GNUTLS_ERROR_EXIT(result, "gnutls_dh_params_init()");