Skip to content

The gmtlib_validate_id function stepped on another object's family #5100

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

Merged
merged 2 commits into from
Apr 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/gmt_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -7688,8 +7688,8 @@ int gmtlib_validate_id (struct GMTAPI_CTRL *API, int family, int object_ID, int
* module_input = GMT_NOTSET [-1]: Do not use the resource's module_input status in determining the next ID.
* module_input = GMTAPI_OPTION_INPUT [0]: Only validate resources with module_input = false.
* module_input = GMTAPI_MODULE_INPUT [1]: Only validate resources with module_input = true.
* Finally, since we allow vectors and matrices to masqerade as DATASETs we check for this and
* rebaptize such objects to become GMT_IS_DATASETs. */
* Finally, since we allow vectors and matrices to masquerade as DATASETs we check for this and
* re-baptize such objects to become GMT_IS_DATASETs. */
unsigned int i;
int item;
struct GMTAPI_DATA_OBJECT *S_obj = NULL;
Expand All @@ -7700,15 +7700,16 @@ int gmtlib_validate_id (struct GMTAPI_CTRL *API, int family, int object_ID, int

for (i = 0, item = GMT_NOTSET; item == GMT_NOTSET && i < API->n_objects; i++) {
S_obj = API->object[i]; /* Shorthand only */
if (!S_obj) continue; /* Empty object */
if (direction != GMT_NOTSET && (int)S_obj->direction != direction) continue; /* Not the same direction */
if (direction == GMT_IN && S_obj->status != GMT_IS_UNUSED && object_ID == GMT_NOTSET) continue; /* Already used this input object once */
if (!S_obj) continue; /* Empty object, skip */
if (direction != GMT_NOTSET && (int)S_obj->direction != direction) continue; /* Not the requested direction */
if (direction == GMT_IN && S_obj->status != GMT_IS_UNUSED && object_ID == GMT_NOTSET) continue; /* Already used this input object once */
/* Preliminary checks passed, no look at family */
if (!(family == GMT_NOTSET || (int)S_obj->family == family)) { /* Not the required data type; check for exceptions... */
if (family == GMT_IS_DATASET && (S_obj->actual_family == GMT_IS_VECTOR || S_obj->actual_family == GMT_IS_MATRIX))
S_obj->family = GMT_IS_DATASET; /* Vectors or Matrix masquerading as dataset are valid. Change their family here. */
else if (family == GMT_IS_GRID && S_obj->actual_family == GMT_IS_MATRIX)
if (family == GMT_IS_GRID && S_obj->actual_family == GMT_IS_MATRIX)
S_obj->family = GMT_IS_GRID; /* Matrix masquerading as grids is valid. Change the family here. */
else /* We don't like your kind */
else if (family == GMT_IS_DATASET && (S_obj->actual_family == GMT_IS_VECTOR || S_obj->actual_family == GMT_IS_MATRIX) && !(S_obj->family == GMT_IS_GRID || S_obj->family == GMT_IS_IMAGE))
S_obj->family = GMT_IS_DATASET; /* Vectors or Matrix masquerading as dataset are valid. Change their family here. */
else if (family != GMT_NOTSET && family != S_obj->family) /* We don't like your kind */
continue;
}
if (object_ID == GMT_NOTSET && (int)S_obj->direction == direction) item = i; /* Pick the first object with the specified direction */
Expand Down Expand Up @@ -8260,7 +8261,8 @@ int GMT_Register_IO (void *V_API, unsigned int family, unsigned int method, unsi
gmt_M_memcpy (S_obj->wesn, wesn, 6, double);
S_obj->region = true;
}

else if (family == GMT_IS_DATASET && S_obj->actual_family == GMT_IS_DATASET) /* All datasets are double (this is informational only) */
S_obj->type = GMT_DOUBLE;
S_obj->alloc_level = GMT->hidden.func_level; /* Object was allocated at this module nesting level */
if (module_input) S_obj->module_input = true;

Expand Down Expand Up @@ -9074,7 +9076,7 @@ void * GMT_Read_Data (void *V_API, unsigned int family, unsigned int method, uns
else { /* Not a CPT file but could be remote */
int k_data;
char file[PATH_MAX] = {""};
if (API->remote_info == NULL && !API->GMT->current.io.internet_error && input[0] == '@' || !gmt_M_file_is_memory (input)) {
if (API->remote_info == NULL && !API->GMT->current.io.internet_error && input[0] == '@' && !gmt_M_file_is_memory (input)) {
/* Maybe using the API without a module call first so server has not been refreshed yet */
gmt_refresh_server (API);
}
Expand Down