network plugin: A fix for the buffer problem for version 4.4.
authorFlorian Forster <octo@crystal.wlan.home.verplant.org>
Tue, 30 Dec 2008 16:13:31 +0000 (17:13 +0100)
committerFlorian Forster <octo@crystal.wlan.home.verplant.org>
Tue, 30 Dec 2008 16:13:31 +0000 (17:13 +0100)
This patch fixes the same problem as 6605ff1a, the insufficient copying of
values to the `type' buffer.

Thanks again to Bruno PrĂ©mont for reporting and debugging this :)

Resolves: #37

src/network.c

index 0ea51b3..3a52a43 100644 (file)
@@ -1395,7 +1395,7 @@ static void network_send_buffer (const char *buffer, int buffer_len)
 } /* void network_send_buffer */
 
 static int add_to_buffer (char *buffer, int buffer_size,
-               value_list_t *vl_def, char *type_def,
+               value_list_t *vl_def, char *type_def, size_t type_def_size,
                const data_set_t *ds, const value_list_t *vl)
 {
        char *buffer_orig = buffer;
@@ -1446,7 +1446,7 @@ static int add_to_buffer (char *buffer, int buffer_size,
                if (write_part_string (&buffer, &buffer_size, TYPE_TYPE,
                                        ds->type, strlen (ds->type)) != 0)
                        return (-1);
-               sstrncpy (type_def, ds->type, sizeof (type_def));
+               sstrncpy (type_def, ds->type, type_def_size);
        }
 
        if (strcmp (vl_def->type_instance, vl->type_instance) != 0)
@@ -1492,7 +1492,8 @@ static int network_write (const data_set_t *ds, const value_list_t *vl)
 
        status = add_to_buffer (send_buffer_ptr,
                        sizeof (send_buffer) - send_buffer_fill,
-                       &send_buffer_vl, send_buffer_type,
+                       &send_buffer_vl,
+                       send_buffer_type, sizeof (send_buffer_type),
                        ds, vl);
        if (status >= 0)
        {
@@ -1506,7 +1507,8 @@ static int network_write (const data_set_t *ds, const value_list_t *vl)
 
                status = add_to_buffer (send_buffer_ptr,
                                sizeof (send_buffer) - send_buffer_fill,
-                               &send_buffer_vl, send_buffer_type,
+                               &send_buffer_vl,
+                               send_buffer_type, sizeof (send_buffer_type),
                                ds, vl);
 
                if (status >= 0)