From 4d1450cc691292cef5bcfdd41cefc030e4dabbf6 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 15 Jun 2015 14:58:36 +0200 Subject: [PATCH] Fix ZOOM: crash extended services diagnostics YAZ-846 The immediate fix is to prevent ZOOM_set_dset_error from removing current task from connection. This, however, has been assumed in a number of places so this fix is rather large unfortunately. --- src/zoom-c.c | 4 ++-- src/zoom-p.h | 1 + src/zoom-sru.c | 11 ++++++----- src/zoom-z3950.c | 7 +++++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/zoom-c.c b/src/zoom-c.c index 53cbb10..b6cc643 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -49,7 +49,6 @@ static void initlog(void) } } -void ZOOM_connection_remove_tasks(ZOOM_connection c); static zoom_ret send_HTTP_redirect(ZOOM_connection c, const char *uri); void ZOOM_set_dset_error(ZOOM_connection c, int error, @@ -84,7 +83,6 @@ void ZOOM_set_dset_error(ZOOM_connection c, int error, c, c->host_port ? c->host_port : "<>", dset, error, addinfo ? addinfo : "", addinfo2 ? addinfo2 : ""); - ZOOM_connection_remove_tasks(c); } } @@ -189,6 +187,8 @@ void ZOOM_connection_remove_task(ZOOM_connection c) if (task) { c->tasks = task->next; + yaz_log(YLOG_LOG, "remove task p=%d type=%d next=%p", + task, (int) task->which, c->tasks); switch (task->which) { case ZOOM_TASK_SEARCH: diff --git a/src/zoom-p.h b/src/zoom-p.h index 236313b..79f2f44 100644 --- a/src/zoom-p.h +++ b/src/zoom-p.h @@ -247,6 +247,7 @@ zoom_ret ZOOM_connection_Z3950_send_init(ZOOM_connection c); ZOOM_task ZOOM_connection_add_task(ZOOM_connection c, int which); void ZOOM_connection_remove_task(ZOOM_connection c); +void ZOOM_connection_remove_tasks(ZOOM_connection c); int ZOOM_test_reconnect(ZOOM_connection c); ZOOM_record ZOOM_record_cache_lookup(ZOOM_resultset r, int pos, diff --git a/src/zoom-sru.c b/src/zoom-sru.c index 17f7c18..bf89a44 100644 --- a/src/zoom-sru.c +++ b/src/zoom-sru.c @@ -391,14 +391,14 @@ static zoom_ret handle_srw_response(ZOOM_connection c, #endif #if YAZ_HAVE_XML2 -static void handle_srw_scan_response(ZOOM_connection c, - Z_SRW_scanResponse *res) +static zoom_ret handle_srw_scan_response(ZOOM_connection c, + Z_SRW_scanResponse *res) { NMEM nmem = odr_extract_mem(c->odr_in); ZOOM_scanset scan; if (!c->tasks || c->tasks->which != ZOOM_TASK_SCAN) - return; + return zoom_complete; scan = c->tasks->u.scan.scan; if (res->num_diagnostics > 0) @@ -410,6 +410,7 @@ static void handle_srw_scan_response(ZOOM_connection c, ZOOM_options_set_int(scan->options, "number", res->num_terms); nmem_destroy(nmem); + return zoom_complete; } #endif @@ -434,7 +435,7 @@ int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres, if (sr->which == Z_SRW_searchRetrieve_response) *cret = handle_srw_response(c, sr->u.response); else if (sr->which == Z_SRW_scan_response) - handle_srw_scan_response(c, sr->u.scan_response); + *cret = handle_srw_scan_response(c, sr->u.scan_response); } } else @@ -460,7 +461,7 @@ int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres, if (sr->which == Z_SRW_searchRetrieve_response) *cret = handle_srw_response(c, sr->u.response); else if (sr->which == Z_SRW_scan_response) - handle_srw_scan_response(c, sr->u.scan_response); + *cret = handle_srw_scan_response(c, sr->u.scan_response); else ret = -1; } diff --git a/src/zoom-z3950.c b/src/zoom-z3950.c index 701f5a4..9c810e8 100644 --- a/src/zoom-z3950.c +++ b/src/zoom-z3950.c @@ -1309,7 +1309,10 @@ static void handle_Z3950_search_response(ZOOM_connection c, static void handle_Z3950_sort_response(ZOOM_connection c, Z_SortResponse *res) { if (res->diagnostics && res->num_diagnostics > 0) + { response_diag(c, res->diagnostics[0]); + ZOOM_connection_remove_tasks(c); + } } static void handle_Z3950_scan_response(ZOOM_connection c, Z_ScanResponse *res) @@ -1356,13 +1359,17 @@ static void handle_Z3950_records(ZOOM_connection c, Z_Records *sr, schema = c->tasks->u.search.schema; if (sr && sr->which == Z_Records_NSD) + { response_default_diag(c, sr->u.nonSurrogateDiagnostic); + ZOOM_connection_remove_tasks(c); + } else if (sr && sr->which == Z_Records_multipleNSD) { if (sr->u.multipleNonSurDiagnostics->num_diagRecs >= 1) response_diag(c, sr->u.multipleNonSurDiagnostics->diagRecs[0]); else ZOOM_set_error(c, ZOOM_ERROR_DECODE, 0); + ZOOM_connection_remove_tasks(c); } else { -- 1.7.10.4