OSSP CVS Repository

ossp - Difference in ossp-pkg/l2/l2_ut_fmtcb.c versions 1.1 and 1.2
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/l2/l2_ut_fmtcb.c 1.1 -> 1.2

--- l2_ut_fmtcb.c        2001/09/06 11:56:15     1.1
+++ l2_ut_fmtcb.c        2001/09/06 14:37:53     1.2
@@ -41,8 +41,10 @@
 
     cpStr = va_arg(*ap, char *);
     nStr  = (size_t)va_arg(*ap, int);
+    if (cpStr == NULL)
+        return L2_ERR_ARG;
     if (nStr > bufsize)
-        return L2_ERROR;
+        return L2_ERR_MEM;
     memcpy(bufptr, cpStr, nStr);
     *buflen = nStr;
     return L2_OK;
@@ -71,6 +73,10 @@
     ucpData = va_arg(*ap, unsigned char *);
     nData   = (size_t)va_arg(*ap, int);
 
+    /* argument sanity check */
+    if (ucpData == NULL)
+        return L2_ERR_ARG;
+
     /* 
      * textual dumping: "foo\1bar" -> "foo\x01bar"
      */
@@ -81,18 +87,18 @@
             uc = *cpI++;
             if (isprint((int)uc)) {
                 if ((char *)cpO >= (bufptr+bufsize))
-                    return L2_ERROR;
+                    return L2_ERR_MEM;
                 *cpO++ = uc;
             }
             else if (uc == '\\') {
                 if ((char *)(cpO+1) >= (bufptr+bufsize))
-                    return L2_ERROR;
+                    return L2_ERR_MEM;
                 *cpO++ = '\\';
                 *cpO++ = '\\';
             }
             else {
                 if ((char *)(cpO+3) >= (bufptr+bufsize))
-                    return L2_ERROR;
+                    return L2_ERR_MEM;
                 *cpO++ = '\\';
                 *cpO++ = 'x';
                 *cpO++ = hex_table[(uc >> 4) & 0xf];
@@ -107,7 +113,7 @@
      */
     else if (strcmp(param, "hex") == 0) {
         if (((nData * 3) - 1) > bufsize)
-            return L2_ERROR;
+            return L2_ERR_MEM;
         cpO = (unsigned char *)bufptr;
         for (i = 0; i < nData; i++) {
             uc = *ucpData++;
@@ -135,7 +141,7 @@
             base64_out[2] = ((base64_in[1] & 0x0f) << 2) + (base64_in[2] >> 6);
             base64_out[3] = ( base64_in[2] & 0x3f);
             if (n + 4 > bufsize)
-                return L2_ERROR;
+                return L2_ERR_MEM;
             bufptr[n++] = base64_table[base64_out[0]];
             bufptr[n++] = base64_table[base64_out[1]];
             bufptr[n++] = base64_table[base64_out[2]];
@@ -150,7 +156,7 @@
             base64_out[1] = ((base64_in[0] & 0x03) << 4) + (base64_in[1] >> 4);
             base64_out[2] = ((base64_in[1] & 0x0f) << 2) + (base64_in[2] >> 6);
             if (n + 4 > bufsize)
-                return L2_ERROR;
+                return L2_ERR_MEM;
             bufptr[n++] = base64_table[base64_out[0]];
             bufptr[n++] = base64_table[base64_out[1]];
             if (nData == 1)
@@ -160,13 +166,13 @@
             bufptr[n++] = '=';
         }
         if (n >= bufsize)
-            return L2_ERROR;
+            return L2_ERR_MEM;
         *buflen = n;
     }
 
     /* anything else is an unknown dumping method... */
     else
-        return L2_ERROR;
+        return L2_ERR_ARG;
 
     return L2_OK;
 }

CVSTrac 2.0.1