Skip to content
Snippets Groups Projects
Commit e1959c6d authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Remove "same thread" checks, and ensure state is always checked

parent fa28e4e5
No related branches found
No related tags found
No related merge requests found
Pipeline #5162 passed
...@@ -100,7 +100,6 @@ typedef struct sftp_client_state { ...@@ -100,7 +100,6 @@ typedef struct sftp_client_state {
void *cb_data; void *cb_data;
sftp_str_t err_msg; sftp_str_t err_msg;
sftp_str_t err_lang; sftp_str_t err_lang;
pthread_t thread;
uint32_t id; uint32_t id;
uint32_t err_id; uint32_t err_id;
uint32_t err_code; uint32_t err_code;
......
...@@ -69,7 +69,6 @@ sftpc_finish(sftpc_state_t state) ...@@ -69,7 +69,6 @@ sftpc_finish(sftpc_state_t state)
assert(state); assert(state);
if (state == NULL) if (state == NULL)
return; return;
assert(state->thread == pthread_self());
// TODO: Close all open handles // TODO: Close all open handles
while (!CloseEvent(state->recv_event)) { while (!CloseEvent(state->recv_event)) {
assert(errno == EBUSY); assert(errno == EBUSY);
...@@ -98,7 +97,6 @@ sftpc_begin(bool (*send_cb)(uint8_t *buf, size_t len, void *cb_data), void *cb_d ...@@ -98,7 +97,6 @@ sftpc_begin(bool (*send_cb)(uint8_t *buf, size_t len, void *cb_data), void *cb_d
ret->txp = NULL; ret->txp = NULL;
ret->send_cb = send_cb; ret->send_cb = send_cb;
ret->cb_data = cb_data; ret->cb_data = cb_data;
ret->thread = pthread_self();
ret->id = 0; ret->id = 0;
ret->err_lang = NULL; ret->err_lang = NULL;
ret->err_msg = NULL; ret->err_msg = NULL;
...@@ -119,17 +117,12 @@ check_state(sftpc_state_t state) ...@@ -119,17 +117,12 @@ check_state(sftpc_state_t state)
assert(state); assert(state);
if (!state) if (!state)
return false; return false;
assert(state->thread == pthread_self());
if (state->thread != pthread_self())
return false;
return true; return true;
} }
static bool static bool
appendheader(sftpc_state_t state, uint8_t type) appendheader(sftpc_state_t state, uint8_t type)
{ {
if (!check_state(state))
return false;
state->err_code = 0; state->err_code = 0;
state->err_id = 0; state->err_id = 0;
free_sftp_str(state->err_lang); free_sftp_str(state->err_lang);
...@@ -165,9 +158,6 @@ get_result(sftpc_state_t state) ...@@ -165,9 +158,6 @@ get_result(sftpc_state_t state)
uint8_t *txbuf; uint8_t *txbuf;
size_t txsz; size_t txsz;
assert(state->thread == pthread_self());
if (state->thread != pthread_self())
return false;
if (!sftp_prep_tx_packet(state->txp, &txbuf, &txsz)) if (!sftp_prep_tx_packet(state->txp, &txbuf, &txsz))
return false; return false;
if (!state->send_cb(txbuf, txsz, state->cb_data)) if (!state->send_cb(txbuf, txsz, state->cb_data))
...@@ -177,7 +167,8 @@ get_result(sftpc_state_t state) ...@@ -177,7 +167,8 @@ get_result(sftpc_state_t state)
if (state->rxp->type != SSH_FXP_VERSION) { if (state->rxp->type != SSH_FXP_VERSION) {
uint32_t id = sftp_get32(state->rxp); uint32_t id = sftp_get32(state->rxp);
if (id != state->id) { if (id != state->id) {
response_handled(state); free(state->rxp);
state->rxp = NULL;
return false; return false;
} }
} }
...@@ -202,6 +193,8 @@ handle_error(sftpc_state_t state) ...@@ -202,6 +193,8 @@ handle_error(sftpc_state_t state)
bool bool
sftpc_init(sftpc_state_t state) sftpc_init(sftpc_state_t state)
{ {
if (!check_state(state))
return false;
if (!appendheader(state, SSH_FXP_INIT)) if (!appendheader(state, SSH_FXP_INIT))
return false; return false;
if (!append32(state, SFTP_VERSION)) if (!append32(state, SFTP_VERSION))
...@@ -222,6 +215,8 @@ sftpc_init(sftpc_state_t state) ...@@ -222,6 +215,8 @@ sftpc_init(sftpc_state_t state)
bool bool
sftpc_recv(sftpc_state_t state, uint8_t *buf, uint32_t sz) sftpc_recv(sftpc_state_t state, uint8_t *buf, uint32_t sz)
{ {
if (!check_state(state))
return false;
if (!sftp_rx_pkt_append(&state->rxp, buf, sz)) if (!sftp_rx_pkt_append(&state->rxp, buf, sz))
return false; return false;
if (sftp_have_full_pkt(state->rxp)) if (sftp_have_full_pkt(state->rxp))
...@@ -232,6 +227,8 @@ sftpc_recv(sftpc_state_t state, uint8_t *buf, uint32_t sz) ...@@ -232,6 +227,8 @@ sftpc_recv(sftpc_state_t state, uint8_t *buf, uint32_t sz)
bool bool
sftpc_realpath(sftpc_state_t state, char *path, sftp_str_t *ret) sftpc_realpath(sftpc_state_t state, char *path, sftp_str_t *ret)
{ {
if (!check_state(state))
return false;
assert(ret); assert(ret);
if (ret == NULL) if (ret == NULL)
return false; return false;
...@@ -260,9 +257,6 @@ sftpc_realpath(sftpc_state_t state, char *path, sftp_str_t *ret) ...@@ -260,9 +257,6 @@ sftpc_realpath(sftpc_state_t state, char *path, sftp_str_t *ret)
static bool static bool
parse_handle(sftpc_state_t state, sftp_str_t *handle) parse_handle(sftpc_state_t state, sftp_str_t *handle)
{ {
assert(state);
if (state == NULL)
return false;
assert(state->rxp); assert(state->rxp);
if (state->rxp == NULL) if (state->rxp == NULL)
return false; return false;
...@@ -281,6 +275,11 @@ parse_handle(sftpc_state_t state, sftp_str_t *handle) ...@@ -281,6 +275,11 @@ parse_handle(sftpc_state_t state, sftp_str_t *handle)
bool bool
sftpc_open(sftpc_state_t state, char *path, uint32_t flags, sftp_file_attr_t attr, sftp_dirhandle_t *handle) sftpc_open(sftpc_state_t state, char *path, uint32_t flags, sftp_file_attr_t attr, sftp_dirhandle_t *handle)
{ {
if (!check_state(state))
return false;
assert(path);
if (path == NULL)
return false;
assert(handle); assert(handle);
if (handle == NULL) if (handle == NULL)
return false; return false;
...@@ -324,6 +323,8 @@ sftpc_open(sftpc_state_t state, char *path, uint32_t flags, sftp_file_attr_t att ...@@ -324,6 +323,8 @@ sftpc_open(sftpc_state_t state, char *path, uint32_t flags, sftp_file_attr_t att
bool bool
sftpc_close(sftpc_state_t state, sftp_filehandle_t *handle) sftpc_close(sftpc_state_t state, sftp_filehandle_t *handle)
{ {
if (!check_state(state))
return false;
if (!appendheader(state, SSH_FXP_CLOSE)) if (!appendheader(state, SSH_FXP_CLOSE))
return false; return false;
if (!appendfhandle(state, *handle)) if (!appendfhandle(state, *handle))
...@@ -339,6 +340,8 @@ sftpc_close(sftpc_state_t state, sftp_filehandle_t *handle) ...@@ -339,6 +340,8 @@ sftpc_close(sftpc_state_t state, sftp_filehandle_t *handle)
bool bool
sftpc_read(sftpc_state_t state, sftp_filehandle_t handle, uint64_t offset, uint32_t len, sftp_str_t *ret) sftpc_read(sftpc_state_t state, sftp_filehandle_t handle, uint64_t offset, uint32_t len, sftp_str_t *ret)
{ {
if (!check_state(state))
return false;
assert(ret); assert(ret);
if (ret == NULL) if (ret == NULL)
return false; return false;
...@@ -367,6 +370,8 @@ sftpc_read(sftpc_state_t state, sftp_filehandle_t handle, uint64_t offset, uint3 ...@@ -367,6 +370,8 @@ sftpc_read(sftpc_state_t state, sftp_filehandle_t handle, uint64_t offset, uint3
bool bool
sftpc_write(sftpc_state_t state, sftp_filehandle_t handle, uint64_t offset, sftp_str_t data) sftpc_write(sftpc_state_t state, sftp_filehandle_t handle, uint64_t offset, sftp_str_t data)
{ {
if (!check_state(state))
return false;
assert(data); assert(data);
if (data == NULL) if (data == NULL)
return false; return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment