diff --git a/ncat/http.c b/ncat/http.c index e3eae16ad..6739378a2 100644 --- a/ncat/http.c +++ b/ncat/http.c @@ -89,7 +89,6 @@ /* $Id$ */ -#include #include #include "base64.h" @@ -528,7 +527,7 @@ static const char *skip_crlf(const char *s) else if (*s == '\r' && *(s + 1) == '\n') return s + 2; - assert(0); + ncat_assert(0); return NULL; } diff --git a/ncat/ncat_connect.c b/ncat/ncat_connect.c index 5b0e278d9..8d6e1a8f8 100644 --- a/ncat/ncat_connect.c +++ b/ncat/ncat_connect.c @@ -102,7 +102,6 @@ #include #include #endif -#include #include #include #include @@ -164,7 +163,7 @@ static int verify_callback(int ok, X509_STORE_CTX *store) X509_NAME_print_ex_fp(stderr, X509_get_issuer_name(cert), 0, XN_FLAG_COMPAT); loguser_noprefix("\n"); - assert(ssl_cert_fp_str_sha1(cert, digest_buf, sizeof(digest_buf)) != NULL); + ncat_assert(ssl_cert_fp_str_sha1(cert, digest_buf, sizeof(digest_buf)) != NULL); loguser("SHA-1 fingerprint: %s\n", digest_buf); } @@ -227,7 +226,7 @@ static void connect_report(nsock_iod nsi) loguser("SSL connection to %s:%hu.", inet_socktop(&peer), nsi_peerport(nsi)); cert = SSL_get_peer_certificate((SSL *) nsi_getssl(nsi)); - assert(cert != NULL); + ncat_assert(cert != NULL); subject = X509_get_subject_name(cert); if (subject != NULL) { @@ -241,7 +240,7 @@ static void connect_report(nsock_iod nsi) loguser_noprefix("\n"); - assert(ssl_cert_fp_str_sha1(cert, digest_buf, sizeof(digest_buf)) != NULL); + ncat_assert(ssl_cert_fp_str_sha1(cert, digest_buf, sizeof(digest_buf)) != NULL); loguser("SHA-1 fingerprint: %s\n", digest_buf); } else { #if HAVE_SYS_UN_H @@ -706,7 +705,7 @@ static void connect_handler(nsock_pool nsp, nsock_event evt, void *data) enum nse_status status = nse_status(evt); enum nse_type type = nse_type(evt); - assert(type == NSE_TYPE_CONNECT || type == NSE_TYPE_CONNECT_SSL); + ncat_assert(type == NSE_TYPE_CONNECT || type == NSE_TYPE_CONNECT_SSL); if (status == NSE_STATUS_ERROR) { loguser("%s.\n", socket_strerror(nse_errorcode(evt))); @@ -715,7 +714,7 @@ static void connect_handler(nsock_pool nsp, nsock_event evt, void *data) loguser("%s.\n", socket_strerror(ETIMEDOUT)); exit(1); } else { - assert(status == NSE_STATUS_SUCCESS); + ncat_assert(status == NSE_STATUS_SUCCESS); } #ifdef HAVE_OPENSSL @@ -779,7 +778,7 @@ static void read_stdin_handler(nsock_pool nsp, nsock_event evt, void *data) char *buf, *tmp = NULL; int nbytes; - assert(type == NSE_TYPE_READ); + ncat_assert(type == NSE_TYPE_READ); if (status == NSE_STATUS_EOF) { if (o.sendonly) { @@ -798,7 +797,7 @@ static void read_stdin_handler(nsock_pool nsp, nsock_event evt, void *data) } else if (status == NSE_STATUS_CANCELLED || status == NSE_STATUS_KILL) { return; } else { - assert(status == NSE_STATUS_SUCCESS); + ncat_assert(status == NSE_STATUS_SUCCESS); } buf = nse_readbuf(evt, &nbytes); @@ -828,7 +827,7 @@ static void read_socket_handler(nsock_pool nsp, nsock_event evt, void *data) char *buf; int nbytes; - assert(type == NSE_TYPE_READ); + ncat_assert(type == NSE_TYPE_READ); if (status == NSE_STATUS_EOF) { nsock_loop_quit(nsp); @@ -842,7 +841,7 @@ static void read_socket_handler(nsock_pool nsp, nsock_event evt, void *data) } else if (status == NSE_STATUS_CANCELLED || status == NSE_STATUS_KILL) { return; } else { - assert(status == NSE_STATUS_SUCCESS); + ncat_assert(status == NSE_STATUS_SUCCESS); } buf = nse_readbuf(evt, &nbytes); @@ -867,7 +866,7 @@ static void write_socket_handler(nsock_pool nsp, nsock_event evt, void *data) enum nse_status status = nse_status(evt); enum nse_type type = nse_type(evt); - assert(type == NSE_TYPE_WRITE); + ncat_assert(type == NSE_TYPE_WRITE); if (status == NSE_STATUS_ERROR) { loguser("%s.\n", socket_strerror(nse_errorcode(evt))); @@ -878,7 +877,7 @@ static void write_socket_handler(nsock_pool nsp, nsock_event evt, void *data) } else if (status == NSE_STATUS_CANCELLED || status == NSE_STATUS_KILL) { return; } else { - assert(status == NSE_STATUS_SUCCESS); + ncat_assert(status == NSE_STATUS_SUCCESS); } /* The write to the socket was successful. Allow reading more from stdin @@ -891,12 +890,12 @@ static void idle_timer_handler(nsock_pool nsp, nsock_event evt, void *data) enum nse_status status = nse_status(evt); enum nse_type type = nse_type(evt); - assert(type == NSE_TYPE_TIMER); + ncat_assert(type == NSE_TYPE_TIMER); if (status == NSE_STATUS_CANCELLED || status == NSE_STATUS_KILL) return; - assert(status == NSE_STATUS_SUCCESS); + ncat_assert(status == NSE_STATUS_SUCCESS); loguser("Idle timeout expired (%d ms).\n", o.idletimeout); diff --git a/ncat/ncat_core.c b/ncat/ncat_core.c index 213dd6954..6da1bbc57 100644 --- a/ncat/ncat_core.c +++ b/ncat/ncat_core.c @@ -107,7 +107,6 @@ #include #include #include -#include /* Only two for now because we might have to listen on IPV4 and IPV6 */ union sockaddr_u listenaddrs[NUM_LISTEN_ADDRS]; @@ -191,9 +190,9 @@ static int resolve_internal(const char *hostname, unsigned short port, char portbuf[16]; int rc; - assert(hostname); - assert(ss); - assert(sslen); + ncat_assert(hostname != NULL); + ncat_assert(ss != NULL); + ncat_assert(sslen != NULL); memset(&hints, 0, sizeof(hints)); hints.ai_family = af; @@ -202,14 +201,14 @@ static int resolve_internal(const char *hostname, unsigned short port, /* Make the port number a string to give to getaddrinfo. */ rc = Snprintf(portbuf, sizeof(portbuf), "%hu", port); - assert(rc >= 0 && (size_t) rc < sizeof(portbuf)); + ncat_assert(rc >= 0 && (size_t) rc < sizeof(portbuf)); rc = getaddrinfo(hostname, portbuf, &hints, &result); if (rc != 0) return rc; if (result == NULL) return EAI_NONAME; - assert(result->ai_addrlen > 0 && result->ai_addrlen <= (int) sizeof(struct sockaddr_storage)); + ncat_assert(result->ai_addrlen > 0 && result->ai_addrlen <= (int) sizeof(struct sockaddr_storage)); *sslen = result->ai_addrlen; memcpy(ss, result->ai_addr, *sslen); freeaddrinfo(result); diff --git a/ncat/ncat_exec_win.c b/ncat/ncat_exec_win.c index 10743e359..6efdc3269 100644 --- a/ncat/ncat_exec_win.c +++ b/ncat/ncat_exec_win.c @@ -89,8 +89,6 @@ /* $Id$ */ -#include - #include "ncat.h" /* This structure holds information about a subprocess with redirected input @@ -186,11 +184,11 @@ extern void set_pseudo_sigchld_handler(void (*handler)(void)) { if (pseudo_sigchld_mutex == NULL) { pseudo_sigchld_mutex = CreateMutex(NULL, FALSE, NULL); - assert(pseudo_sigchld_mutex != NULL); + ncat_assert(pseudo_sigchld_mutex != NULL); } - assert(WaitForSingleObject(pseudo_sigchld_mutex, INFINITE) == WAIT_OBJECT_0); + ncat_assert(WaitForSingleObject(pseudo_sigchld_mutex, INFINITE) == WAIT_OBJECT_0); pseudo_sigchld_handler = handler; - assert(ReleaseMutex(pseudo_sigchld_mutex) != 0); + ncat_assert(ReleaseMutex(pseudo_sigchld_mutex) != 0); } /* Run a command and redirect its input and output handles to a pair of @@ -450,7 +448,7 @@ loop_end: WSACloseEvent(events[0]); - assert(unregister_subprocess(info->proc) != -1); + ncat_assert(unregister_subprocess(info->proc) != -1); GetExitCodeProcess(info->proc, &ret); if (ret == STILL_ACTIVE) { @@ -472,10 +470,10 @@ loop_end: subprocess_info_close(info); free(info); - assert(WaitForSingleObject(pseudo_sigchld_mutex, INFINITE) == WAIT_OBJECT_0); + ncat_assert(WaitForSingleObject(pseudo_sigchld_mutex, INFINITE) == WAIT_OBJECT_0); if (pseudo_sigchld_handler != NULL) pseudo_sigchld_handler(); - assert(ReleaseMutex(pseudo_sigchld_mutex) != 0); + ncat_assert(ReleaseMutex(pseudo_sigchld_mutex) != 0); return ret; } @@ -488,7 +486,7 @@ static int get_subprocess_slot(void) { int i, free_index, max_index; - assert(WaitForSingleObject(subprocesses_mutex, INFINITE) == WAIT_OBJECT_0); + ncat_assert(WaitForSingleObject(subprocesses_mutex, INFINITE) == WAIT_OBJECT_0); free_index = -1; max_index = 0; @@ -508,7 +506,7 @@ static int get_subprocess_slot(void) free_index = max_index++; subprocess_max_index = max_index; - assert(ReleaseMutex(subprocesses_mutex) != 0); + ncat_assert(ReleaseMutex(subprocesses_mutex) != 0); return free_index; } @@ -523,14 +521,14 @@ static int register_subprocess(HANDLE proc) if (subprocesses_mutex == NULL) { subprocesses_mutex = CreateMutex(NULL, FALSE, NULL); - assert(subprocesses_mutex != NULL); + ncat_assert(subprocesses_mutex != NULL); } if (pseudo_sigchld_mutex == NULL) { pseudo_sigchld_mutex = CreateMutex(NULL, FALSE, NULL); - assert(pseudo_sigchld_mutex != NULL); + ncat_assert(pseudo_sigchld_mutex != NULL); } - assert(WaitForSingleObject(subprocesses_mutex, INFINITE) == WAIT_OBJECT_0); + ncat_assert(WaitForSingleObject(subprocesses_mutex, INFINITE) == WAIT_OBJECT_0); i = get_subprocess_slot(); if (i == -1) { @@ -551,7 +549,7 @@ static int register_subprocess(HANDLE proc) } } - assert(ReleaseMutex(subprocesses_mutex) != 0); + ncat_assert(ReleaseMutex(subprocesses_mutex) != 0); return i; } @@ -562,7 +560,7 @@ static int unregister_subprocess(HANDLE proc) { int i; - assert(WaitForSingleObject(subprocesses_mutex, INFINITE) == WAIT_OBJECT_0); + ncat_assert(WaitForSingleObject(subprocesses_mutex, INFINITE) == WAIT_OBJECT_0); for (i = 0; i < subprocess_max_index; i++) { if (proc == subprocesses[i]) @@ -576,7 +574,7 @@ static int unregister_subprocess(HANDLE proc) i = -1; } - assert(ReleaseMutex(subprocesses_mutex) != 0); + ncat_assert(ReleaseMutex(subprocesses_mutex) != 0); return i; } @@ -588,7 +586,7 @@ static void terminate_subprocesses(void) if (o.debug) logdebug("Terminating subprocesses\n"); - assert(WaitForSingleObject(subprocesses_mutex, INFINITE) == WAIT_OBJECT_0); + ncat_assert(WaitForSingleObject(subprocesses_mutex, INFINITE) == WAIT_OBJECT_0); if (o.debug > 1) logdebug("max_index %d\n", subprocess_max_index); @@ -607,7 +605,7 @@ static void terminate_subprocesses(void) subprocesses[i] = NULL; } - assert(ReleaseMutex(subprocesses_mutex) != 0); + ncat_assert(ReleaseMutex(subprocesses_mutex) != 0); } static void sigint_handler(int s) diff --git a/ncat/ncat_listen.c b/ncat/ncat_listen.c index 2c0b948e3..3a4a0acee 100644 --- a/ncat/ncat_listen.c +++ b/ncat/ncat_listen.c @@ -91,7 +91,6 @@ #include "ncat.h" -#include #include #include #include @@ -183,7 +182,7 @@ static int get_conn_count(void) conn_dec_changed = 0; count = conn_inc - conn_dec; } while (conn_dec_changed); - assert(count <= INT_MAX); + ncat_assert(count <= INT_MAX); return count; } diff --git a/ncat/ncat_posix.c b/ncat/ncat_posix.c index 9dbb4f09b..afac3f333 100644 --- a/ncat/ncat_posix.c +++ b/ncat/ncat_posix.c @@ -89,8 +89,6 @@ /* $Id$ */ -#include - #include "ncat.h" char **cmdline_split(const char *cmdexec); @@ -350,7 +348,7 @@ int ssl_load_default_ca_certs(SSL_CTX *ctx) logdebug("Using system default trusted CA certificates and those in %s.\n", NCAT_CA_CERTS_PATH); /* Load distribution-provided defaults, if any. */ - assert(SSL_CTX_set_default_verify_paths(ctx) > 0); + ncat_assert(SSL_CTX_set_default_verify_paths(ctx) > 0); /* Also load the trusted certificates we ship. */ rc = SSL_CTX_load_verify_locations(ctx, NCAT_CA_CERTS_PATH, NULL); diff --git a/ncat/ncat_ssl.c b/ncat/ncat_ssl.c index 61c165f6c..d7a94b5f5 100644 --- a/ncat/ncat_ssl.c +++ b/ncat/ncat_ssl.c @@ -95,7 +95,6 @@ #include "nsock.h" #include "ncat.h" -#include #include #include #include @@ -160,7 +159,7 @@ SSL_CTX *setup_ssl_listen(void) if (ssl_gen_cert(&cert, &key) == 0) bye("ssl_gen_cert(): %s.", ERR_error_string(ERR_get_error(), NULL)); if (o.verbose) { - assert(ssl_cert_fp_str_sha1(cert, digest_buf, sizeof(digest_buf)) != NULL); + ncat_assert(ssl_cert_fp_str_sha1(cert, digest_buf, sizeof(digest_buf)) != NULL); loguser("SHA-1 fingerprint: %s\n", digest_buf); } if (SSL_CTX_use_certificate(sslctx, cert) != 1) @@ -562,7 +561,7 @@ char *ssl_cert_fp_str_sha1(const X509 *cert, char *strbuf, size_t len) Snprintf(p, 3, "%02X", binbuf[i]); p += 2; } - assert(p - strbuf <= len); + ncat_assert(p - strbuf <= len); *p = '\0'; return strbuf; diff --git a/ncat/test/test-wildcard.c b/ncat/test/test-wildcard.c index cbcaa99d5..f675adc00 100644 --- a/ncat/test/test-wildcard.c +++ b/ncat/test/test-wildcard.c @@ -7,7 +7,6 @@ dNSNames, then checks that matching names are accepted and non-matching names are rejected. The SSL transactions happen over OpenSSL BIO pairs. */ -#include #include #include #include @@ -68,28 +67,28 @@ static int test(const struct lstr commonNames[], const struct lstr dNSNames[], tests_run++; - assert(gen_cert(&cert, &key, commonNames, dNSNames) == 1); + ncat_assert(gen_cert(&cert, &key, commonNames, dNSNames) == 1); - assert(BIO_new_bio_pair(&server_bio, 0, &client_bio, 0) == 1); + ncat_assert(BIO_new_bio_pair(&server_bio, 0, &client_bio, 0) == 1); server_ctx = SSL_CTX_new(SSLv23_server_method()); - assert(server_ctx != NULL); + ncat_assert(server_ctx != NULL); client_ctx = SSL_CTX_new(SSLv23_client_method()); - assert(client_ctx != NULL); + ncat_assert(client_ctx != NULL); SSL_CTX_set_verify(client_ctx, SSL_VERIFY_PEER, NULL); SSL_CTX_set_verify_depth(client_ctx, 1); ssl_ctx_trust_cert(client_ctx, cert); server_ssl = SSL_new(server_ctx); - assert(server_ssl != NULL); + ncat_assert(server_ssl != NULL); SSL_set_accept_state(server_ssl); SSL_set_bio(server_ssl, server_bio, server_bio); - assert(SSL_use_certificate(server_ssl, cert) == 1); - assert(SSL_use_PrivateKey(server_ssl, key) == 1); + ncat_assert(SSL_use_certificate(server_ssl, cert) == 1); + ncat_assert(SSL_use_PrivateKey(server_ssl, key) == 1); client_ssl = SSL_new(client_ctx); - assert(client_ssl != NULL); + ncat_assert(client_ssl != NULL); SSL_set_connect_state(client_ssl); SSL_set_bio(client_ssl, client_bio, client_bio); @@ -530,7 +529,7 @@ void test_specificity(const struct lstr patterns[], for (i = 0; i < ARR_LEN && !is_sentinel(&patterns[i]); i++) scratch[i] = patterns[i]; - assert(i < ARR_LEN); + ncat_assert(i < ARR_LEN); scratch[i] = lstr_sentinel; test(scratch, NULL, test_names, expected_forward); diff --git a/ncat/util.c b/ncat/util.c index 057c84358..2e2bd547e 100644 --- a/ncat/util.c +++ b/ncat/util.c @@ -95,7 +95,6 @@ #include "nbase.h" #include "sockaddr_u.h" -#include #include #ifdef WIN32 #include @@ -212,7 +211,7 @@ void zmem(void *mem, size_t n) buffer and updates the variables to make room if necessary. */ int strbuf_append(char **buf, size_t *size, size_t *offset, const char *s, size_t n) { - assert(*offset <= *size); + ncat_assert(*offset <= *size); if (n >= *size - *offset) { *size += n + 1; @@ -239,7 +238,7 @@ int strbuf_sprintf(char **buf, size_t *size, size_t *offset, const char *fmt, .. va_list va; int n; - assert(*offset <= *size); + ncat_assert(*offset <= *size); if (*buf == NULL) { *size = 1;