GFS: fix sizeof: saved by the bell
[yaz-moved-to-github.git] / src / seshigh.c
index eea76c1..bd1ec84 100644 (file)
@@ -127,6 +127,16 @@ static void wr_diag(WRBUF w, int error, const char *addinfo)
     wrbuf_puts(w, " ");    
 }
 
+static int odr_int_to_int(Odr_int v)
+{
+    if (v >= INT_MAX)
+        return INT_MAX;
+    else if (v <= INT_MIN)
+        return INT_MIN;
+    else
+        return (int) v;
+}
+
 /*
  * Create and initialize a new association-handle.
  *  channel  : iochannel for the current line.
@@ -836,16 +846,7 @@ static int ccl2pqf(ODR odr, const Odr_oct *ccl, CCL_bibset bibset,
     return 0;
 }
 
-static int odr_int_to_int(Odr_int v)
-{
-    if (v >= INT_MAX)
-        return INT_MAX;
-    else if (v <= INT_MIN)
-        return INT_MIN;
-    else return v;
-}
-
-static void srw_bend_search(association *assoc, request *req,
+static void srw_bend_search(association *assoc,
                             Z_SRW_PDU *sr,
                             Z_SRW_PDU *res,
                             int *http_code)
@@ -1148,7 +1149,7 @@ static void srw_bend_search(association *assoc, request *req,
     }
 }
 
-static char *srw_bend_explain_default(void *handle, bend_explain_rr *rr)
+static char *srw_bend_explain_default(bend_explain_rr *rr)
 {
 #if YAZ_HAVE_XML2
     xmlNodePtr ptr = (xmlNode *) rr->server_node_ptr;
@@ -1184,7 +1185,7 @@ static char *srw_bend_explain_default(void *handle, bend_explain_rr *rr)
     return 0;
 }
 
-static void srw_bend_explain(association *assoc, request *req,
+static void srw_bend_explain(association *assoc,
                              Z_SRW_PDU *sr,
                              Z_SRW_explainResponse *srw_res,
                              int *http_code)
@@ -1210,7 +1211,7 @@ static void srw_bend_explain(association *assoc, request *req,
         if (assoc->init->bend_explain)
             (*assoc->init->bend_explain)(assoc->backend, &rr);
         else
-            srw_bend_explain_default(assoc->backend, &rr);
+            srw_bend_explain_default(&rr);
 
         if (rr.explain_buf)
         {
@@ -1232,7 +1233,7 @@ static void srw_bend_explain(association *assoc, request *req,
     }
 }
 
-static void srw_bend_scan(association *assoc, request *req,
+static void srw_bend_scan(association *assoc,
                           Z_SRW_PDU *sr,
                           Z_SRW_scanResponse *srw_res,
                           int *http_code)
@@ -1420,7 +1421,7 @@ static void srw_bend_scan(association *assoc, request *req,
 
 }
 
-static void srw_bend_update(association *assoc, request *req,
+static void srw_bend_update(association *assoc,
                            Z_SRW_PDU *sr,
                            Z_SRW_updateResponse *srw_res,
                            int *http_code)
@@ -1789,7 +1790,7 @@ static void process_http_request(association *assoc, request *req)
             }
             else
             {
-                srw_bend_search(assoc, req, sr, res, &http_code);
+                srw_bend_search(assoc, sr, res, &http_code);
             }
             if (http_code == 200)
                 soap_package->u.generic->p = res;
@@ -1804,8 +1805,7 @@ static void process_http_request(association *assoc, request *req)
                 res->u.explain_response->diagnostics = diagnostic;
                 res->u.explain_response->num_diagnostics = num_diagnostic;
             }
-            srw_bend_explain(assoc, req, sr,
-                             res->u.explain_response, &http_code);
+            srw_bend_explain(assoc, sr, res->u.explain_response, &http_code);
             if (http_code == 200)
                 soap_package->u.generic->p = res;
         }
@@ -1819,8 +1819,7 @@ static void process_http_request(association *assoc, request *req)
                 res->u.scan_response->diagnostics = diagnostic;
                 res->u.scan_response->num_diagnostics = num_diagnostic;
             }
-            srw_bend_scan(assoc, req, sr,
-                          res->u.scan_response, &http_code);
+            srw_bend_scan(assoc, sr, res->u.scan_response, &http_code);
             if (http_code == 200)
                 soap_package->u.generic->p = res;
         }
@@ -1835,8 +1834,7 @@ static void process_http_request(association *assoc, request *req)
                 res->u.update_response->num_diagnostics = num_diagnostic;
             }
             yaz_log(YLOG_DEBUG, "num_diag = %d", res->u.update_response->num_diagnostics );
-            srw_bend_update(assoc, req, sr,
-                            res->u.update_response, &http_code);
+            srw_bend_update(assoc, sr, res->u.update_response, &http_code);
             if (http_code == 200)
                 soap_package->u.generic->p = res;
         }
@@ -2090,7 +2088,7 @@ static int process_gdu_response(association *assoc, request *req, Z_GDU *res)
  */
 static int process_z_response(association *assoc, request *req, Z_APDU *res)
 {
-    Z_GDU *gres = (Z_GDU *) odr_malloc(assoc->encode, sizeof(*res));
+    Z_GDU *gres = (Z_GDU *) odr_malloc(assoc->encode, sizeof(*gres));
     gres->which = Z_GDU_Z3950;
     gres->u.z3950 = res;
 
@@ -2290,10 +2288,10 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb)
     yaz_log(log_requestdetail, "Negotiated to v%d: %s", assoc->version, options);
 
     if (*req->maximumRecordSize < assoc->maximumRecordSize)
-        assoc->maximumRecordSize = *req->maximumRecordSize;
+        assoc->maximumRecordSize = odr_int_to_int(*req->maximumRecordSize);
 
     if (*req->preferredMessageSize < assoc->preferredMessageSize)
-        assoc->preferredMessageSize = *req->preferredMessageSize;
+        assoc->preferredMessageSize = odr_int_to_int(*req->preferredMessageSize);
 
     resp->preferredMessageSize =
         odr_intdup(assoc->encode, assoc->preferredMessageSize);
@@ -2425,13 +2423,19 @@ static Z_Records *pack_records(association *a, char *setname, Odr_int start,
         (Z_Records *) odr_malloc(a->encode, sizeof(*records));
     Z_NamePlusRecordList *reclist =
         (Z_NamePlusRecordList *) odr_malloc(a->encode, sizeof(*reclist));
-    Z_NamePlusRecord **list =
-        (Z_NamePlusRecord **) odr_malloc(a->encode, sizeof(*list) * toget);
 
     records->which = Z_Records_DBOSD;
     records->u.databaseOrSurDiagnostics = reclist;
     reclist->num_records = 0;
-    reclist->records = list;
+
+    if (toget < 0)
+        return diagrec(a, YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE, 0);
+    else if (toget == 0)
+        reclist->records = odr_nullval();
+    else
+        reclist->records = (Z_NamePlusRecord **)
+            odr_malloc(a->encode, sizeof(*reclist->records) * toget);
+
     *pres = Z_PresentStatus_success;
     *num = 0;
     *next = 0;