[gom] gom: Correctly check the length of parameters before saving them



commit 9bd07a37bdd18adcfa284d534553c5d0b5c1247e
Author: Bastien Nocera <hadess hadess net>
Date:   Tue May 6 21:41:59 2014 +0200

    gom: Correctly check the length of parameters before saving them
    
    Check that the primary-key and table names aren't getting clipped before
    we save them, otherwise we'll fail later at run-time.
    
    Previous commit was trying to do that, but ended up ensuring that the
    names were at least as big as the byte array we store them in, rather
    than the (correct) opposite.

 gom/gom-resource.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/gom/gom-resource.c b/gom/gom-resource.c
index 7c7e6c9..5288e1c 100644
--- a/gom/gom-resource.c
+++ b/gom/gom-resource.c
@@ -52,7 +52,7 @@ gom_resource_class_set_primary_key (GomResourceClass *resource_class,
 
    g_return_if_fail(GOM_IS_RESOURCE_CLASS(resource_class));
    g_return_if_fail(primary_key != NULL);
-   g_return_if_fail(strlen(primary_key) >= sizeof(resource_class->primary_key));
+   g_return_if_fail(strlen(primary_key) <= sizeof(resource_class->primary_key));
 
    pspec = g_object_class_find_property(G_OBJECT_CLASS(resource_class), primary_key);
    if (!pspec) {
@@ -202,7 +202,7 @@ gom_resource_class_set_table (GomResourceClass *resource_class,
 {
    g_return_if_fail(GOM_IS_RESOURCE_CLASS(resource_class));
    g_return_if_fail(table != NULL);
-   g_return_if_fail(strlen(table) >= sizeof(resource_class->table));
+   g_return_if_fail(strlen(table) <= sizeof(resource_class->table));
 
    g_snprintf(resource_class->table,
               sizeof(resource_class->table),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]