OSSP CVS Repository

ossp - Check-in [4245]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 4245
Date: 2001-Jul-24 17:46:18 (local)
2001-Jul-24 15:46:18 (UTC)
User:simons
Branch:
Comment: xds_encode() and xds_decode() had two problems:

- In case any of the callbacks returns with an error, the original xds->buffer_len value must be restored or the buffer is messed up with values from successful callback executions. The routines wouldn't be atomic in that case.

- If an encoding callback uses up all buffer space but formatted the value successfully nonetheless, the xds->buffer_len wasn't incremented.

Both problems have been fixed.

Tickets:
Inspections:
Files:
ossp-pkg/xds/vdecode.c      1.3 -> 1.4     4 inserted, 0 deleted
ossp-pkg/xds/vencode.c      1.10 -> 1.11     7 inserted, 0 deleted

ossp-pkg/xds/vdecode.c 1.3 -> 1.4

--- vdecode.c    2001/07/16 17:50:07     1.3
+++ vdecode.c    2001/07/24 15:46:18     1.4
@@ -32,6 +32,7 @@
 
 int xds_vdecode(xds_t* xds, const char* fmt_arg, va_list args)
     {
+    size_t buffer_len_backup;
     char* name;
     char* p;
     char* fmt;
@@ -58,6 +59,7 @@
     fmt = p = strdup(fmt_arg);
     if (fmt == NULL)
         return XDS_ERR_NO_MEM;
+    buffer_len_backup = xds->buffer_len;
     for(name = p; *p != '\0'; name = p)
         {
         while(isalnum(*p) || *p == '-' || *p == '_')
@@ -94,5 +96,7 @@
     /* Clean up and leave. */
   leave:
     free(fmt);
+    if (rc != XDS_OK)
+        xds->buffer_len = buffer_len_backup;
     return rc;
     }


ossp-pkg/xds/vencode.c 1.10 -> 1.11

--- vencode.c    2001/07/19 15:21:35     1.10
+++ vencode.c    2001/07/24 15:46:18     1.11
@@ -33,6 +33,7 @@
 int xds_vencode(xds_t* xds, const char* fmt_arg, va_list args)
     {
     va_list args_backup;
+    size_t buffer_len_backup;
     char* name;
     char* p;
     char* fmt;
@@ -90,6 +91,7 @@
     fmt = p = strdup(fmt_arg);
     if (fmt == NULL)
         return XDS_ERR_NO_MEM;
+    buffer_len_backup = xds->buffer_len;
     for(name = p; *p != '\0'; name = p)
         {
         while(isalnum(*p) || *p == '-' || *p == '_')
@@ -125,7 +127,10 @@
                             args = args_backup;
                             }
                         else
+                            {
                             restart_engine = XDS_FALSE;
+                            xds->buffer_len += rc;
+                            }
 
                         if (!xds->we_own_buffer)
                             {
@@ -165,5 +170,7 @@
     /* Clean up and leave. */
   leave:
     free(fmt);
+    if (rc != XDS_OK)
+        xds->buffer_len = buffer_len_backup;
     return rc;
     }

CVSTrac 2.0.1