]> git.sur5r.net Git - openldap/blobdiff - libraries/liblutil/base64.c
In ldap_extended_operation_s, check for NULL retoidp and retdatap
[openldap] / libraries / liblutil / base64.c
index 6f4b88fe8d985c779261c44955c727b690d9c5c7..85eb0c2eabbb02f6eb68f319237178cb5b79cdfc 100644 (file)
@@ -1,3 +1,8 @@
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 /*
  * Modified by Kurt D. Zeilenga for inclusion into OpenLDAP
  */
@@ -46,9 +51,9 @@
 
 #include "portable.h"
 
-#include <stdlib.h>
-#include <stddef.h>
-
+#include <ac/assert.h>
+#include <ac/stdlib.h>
+#include <ac/ctype.h>
 #include <ac/string.h>
 
 /* include socket.h to get sys/types.h and/or winsock2.h */
@@ -56,8 +61,6 @@
 
 #include "lutil.h"
 
-#define Assert(Cond) if (!(Cond)) abort()
-
 static const char Base64[] =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 static const char Pad64 = '=';
@@ -126,7 +129,7 @@ static const char Pad64 = '=';
    */
 
 int
-b64_ntop(
+lutil_b64_ntop(
        u_char const *src,
        size_t srclength,
        char *target,
@@ -147,10 +150,10 @@ b64_ntop(
                output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
                output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
                output[3] = input[2] & 0x3f;
-               Assert(output[0] < 64);
-               Assert(output[1] < 64);
-               Assert(output[2] < 64);
-               Assert(output[3] < 64);
+               assert(output[0] < 64);
+               assert(output[1] < 64);
+               assert(output[2] < 64);
+               assert(output[3] < 64);
 
                if (datalength + 4 > targsize)
                        return (-1);
@@ -170,9 +173,9 @@ b64_ntop(
                output[0] = input[0] >> 2;
                output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
                output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
-               Assert(output[0] < 64);
-               Assert(output[1] < 64);
-               Assert(output[2] < 64);
+               assert(output[0] < 64);
+               assert(output[1] < 64);
+               assert(output[2] < 64);
 
                if (datalength + 4 > targsize)
                        return (-1);
@@ -197,7 +200,7 @@ b64_ntop(
  */
 
 int
-b64_pton(
+lutil_b64_pton(
        char const *src,
        u_char *target, 
        size_t targsize)
@@ -209,7 +212,7 @@ b64_pton(
        tarindex = 0;
 
        while ((ch = *src++) != '\0') {
-               if (isspace(ch))        /* Skip whitespace anywhere. */
+               if (isascii(ch) && isspace(ch)) /* Skip whitespace anywhere. */
                        continue;
 
                if (ch == Pad64)
@@ -279,7 +282,7 @@ b64_pton(
                case 2:         /* Valid, means one byte of info */
                        /* Skip any number of spaces. */
                        for ((void)NULL; ch != '\0'; ch = *src++)
-                               if (!isspace(ch))
+                               if (! (isascii(ch) && isspace(ch)))
                                        break;
                        /* Make sure there is another trailing = sign. */
                        if (ch != Pad64)
@@ -294,7 +297,7 @@ b64_pton(
                         * whitespace after it?
                         */
                        for ((void)NULL; ch != '\0'; ch = *src++)
-                               if (!isspace(ch))
+                               if (! (isascii(ch) && isspace(ch)))
                                        return (-1);
 
                        /*