-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CLIENT-2093] Add more input validation in client config and partition filter dictionaries #582
base: dev
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #582 +/- ##
==========================================
+ Coverage 81.35% 81.84% +0.49%
==========================================
Files 100 100
Lines 15356 15512 +156
==========================================
+ Hits 12493 12696 +203
+ Misses 2863 2816 -47 ☔ View full report in Codecov by Sentry. |
35bc608
to
42ea3de
Compare
b7e566b
to
8465fc2
Compare
b696951
to
c012182
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently at line 800 of type.c. I will come back to this, here are comments for now.
snprintf(error_msg, MAX_ERR_MSG_SIZE, "config%s must be a %s", config_keys, | ||
expected_type_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snprintf(error_msg, MAX_ERR_MSG_SIZE, "config%s must be a %s", config_keys, | |
expected_type_name); | |
snprintf(error_msg, MAX_ERR_MSG_SIZE, "config %s must be a %s", config_keys, | |
expected_type_name); |
spacing between "config" and the config name
py_port = PyTuple_GetItem(py_host, 1); | ||
if (PyLong_Check(py_port)) { | ||
if (PyLong_CheckExact(py_port)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the exact check? Would a subclass cause a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because Python booleans are subtypes of Python integers. I found this out when testing my changes
https://docs.python.org/3/c-api/bool.html
Booleans in Python are implemented as a subclass of integers
// ["hosts"][<10 chars max>][0] | ||
// 1234567890123456789012345678 | ||
// 0 10 20 + 1 = 29 | ||
char keys_str[29]; | ||
snprintf(keys_str, 29, "[\"hosts\"][%d][0]", i); | ||
initialize_config_value_type_err( | ||
config_value_type_error_msg, keys_str, "str", | ||
&error_code); | ||
goto CONSTRUCTOR_ERROR; | ||
} | ||
|
||
py_port = PyTuple_GetItem(py_host, 1); | ||
if (PyLong_Check(py_port)) { | ||
if (PyLong_CheckExact(py_port)) { | ||
port = (uint16_t)PyLong_AsLong(py_port); | ||
} | ||
else { | ||
port = 0; | ||
char keys_str[29]; | ||
snprintf(keys_str, 29, "[\"hosts\"][%d][1]", i); | ||
initialize_config_value_type_err( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the "29" should be a constant, you could move the explanation from line 667 to the constant deceleration and give it a little more context.
char keys_str[29]; | ||
snprintf(keys_str, 29, "[\"hosts\"][%d][2]", i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, should be a constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At tls_config.c line 33, will come back to this
@@ -1152,7 +1385,7 @@ static int set_rack_aware_config(as_config *conf, PyObject *config_dict) | |||
|
|||
py_config_value = PyDict_GetItemString(config_dict, "rack_id"); | |||
if (py_config_value) { | |||
if (PyLong_Check(py_config_value)) { | |||
if (PyLong_CheckExact(py_config_value)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the exact check? I'm not sure but I don't think a sub class would cause issues.
@@ -1188,7 +1421,7 @@ static int set_rack_aware_config(as_config *conf, PyObject *config_dict) | |||
} | |||
|
|||
Py_INCREF(rack_id_pyobj); | |||
if (PyLong_Check(rack_id_pyobj) == false) { | |||
if (PyLong_CheckExact(rack_id_pyobj) == false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the exact check? (same as above)
@@ -768,7 +768,7 @@ as_status get_uint32_value(PyObject *py_policy_val, uint32_t *return_uint32) | |||
if (!py_policy_val) { | |||
return AEROSPIKE_ERR_PARAM; | |||
} | |||
if (PyLong_Check(py_policy_val)) { | |||
if (PyLong_CheckExact(py_policy_val)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as others, why exact?
@@ -25,68 +25,59 @@ static char *get_string_from_string_like(PyObject *string_like); | |||
* Param: tls_conf PyDict. | |||
* Fill in the appropriate TLS values of config based on the contents of | |||
* tls_config | |||
Returns NULL if no error occurred, or the config key and expected value type where the error occurred |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should start with "*" like the other lines
Valgrind
This branch: https://github.com/aerospike/aerospike-client-python/actions/runs/8104278566/job/22150570588
Dev: https://github.com/aerospike/aerospike-client-python/actions/runs/8103677912/job/22148781775
Changes
Extra changes:
str
instead of abytearray
for the partition filter's digest atpartition_filter["digest"]["value"]
ParamError
instead of setting it to 0.Notes