Skip to content

Commit

Permalink
Merge branch 'devel' into libnetconf3
Browse files Browse the repository at this point in the history
  • Loading branch information
Roytak authored Oct 26, 2023
2 parents f64926a + 99fd7ad commit 18a5f24
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/session_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ recv_rpc_check_msgid(struct nc_session *session, const struct lyd_node *envp)
/* should be called holding the session RPC lock! IO lock will be acquired as needed
* returns: NC_PSPOLL_ERROR,
* NC_PSPOLL_TIMEOUT,
* NC_PSPOLL_BAD_RPC,
* NC_PSPOLL_BAD_RPC (| NC_PSPOLL_REPLY_ERROR),
* NC_PSPOLL_RPC
*/
static int
Expand All @@ -1381,7 +1381,7 @@ nc_server_recv_rpc_io(struct nc_session *session, int io_timeout, struct nc_serv
struct ly_in *msg;
struct nc_server_reply *reply = NULL;
struct lyd_node *e;
int r, ret;
int r, ret = 0;

NC_CHECK_ARG_RET(session, session, rpc, NC_PSPOLL_ERROR);

Expand All @@ -1396,7 +1396,6 @@ nc_server_recv_rpc_io(struct nc_session *session, int io_timeout, struct nc_serv
r = nc_read_msg_io(session, io_timeout, &msg, 0);
if (r == -2) {
/* malformed message */
ret = NC_PSPOLL_BAD_RPC;
reply = nc_server_reply_err(nc_err(session->ctx, NC_ERR_MALFORMED_MSG));
goto cleanup;
}
Expand All @@ -1417,13 +1416,10 @@ nc_server_recv_rpc_io(struct nc_session *session, int io_timeout, struct nc_serv
ret = NC_PSPOLL_RPC;
} else {
/* no message-id */
ret = NC_PSPOLL_BAD_RPC;
reply = nc_server_reply_err(nc_err(session->ctx, NC_ERR_MISSING_ATTR, NC_ERR_TYPE_RPC, "message-id", "rpc"));
}
} else {
/* bad RPC received */
ret = NC_PSPOLL_BAD_RPC;

if ((*rpc)->envp) {
/* at least the envelopes were parsed */
e = nc_err(session->ctx, NC_ERR_OP_FAILED, NC_ERR_TYPE_APP);
Expand All @@ -1433,6 +1429,9 @@ nc_server_recv_rpc_io(struct nc_session *session, int io_timeout, struct nc_serv
/* completely malformed message, NETCONF version 1.1 defines sending error reply from
* the server (RFC 6241 sec. 3) */
reply = nc_server_reply_err(nc_err(session->ctx, NC_ERR_MALFORMED_MSG));
} else {
/* at least set the return value */
ret = NC_PSPOLL_BAD_RPC;
}
}

Expand All @@ -1448,6 +1447,9 @@ nc_server_recv_rpc_io(struct nc_session *session, int io_timeout, struct nc_serv
session->term_reason = NC_SESSION_TERM_OTHER;
}
}

/* bad RPC and an error reply sent */
ret = NC_PSPOLL_BAD_RPC | NC_PSPOLL_REPLY_ERROR;
}

ly_in_free(msg, 1);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fd_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ test_send_recv_malformed_10(void **state)
nc_ps_add_session(ps, server_session);

ret = nc_ps_poll(ps, 0, NULL);
assert_int_equal(ret, NC_PSPOLL_BAD_RPC);
assert_int_equal(ret, NC_PSPOLL_BAD_RPC | NC_PSPOLL_REPLY_ERROR);

/* server finished */
nc_ps_free(ps);
Expand Down

0 comments on commit 18a5f24

Please sign in to comment.