mirror of
https://github.com/nmap/nmap.git
synced 2025-12-20 14:39:02 +00:00
Allow NSE_TYPE_CONNECT_SSL to be canceled.
This fixes a really bad bug that seems to have been there for a while. Canceling a nsock connect SSL operation fails with fatal(). I have never seen it in real life though. Added a corresponding unit test.
This commit is contained in:
@@ -199,6 +199,7 @@ int nsock_event_cancel(nsock_pool ms_pool, nsock_event_id id, int notify) {
|
||||
/* First we figure out what list it is in */
|
||||
switch (type) {
|
||||
case NSE_TYPE_CONNECT:
|
||||
case NSE_TYPE_CONNECT_SSL:
|
||||
event_list = &nsp->connect_events;
|
||||
break;
|
||||
|
||||
|
||||
@@ -42,6 +42,62 @@ static int basic_udata(void *tdata) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void cancel_handler(nsock_pool nsp, nsock_event nse, void *udata) {
|
||||
int *ev_done = (int *)udata;
|
||||
|
||||
if (nse_status(nse) == NSE_STATUS_CANCELLED)
|
||||
*ev_done = 1;
|
||||
}
|
||||
|
||||
static int cancel_setup(void **tdata) {
|
||||
struct basic_test_data *btd;
|
||||
|
||||
btd = calloc(1, sizeof(struct basic_test_data));
|
||||
if (btd == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
btd->nsp = nsp_new(NULL);
|
||||
|
||||
*tdata = btd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cancel_teardown(void *tdata) {
|
||||
struct basic_test_data *btd = (struct basic_test_data *)tdata;
|
||||
|
||||
if (tdata) {
|
||||
nsp_delete(btd->nsp);
|
||||
free(tdata);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cancel_run(void *tdata) {
|
||||
struct basic_test_data *btd = (struct basic_test_data *)tdata;
|
||||
struct sockaddr_in peer;
|
||||
nsock_iod iod;
|
||||
nsock_event_id id;
|
||||
int done = 0;
|
||||
|
||||
iod = nsi_new(btd->nsp, NULL);
|
||||
AssertNonNull(iod);
|
||||
|
||||
memset(&peer, 0, sizeof(peer));
|
||||
peer.sin_family = AF_INET;
|
||||
inet_aton("127.0.0.1", &peer.sin_addr);
|
||||
|
||||
id = nsock_connect_ssl(btd->nsp, iod, cancel_handler, 4000, (void *)&done,
|
||||
(struct sockaddr *)&peer, sizeof(peer), IPPROTO_TCP,
|
||||
PORT_TCPSSL, NULL);
|
||||
nsock_event_cancel(btd->nsp, id, 1);
|
||||
|
||||
nsi_delete(iod, NSOCK_PENDING_SILENT);
|
||||
|
||||
return (done == 1) ? 0 : -ENOEXEC;
|
||||
}
|
||||
|
||||
|
||||
const struct test_case TestPoolUserData = {
|
||||
.t_name = "nsock pool user data",
|
||||
.t_setup = basic_setup,
|
||||
@@ -49,4 +105,10 @@ const struct test_case TestPoolUserData = {
|
||||
.t_teardown = basic_teardown
|
||||
};
|
||||
|
||||
const struct test_case TestCancelSSLOperation = {
|
||||
.t_name = "schedule and cancel SSL connect",
|
||||
.t_setup = cancel_setup,
|
||||
.t_run = cancel_run,
|
||||
.t_teardown = cancel_teardown
|
||||
};
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
char *socket_strerror(int errnum);
|
||||
|
||||
extern const struct test_case TestPoolUserData;
|
||||
extern const struct test_case TestCancelOperation;
|
||||
extern const struct test_case TestTimer;
|
||||
extern const struct test_case TestLogLevels;
|
||||
extern const struct test_case TestErrLevels;
|
||||
@@ -38,6 +39,7 @@ extern const struct test_case TestHeapOrdering;
|
||||
static const struct test_case *TestCases[] = {
|
||||
/* ---- basic.c */
|
||||
&TestPoolUserData,
|
||||
&TestCancelOperation,
|
||||
/* ---- timer.c */
|
||||
&TestTimer,
|
||||
/* ---- logs.c */
|
||||
|
||||
Reference in New Issue
Block a user