OSSP CVS Repository

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

Check-in Number: 1421
Date: 2001-Dec-12 18:18:55 (local)
2001-Dec-12 17:18:55 (UTC)
User:simons
Branch:
Comment: Guarantee that the buffer returned by var_expand() is terminated with a null byte.
Tickets:
Inspections:
Files:
ossp-pkg/var/var.c      1.44 -> 1.45     14 inserted, 1 deleted
ossp-pkg/var/var.pod      1.13 -> 1.14     8 inserted, 6 deleted
ossp-pkg/var/var_test.c      1.23 -> 1.24     1 inserted, 1 deleted

ossp-pkg/var/var.c 1.44 -> 1.45

--- var.c        2001/12/12 16:52:56     1.44
+++ var.c        2001/12/12 17:18:55     1.45
@@ -1965,5 +1965,18 @@
                lookup, lookup_context, force_expand, &output, 0, 0);
     *result = (char *)output.begin;
     *result_len = output.end - output.begin;
-    return (rc >= 0) ? VAR_OK : rc;
+    if (rc >= 0)
+        {
+        if (!tokenbuf_append(&output, "\0", 1))
+            {
+            tokenbuf_free(&output);
+            return VAR_ERR_OUT_OF_MEMORY;
+            }
+        --output.end;
+        rc = VAR_OK;
+        }
+
+    *result = (char *)output.begin;
+    *result_len = output.end - output.begin;
+    return rc;
 }


ossp-pkg/var/var.pod 1.13 -> 1.14

--- var.pod      2001/12/12 16:51:20     1.13
+++ var.pod      2001/12/12 17:18:55     1.14
@@ -166,19 +166,21 @@
 A pointer to a character pointer in which the location of the expanded
 text buffer will be stored. The result buffer will be allocated by
 var_expand() using the system call malloc(3), thus it is the caller's
-responsibility to free(3) that buffer once it is not used anymore.
+responsibility to free(3) that buffer once it is not used anymore. The
+result buffer will be terminated by null byte, which is not included
+in the "result_len" counter.
 
 If var_expand() fails with an error, "result" will point to "input".
-The only exception is the VAR_ERR_INVALID_ARGUMENT error, in which
-case "result" is not modified.
+The only exceptions are the VAR_ERR_INVALID_ARGUMENT
+VAR_ERR_OUT_OF_MEMORY errors, in which case "result" is undefined.
 
 =item size_t *result_len
 
 A pointer to the location in which the length of the expanded text
 buffer will be stored. If var_expand() fails with an error -- with the
-exception of VAR_ERR_INVALID_ARGUMENT --, "result_len" will contain
-the number of characters that have been consumed from "input" before
-the error occured.
+exception of VAR_ERR_INVALID_ARGUMENT and VAR_ERR_OUT_OF_MEMORY --,
+"result_len" will contain the number of characters that have been
+consumed from "input" before the error occured.
 
 =item var_cb_t lookup
 


ossp-pkg/var/var_test.c 1.23 -> 1.24

--- var_test.c   2001/12/12 16:51:20     1.23
+++ var_test.c   2001/12/12 17:18:55     1.24
@@ -143,7 +143,7 @@
         { "${ARRAY[$NUMEXP-1]}",          "entry0"                                         },
         { "${ARRAY[${UNDEFINED}-1]}",     "${ARRAY[${UNDEFINED}-1]}"                       },
         { "${ARRAY[5/(${UNDEFINED})]}",   "${ARRAY[5/(${UNDEFINED})]}"                     },
-        { ":[${ARRAY}-]:",                ":entry0-entry1-entry2-entry3-:"                 }
+        { "[${ARRAY}-]",                  "entry0-entry1-entry2-entry3-"                   }
     };
     char *tmp;
     size_t tmp_len;

CVSTrac 2.0.1