Skip to content

Commit

Permalink
[CLIENT-3254] Fix client.truncate() seg faulting if there is no conne…
Browse files Browse the repository at this point in the history
…ction (#709)
  • Loading branch information
juliannguyen4 authored Jan 9, 2025
1 parent 6c5b275 commit f5805b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/client/truncate.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ PyObject *AerospikeClient_Truncate(AerospikeClient *self, PyObject *args,
return NULL;
}

if (!self || !self->as) {
as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
goto CLEANUP;
}
if (!self->is_conn_16) {
as_error_update(&err, AEROSPIKE_ERR_CLUSTER,
"No connection to aerospike cluster");
goto CLEANUP;
}

// Start conversion of the namespace parameter
if (PyUnicode_Check(py_ns)) {
namespace = strdup((char *)PyUnicode_AsUTF8(py_ns));
Expand Down
5 changes: 5 additions & 0 deletions test/new_tests/test_truncate.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,8 @@ def test_whole_set_truncation_with_invalid_policy(self):
def test_whole_set_truncation_with_invalid_policy_type(self, policy):
with pytest.raises(e.ClientError):
self.as_connection.truncate("test", "truncate", 0, policy)

def test_truncate_after_close(self):
self.as_connection.close()
with pytest.raises(e.ClusterError):
self.as_connection.truncate("test", None, 0)

0 comments on commit f5805b9

Please sign in to comment.