mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-05-31 09:50:05 +02:00
grel: Validate field index input to public functions
Previously this was passed straight into an array dereference, so could easily have under- or over-flowed the array. Add a precondition check to it. This doesn’t change the API contract, because the code already emitted a critical warning if the index didn’t find a table: ``` g_return_val_if_fail (table != NULL, NULL) ``` This fixes a load of `-Wsign-conversion` warnings and makes these functions safer. Signed-off-by: Philip Withnall <pwithnall@gnome.org> Helps: #3405
This commit is contained in:
parent
29068a5a37
commit
ef065dd195
@ -391,10 +391,13 @@ g_relation_delete (GRelation *relation,
|
||||
GHashTable *table;
|
||||
GHashTable *key_table;
|
||||
size_t count;
|
||||
size_t unsigned_field;
|
||||
|
||||
g_return_val_if_fail (relation != NULL, 0);
|
||||
g_return_val_if_fail (field >= 0 && (size_t) field < relation->fields, 0);
|
||||
|
||||
table = relation->hashed_tuple_tables[field];
|
||||
unsigned_field = (size_t) field;
|
||||
table = relation->hashed_tuple_tables[unsigned_field];
|
||||
count = relation->count;
|
||||
|
||||
g_return_val_if_fail (table != NULL, 0);
|
||||
@ -404,7 +407,7 @@ g_relation_delete (GRelation *relation,
|
||||
if (!key_table)
|
||||
return 0;
|
||||
|
||||
relation->current_field = field;
|
||||
relation->current_field = unsigned_field;
|
||||
|
||||
g_hash_table_foreach (key_table, g_relation_delete_tuple, relation);
|
||||
|
||||
@ -458,10 +461,13 @@ g_relation_select (GRelation *relation,
|
||||
GHashTable *key_table;
|
||||
GRealTuples *tuples;
|
||||
size_t count;
|
||||
size_t unsigned_field;
|
||||
|
||||
g_return_val_if_fail (relation != NULL, NULL);
|
||||
g_return_val_if_fail (field >= 0 && (size_t) field < relation->fields, NULL);
|
||||
|
||||
table = relation->hashed_tuple_tables[field];
|
||||
unsigned_field = (size_t) field;
|
||||
table = relation->hashed_tuple_tables[unsigned_field];
|
||||
|
||||
g_return_val_if_fail (table != NULL, NULL);
|
||||
|
||||
@ -503,10 +509,13 @@ g_relation_count (GRelation *relation,
|
||||
{
|
||||
GHashTable *table;
|
||||
GHashTable *key_table;
|
||||
size_t unsigned_field;
|
||||
|
||||
g_return_val_if_fail (relation != NULL, 0);
|
||||
g_return_val_if_fail (field >= 0 && (size_t) field < relation->fields, 0);
|
||||
|
||||
table = relation->hashed_tuple_tables[field];
|
||||
unsigned_field = (size_t) field;
|
||||
table = relation->hashed_tuple_tables[unsigned_field];
|
||||
|
||||
g_return_val_if_fail (table != NULL, 0);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user