More in the way of error-checking.
authorSebastian Hammer <quinn@indexdata.com>
Fri, 10 Feb 1995 18:57:24 +0000 (18:57 +0000)
committerSebastian Hammer <quinn@indexdata.com>
Fri, 10 Feb 1995 18:57:24 +0000 (18:57 +0000)
odr/ber_any.c
odr/ber_tag.c
odr/odr_bit.c
odr/odr_bool.c
odr/odr_cons.c
odr/odr_int.c
odr/odr_null.c
odr/odr_oct.c
odr/odr_oid.c

index 6d69017..71846df 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: ber_any.c,v $
- * Revision 1.2  1995-02-10 15:55:28  quinn
+ * Revision 1.3  1995-02-10 18:57:24  quinn
+ * More in the way of error-checking.
+ *
+ * Revision 1.2  1995/02/10  15:55:28  quinn
  * Bug fixes, mostly.
  *
  * Revision 1.1  1995/02/09  15:51:45  quinn
@@ -49,31 +52,31 @@ int completeBER(unsigned char *buf, int len)
     unsigned char *b = buf;
     
     if (!buf[0] && !buf[1])
-       return -1;
+       return 0;
     if ((res = ber_dectag(b, &class, &tag, &cons)) <= 0)
        return 0;
     if (res > len)
-       return -1;
+       return 0;
     b += res;
     len -= res;
     if ((res = ber_declen(b, &ll)) <= 0)
-       return -1;
+       return 0;
     if (res > len)
-       return -1;
+       return 0;
     b += res;
     len -= res;
     if (ll >= 0)
        return (len >= ll ? ll + (b-buf) : -1);
     if (!cons)
-       return -1;    
+       return 0;    
     while (1)
     {
        if ((res = completeBER(b, len)) < 0)
-           return -1;
+           return 0;
        b += res;
        len -= res;
        if (len < 2)
-           return -1;
+           return 0;
        if (*b == 0 && *(b + 1) == 0)
            return (b - buf) + 2;
     }
index f6c3576..1c53686 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: ber_tag.c,v $
- * Revision 1.4  1995-02-10 15:55:28  quinn
+ * Revision 1.5  1995-02-10 18:57:24  quinn
+ * More in the way of error-checking.
+ *
+ * Revision 1.4  1995/02/10  15:55:28  quinn
  * Bug fixes, mostly.
  *
  * Revision 1.3  1995/02/09  15:51:46  quinn
  * On decoding:
  *      if tag && class match up, advance pointer and return 1. set cons.
  *      else leave pointer unchanged. Return 0.
+ *
+ * Should perhaps be odr_tag?
 */
-int ber_tag(ODR o, const void *p, int class, int tag, int *constructed)
+int ber_tag(ODR o, void *p, int class, int tag, int *constructed)
 {
     static int lclass = -1, ltag, br, lcons; /* save t&c rather than
                                                decoding twice */
     int rd;
+    char **pp = p;
 
+    if (o->direction == ODR_DECODE)
+       *pp = 0;
     o->t_class = -1;
     if (o->buf == o->bp)   /* This is insurance. It shouldn't be necessary */
        lclass = -1;
     switch (o->direction)
     {
        case ODR_ENCODE:
-           if (!p)
+           if (!*pp)
                return 0;
            if ((rd = ber_enctag(o->bp, class, tag, *constructed, o->left))
                <=0)
@@ -59,7 +67,7 @@ int ber_tag(ODR o, const void *p, int class, int tag, int *constructed)
            if (lclass < 0)
            {
                if ((br = ber_dectag(o->bp, &lclass, &ltag, &lcons)) <= 0)
-                   return -1;
+                   return 0;
 #ifdef ODR_DEBUG
                fprintf(stderr, "\n[class=%d,tag=%d,cons=%d]", lclass, ltag,
                    lcons);
@@ -75,7 +83,7 @@ int ber_tag(ODR o, const void *p, int class, int tag, int *constructed)
            }
            else
                return 0;
-       case ODR_PRINT: return p != 0;
+       case ODR_PRINT: return *pp != 0;
        default: return 0;
     }
 }
index b3dacbd..f20a252 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_bit.c,v $
- * Revision 1.4  1995-02-09 15:51:47  quinn
+ * Revision 1.5  1995-02-10 18:57:25  quinn
+ * More in the way of error-checking.
+ *
+ * Revision 1.4  1995/02/09  15:51:47  quinn
  * Works better now.
  *
  * Revision 1.3  1995/02/07  14:13:45  quinn
@@ -35,15 +38,10 @@ int odr_bitstring(ODR o, Odr_bitmask **p, int opt)
        o->t_class = ODR_UNIVERSAL;
        o->t_tag = ODR_BITSTRING;
     }
-    if (o->direction == ODR_DECODE)
-       *p = 0;
-    if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
+    if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons)) < 0)
        return 0;
     if (!res)
-    {
-       *p = 0;
        return opt;
-    }
     if (o->direction == ODR_PRINT)
     {
        fprintf(o->print, "%sBITSTRING(len=%d)\n", odr_indent(o), (*p)->top + 1);
index bc21834..7a09f96 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_bool.c,v $
- * Revision 1.2  1995-02-09 15:51:47  quinn
+ * Revision 1.3  1995-02-10 18:57:25  quinn
+ * More in the way of error-checking.
+ *
+ * Revision 1.2  1995/02/09  15:51:47  quinn
  * Works better now.
  *
  * Revision 1.1  1995/02/02  16:21:53  quinn
@@ -28,15 +31,10 @@ int odr_bool(ODR o, int **p, int opt)
        o->t_class = ODR_UNIVERSAL;
        o->t_tag = ODR_BOOLEAN;
     }
-    if (o->direction == ODR_DECODE)
-       *p = 0;
-    if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
+    if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons)) < 0)
        return 0;
     if (!res)
-    {
-       *p = 0;
        return opt;
-    }
     if (o->direction == ODR_PRINT)
     {
        fprintf(o->print, "%s%s\n", odr_indent(o), (**p ? "TRUE" : "FALSE"));
index 92ebf6a..f85d817 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_cons.c,v $
- * Revision 1.4  1995-02-10 15:55:29  quinn
+ * Revision 1.5  1995-02-10 18:57:25  quinn
+ * More in the way of error-checking.
+ *
+ * Revision 1.4  1995/02/10  15:55:29  quinn
  * Bug fixes, mostly.
  *
  * Revision 1.3  1995/02/09  15:51:48  quinn
@@ -30,9 +33,7 @@ int odr_constructed_begin(ODR o, void *p, int class, int tag)
        o->t_class = class;
        o->t_tag = tag;
     }
-    if (o->direction == ODR_DECODE)
-       *(char**)p = 0;
-    if ((res = ber_tag(o, *(char**)p, o->t_class, o->t_tag, &cons)) < 0)
+    if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons)) < 0)
        return 0;
     if (!res || !cons)
        return 0;
index 5b303b6..d617ea8 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_int.c,v $
- * Revision 1.3  1995-02-09 15:51:48  quinn
+ * Revision 1.4  1995-02-10 18:57:25  quinn
+ * More in the way of error-checking.
+ *
+ * Revision 1.3  1995/02/09  15:51:48  quinn
  * Works better now.
  *
  * Revision 1.2  1995/02/07  14:13:45  quinn
@@ -30,18 +33,10 @@ int odr_integer(ODR o, int **p, int opt)
        o->t_class = ODR_UNIVERSAL;
        o->t_tag = ODR_INTEGER;
     }
-    if (o->direction == ODR_DECODE)
-       *p =0;
-    if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
-    {
-       *p = 0;
+    if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons)) < 0)
        return 0;
-    }
     if (!res)
-    {
-       *p = 0;
        return opt;
-    }
     if (o->direction == ODR_PRINT)
     {
        fprintf(o->print, "%s%d\n", odr_indent(o), **p);
index 2db7952..a80a2ac 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_null.c,v $
- * Revision 1.2  1995-02-09 15:51:49  quinn
+ * Revision 1.3  1995-02-10 18:57:25  quinn
+ * More in the way of error-checking.
+ *
+ * Revision 1.2  1995/02/09  15:51:49  quinn
  * Works better now.
  *
  * Revision 1.1  1995/02/02  16:21:54  quinn
@@ -28,15 +31,10 @@ int odr_null(ODR o, int **p, int opt)
        o->t_class = ODR_UNIVERSAL;
        o->t_tag = ODR_NULL;
     }
-    if (o->direction == ODR_DECODE)
-       *p =0;
-    if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
+    if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons)) < 0)
        return 0;
     if (!res)
-    {
-       *p = 0;
        return opt;
-    }
     if (o->direction == ODR_PRINT)
     {
        fprintf(o->print, "%sNULL\n", odr_indent(o));
index 7ff12e1..1140648 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_oct.c,v $
- * Revision 1.5  1995-02-09 15:51:49  quinn
+ * Revision 1.6  1995-02-10 18:57:26  quinn
+ * More in the way of error-checking.
+ *
+ * Revision 1.5  1995/02/09  15:51:49  quinn
  * Works better now.
  *
  * Revision 1.4  1995/02/07  14:13:46  quinn
@@ -36,18 +39,10 @@ int odr_octetstring(ODR o, Odr_oct **p, int opt)
        o->t_class = ODR_UNIVERSAL;
        o->t_tag = ODR_OCTETSTRING;
     }
-    if (o->direction == ODR_DECODE)
-       *p = 0;
-    if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
-    {
-       *p = 0;
+    if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons)) < 0)
        return 0;
-    }
     if (!res)
-    {
-       *p = 0;
        return opt;
-    }
     if (o->direction == ODR_PRINT)
     {
        fprintf(o->print, "%sOCTETSTRING(len=%d)\n", odr_indent(o), (*p)->len);
@@ -79,15 +74,10 @@ int odr_cstring(ODR o, char **p, int opt)
        o->t_class = ODR_UNIVERSAL;
        o->t_tag = ODR_OCTETSTRING;
     }
-    if (o->direction == ODR_DECODE)
-       *p = 0;
-    if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
+    if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons)) < 0)
        return 0;
     if (!res)
-    {
-       *p = 0;
        return opt;
-    }
     if (o->direction == ODR_PRINT)
     {
        fprintf(o->print, "%s'%s'\n", odr_indent(o), *p);
index 9dce6b0..374092a 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_oid.c,v $
- * Revision 1.4  1995-02-10 15:55:29  quinn
+ * Revision 1.5  1995-02-10 18:57:26  quinn
+ * More in the way of error-checking.
+ *
+ * Revision 1.4  1995/02/10  15:55:29  quinn
  * Bug fixes, mostly.
  *
  * Revision 1.3  1995/02/09  15:51:49  quinn
@@ -34,18 +37,10 @@ int odr_oid(ODR o, Odr_oid **p, int opt)
        o->t_class = ODR_UNIVERSAL;
        o->t_tag = ODR_OID;
     }
-    if (o->direction == ODR_DECODE)
-       *p =0;
-    if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
-    {
-       *p = 0;
+    if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons)) < 0)
        return 0;
-    }
     if (!res || cons)
-    {
-       *p = 0;
        return opt;
-    }
     if (o->direction == ODR_PRINT)
     {
        int i;