1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 12:41:29 +00:00

Use ncat_assert in place of assert everywhere.

This commit is contained in:
david
2013-01-04 18:59:47 +00:00
parent b44d477344
commit 63d9e8b5d5
9 changed files with 50 additions and 61 deletions

View File

@@ -89,7 +89,6 @@
/* $Id$ */
#include <assert.h>
#include <string.h>
#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;
}

View File

@@ -102,7 +102,6 @@
#include <unistd.h>
#include <netdb.h>
#endif
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -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);

View File

@@ -107,7 +107,6 @@
#include <fcntl.h>
#include <ctype.h>
#include <time.h>
#include <assert.h>
/* 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);

View File

@@ -89,8 +89,6 @@
/* $Id$ */
#include <assert.h>
#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)

View File

@@ -91,7 +91,6 @@
#include "ncat.h"
#include <assert.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
@@ -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;
}

View File

@@ -89,8 +89,6 @@
/* $Id$ */
#include <assert.h>
#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);

View File

@@ -95,7 +95,6 @@
#include "nsock.h"
#include "ncat.h"
#include <assert.h>
#include <stdio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
@@ -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;

View File

@@ -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 <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -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);

View File

@@ -95,7 +95,6 @@
#include "nbase.h"
#include "sockaddr_u.h"
#include <assert.h>
#include <stdio.h>
#ifdef WIN32
#include <iphlpapi.h>
@@ -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;