From dc28179889eaf302a471e6c57b2a3ee08a8916be Mon Sep 17 00:00:00 2001 From: David Linko Date: Wed, 7 Feb 2024 16:19:41 -0500 Subject: [PATCH] 11 ion nm fails to handle hex string with blank space (#69) * added new patch for nm rest * updated python39 to 3, RHEL8 to RHEL9 * updated ci to use var for know hosts file * fixing loading modules * updating ci for RHEL9 * updating anms-init to rhel9 * installing node rpm directly * added patch from dtnma-tools --------- Co-authored-by: d-linko Co-authored-by: Brian Sipos --- ion/Dockerfile | 1 + ion/dtnma-tools-nm_rest.patch | 152 ++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 ion/dtnma-tools-nm_rest.patch diff --git a/ion/Dockerfile b/ion/Dockerfile index 2adac6f..940f888 100644 --- a/ion/Dockerfile +++ b/ion/Dockerfile @@ -36,6 +36,7 @@ RUN cd /usr/src/ion-ios && \ patch -p1 request_method, "POST")) { + char buffer[AMP_MAX_EID_LEN+1]; +- int dlen = mg_read(conn, buffer, sizeof(buffer)); ++ int dlen = mg_read(conn, buffer, sizeof(buffer) - 1); + if ( dlen < 1 ) { + mg_send_http_error(conn, 400, "Invalid request body data (expect EID name) %d", dlen); + return 400; + } else { ++ buffer[dlen] = '\0'; + return agentsCreateHandler(conn, buffer); + } + } else { +@@ -300,34 +301,64 @@ static int agentSendRaw(struct mg_connection *conn, time_t ts, agent_t *agent, c + msg_ctrl_t *msg = NULL; + int success; + +- blob_t *data = utils_string_to_hex(hex); +- if (data == NULL) { ++ if((msg = msg_ctrl_create()) == NULL) ++ { + mg_send_http_error(conn, + 500, +- "Error creating blob from input"); ++ "Error creating message"); + return 500; + } +- id = ari_deserialize_raw(data, &success); +- blob_release(data, 1); +- if (id == NULL) { ++ if((msg->ac = ac_create()) == NULL) ++ { ++ msg_ctrl_release(msg, 1); + mg_send_http_error(conn, + 500, +- "Error creating blob from input"); ++ "Error creating AC"); + return 500; + } + +- +- ui_postprocess_ctrl(id); ++ msg->start = ts; + +- if((msg = msg_ctrl_create_ari(id)) == NULL) +- { +- ari_release(id, 1); +- mg_send_http_error(conn, +- 500, +- "Error creating ARI from input"); +- return HTTP_INTERNAL_ERROR; ++ char *part = NULL; ++ const char *ctrlsep = " \f\n\r\t\v"; // Identical to isspace() ++ char *saveptr = NULL; ++ part = strtok_r(hex, ctrlsep, &saveptr); ++ while(part != NULL) { ++ fprintf(stderr, "Handling message part %s\n", part); ++ ++ blob_t *data = utils_string_to_hex(part); ++ if (data == NULL) { ++ mg_send_http_error(conn, ++ HTTP_INTERNAL_ERROR, ++ "Error creating blob from input"); ++ msg_ctrl_release(msg, 1); ++ return HTTP_INTERNAL_ERROR; ++ } ++ id = ari_deserialize_raw(data, &success); ++ blob_release(data, 1); ++ if (id == NULL) { ++ mg_send_http_error(conn, ++ HTTP_INTERNAL_ERROR, ++ "Error decoding CTRL"); ++ msg_ctrl_release(msg, 1); ++ return HTTP_INTERNAL_ERROR; ++ } ++ ++ ui_postprocess_ctrl(id); ++ if(vec_push(&(msg->ac->values), id) != VEC_OK) { ++ mg_send_http_error(conn, ++ HTTP_INTERNAL_ERROR, ++ "Error adding CTRL to message"); ++ ari_release(id, 1); ++ msg_ctrl_release(msg, 1); ++ return HTTP_INTERNAL_ERROR; ++ } ++ ++ part = strtok_r(NULL, ctrlsep, &saveptr); + } +- msg->start = ts; ++ ++ fprintf(stderr, "Sending message with %d controls\n", ac_get_count(msg->ac)); ++ + iif_send_msg(&ion_ptr, MSG_TYPE_PERF_CTRL, msg, agent->eid.name); + ui_log_transmit_msg(agent, msg); + msg_ctrl_release(msg, 1); +@@ -460,21 +491,23 @@ static int agentEidHandler(struct mg_connection *conn, void *cbdata) + } + else if (0 == strcmp(cmd, "hex")) + { +- // URL idx field translates to agent name +- // Optional query parameter "ts" will translate to timestamp (TODO: Always 0 for initial cut) +- // Request body contains CBOR-encoded HEX string +- char buffer[MAX_INPUT_BYTES]; +- int dlen = mg_read(conn, buffer, sizeof(buffer)); +- if (dlen <= 0) { +- return HTTP_BAD_REQUEST; +- } +- buffer[dlen] = 0; // Ensure string is NULL-terminated +- int ts = 0; +- if (cnt == 3) { +- // Optional Timestamp as last element of URL path +- ts = atoi(cmd2); +- } +- return agentSendRaw(conn, ++ // URL idx field translates to agent name ++ // Optional query parameter "ts" will translate to timestamp (TODO: Always 0 for initial cut) ++ // Request body contains CBOR-encoded HEX string ++ char buffer[MAX_INPUT_BYTES]; ++ int dlen = mg_read(conn, buffer, sizeof(buffer) - 1); ++ if (dlen <= 0) { ++ return HTTP_BAD_REQUEST; ++ } ++ buffer[dlen] = '\0'; ++ ++ int ts = 0; ++ if (cnt == 3) { ++ // Optional Timestamp as last element of URL path ++ ts = atoi(cmd2); ++ } ++ ++ return agentSendRaw(conn, + ts, + agent, + buffer +@@ -557,7 +590,11 @@ static int agentIdxHandler(struct mg_connection *conn, void *cbdata) + // Optional query parameter "ts" will translate to timestamp (TODO: Always 0 for initial cut) + // Request body contains CBOR-encoded HEX string + char buffer[MAX_INPUT_BYTES]; +- int dlen = mg_read(conn, buffer, sizeof(buffer)); ++ int dlen = mg_read(conn, buffer, sizeof(buffer) - 1); ++ if (dlen <= 0) { ++ return HTTP_BAD_REQUEST; ++ } ++ buffer[dlen] = '\0'; + return agentSendRaw(conn, + 0, // Timestamp TODO. This will be an optional query param + agent,