Skip to content

Commit

Permalink
Check class APIs nullability for radareorg#23490
Browse files Browse the repository at this point in the history
  • Loading branch information
astralia committed Nov 7, 2024
1 parent 63ac551 commit 45ae9d1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions libr/anal/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ static bool r_anal_class_exists_raw(RAnal *anal, const char *name) {
}

R_API bool r_anal_class_exists(RAnal *anal, const char *name) {
R_RETURN_VAL_IF_FAIL (anal && name, false);
char *class_name_sanitized = r_str_sanitize_sdb_key (name);
if (!class_name_sanitized) {
return false;
Expand All @@ -128,6 +129,7 @@ R_API bool r_anal_class_exists(RAnal *anal, const char *name) {
}

R_API SdbList *r_anal_class_get_all(RAnal *anal, bool sorted) {
R_RETURN_VAL_IF_FAIL (anal, NULL);
return sdb_foreach_list (anal->sdb_classes, sorted);
}

Expand All @@ -147,6 +149,7 @@ static bool rename_key(Sdb *sdb, const char *key_old, const char *key_new) {
}

R_API RAnalClassErr r_anal_class_rename(RAnal *anal, const char *old_name, const char *new_name) {
R_RETURN_VAL_IF_FAIL (anal && old_name && new_name, R_ANAL_CLASS_ERR_OTHER);
if (r_anal_class_exists (anal, new_name)) {
return R_ANAL_CLASS_ERR_CLASH;
}
Expand Down Expand Up @@ -509,6 +512,7 @@ R_API void r_anal_class_method_fini(RAnalMethod *meth) {
// if the method exists: store it in *meth and return R_ANAL_CLASS_ERR_SUCCESS
// else return the error, contents of *meth are undefined
R_API RAnalClassErr r_anal_class_method_get(RAnal *anal, const char *class_name, const char *meth_name, RAnalMethod *meth) {
R_RETURN_VAL_IF_FAIL (anal && class_name && meth_name && meth, R_ANAL_CLASS_ERR_OTHER);
char *content = r_anal_class_get_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_METHOD, meth_name, false);
if (!content) {
return R_ANAL_CLASS_ERR_NONEXISTENT_ATTR;
Expand Down Expand Up @@ -546,6 +550,7 @@ static void r_anal_class_method_fini_proxy(void *e, void *user) {
}

R_API RVector/*<RAnalMethod>*/ *r_anal_class_method_get_all(RAnal *anal, const char *class_name) {
R_RETURN_VAL_IF_FAIL (anal && class_name, NULL);
RVector *vec = r_vector_new (sizeof (RAnalMethod), r_anal_class_method_fini_proxy, NULL);
if (!vec) {
return NULL;
Expand Down Expand Up @@ -581,6 +586,7 @@ R_API RVector/*<RAnalMethod>*/ *r_anal_class_method_get_all(RAnal *anal, const c
}

R_API RAnalClassErr r_anal_class_method_set(RAnal *anal, const char *class_name, RAnalMethod *meth) {
R_RETURN_VAL_IF_FAIL (anal && class_name && meth, R_ANAL_CLASS_ERR_OTHER);
char *content = r_str_newf ("%"PFMT64u"%c%"PFMT64d, meth->addr, SDB_RS, meth->vtable_offset);
RAnalClassErr err = r_anal_class_set_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_METHOD, meth->name, content);
free (content);
Expand All @@ -594,6 +600,7 @@ R_API RAnalClassErr r_anal_class_method_set(RAnal *anal, const char *class_name,
}

R_API RAnalClassErr r_anal_class_method_rename(RAnal *anal, const char *class_name, const char *old_meth_name, const char *new_meth_name) {
R_RETURN_VAL_IF_FAIL (anal && class_name && old_meth_name && new_meth_name, R_ANAL_CLASS_ERR_OTHER);
RAnalClassErr err = r_anal_class_rename_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_METHOD, old_meth_name, new_meth_name);
if (err != R_ANAL_CLASS_ERR_SUCCESS) {
return err;
Expand Down Expand Up @@ -643,6 +650,7 @@ static void r_anal_class_method_delete_class(RAnal *anal, const char *class_name
}

R_API RAnalClassErr r_anal_class_method_delete(RAnal *anal, const char *class_name, const char *meth_name) {
R_RETURN_VAL_IF_FAIL (anal && class_name && meth_name, R_ANAL_CLASS_ERR_OTHER);
char *class_name_sanitized = r_str_sanitize_sdb_key (class_name);
if (!class_name_sanitized) {
return R_ANAL_CLASS_ERR_OTHER;
Expand Down Expand Up @@ -673,6 +681,7 @@ R_API void r_anal_class_base_fini(RAnalBaseClass *base) {
}

R_API RAnalClassErr r_anal_class_base_get(RAnal *anal, const char *class_name, const char *base_id, RAnalBaseClass *base) {
R_RETURN_VAL_IF_FAIL (anal && class_name && base_id && base, R_ANAL_CLASS_ERR_OTHER);
char *content = r_anal_class_get_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_BASE,
base_id, false);
if (!content) {
Expand Down Expand Up @@ -717,6 +726,7 @@ static void r_anal_class_base_fini_proxy(void *e, void *user) {
}

R_API RVector/*<RAnalBaseClass>*/ *r_anal_class_base_get_all(RAnal *anal, const char *class_name) {
R_RETURN_VAL_IF_FAIL (anal && class_name, NULL);
RVector *vec = r_vector_new (sizeof (RAnalBaseClass), r_anal_class_base_fini_proxy, NULL);
if (!vec) {
return NULL;
Expand Down Expand Up @@ -772,6 +782,7 @@ static RAnalClassErr r_anal_class_base_set_raw(RAnal *anal, const char *class_na
}

R_API RAnalClassErr r_anal_class_base_set(RAnal *anal, const char *class_name, RAnalBaseClass *base) {
R_RETURN_VAL_IF_FAIL (anal && class_name && base, R_ANAL_CLASS_ERR_OTHER);
char *base_class_name_sanitized = r_str_sanitize_sdb_key (base->class_name);
if (!base_class_name_sanitized) {
return R_ANAL_CLASS_ERR_OTHER;
Expand Down Expand Up @@ -799,6 +810,7 @@ R_API RAnalClassErr r_anal_class_base_set(RAnal *anal, const char *class_name, R
}

R_API RAnalClassErr r_anal_class_base_delete(RAnal *anal, const char *class_name, const char *base_id) {
R_RETURN_VAL_IF_FAIL (anal && class_name && base_id, R_ANAL_CLASS_ERR_OTHER);
return r_anal_class_delete_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_BASE, base_id);
}

Expand Down Expand Up @@ -862,6 +874,7 @@ R_API void r_anal_class_vtable_fini(RAnalVTable *vtable) {
}

R_API RAnalClassErr r_anal_class_vtable_get(RAnal *anal, const char *class_name, const char *vtable_id, RAnalVTable *vtable) {
R_RETURN_VAL_IF_FAIL (anal && class_name && vtable_id && vtable, R_ANAL_CLASS_ERR_OTHER);
char *content = r_anal_class_get_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_VTABLE, vtable_id, false);
if (!content) {
return R_ANAL_CLASS_ERR_NONEXISTENT_ATTR;
Expand Down Expand Up @@ -907,6 +920,7 @@ static void r_anal_class_vtable_fini_proxy(void *e, void *user) {
}

R_API RVector/*<RAnalVTable>*/ *r_anal_class_vtable_get_all(RAnal *anal, const char *class_name) {
R_RETURN_VAL_IF_FAIL (anal && class_name, NULL);
RVector *vec = r_vector_new (sizeof (RAnalVTable), r_anal_class_vtable_fini_proxy, NULL);
if (!vec) {
return NULL;
Expand Down Expand Up @@ -957,6 +971,7 @@ static bool vtable_exists_at(RAnal *anal, const char *class_name, ut64 addr) {
}

R_API RAnalClassErr r_anal_class_vtable_set(RAnal *anal, const char *class_name, RAnalVTable *vtable) {
R_RETURN_VAL_IF_FAIL (anal && class_name && vtable, R_ANAL_CLASS_ERR_OTHER);
if (vtable_exists_at (anal, class_name, vtable->addr)) {
return R_ANAL_CLASS_ERR_OTHER;
}
Expand Down Expand Up @@ -1006,6 +1021,7 @@ static void r_anal_class_vtable_rename_class(RAnal *anal, const char *old_class_
}

static void r_anal_class_vtable_delete_class(RAnal *anal, const char *class_name) {
R_RETURN_IF_FAIL (anal && class_name);
char *array_key = key_attr_type_attrs (class_name, attr_type_id (R_ANAL_CLASS_ATTR_TYPE_VTABLE));
char *array = sdb_get (anal->sdb_classes_attrs, array_key, 0);
free (array_key);
Expand Down

0 comments on commit 45ae9d1

Please sign in to comment.