# Copyright (C) 1994, Index Data I/S
# All rights reserved.
# Sebastian Hammer, Adam Dickmeiss
-# $Id: Makefile,v 1.4 1995-03-07 09:23:12 quinn Exp $
+# $Id: Makefile,v 1.5 1995-03-08 12:11:59 quinn Exp $
SHELL=/bin/sh
INCLUDE=-I../include -I.
odr_choice.o odr_any.o ber_any.o odr.o
CPP=cc -E
-all: $(LIB) test
+all: $(LIB)
test: test.o $(LIB)
$(CC) $(CFLAGS) $(INCLUDE) -o test test.o $(LIB)
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: ber_any.c,v $
- * Revision 1.5 1995-02-14 20:39:54 quinn
+ * Revision 1.6 1995-03-08 12:12:02 quinn
+ * Added better error checking.
+ *
+ * Revision 1.5 1995/02/14 20:39:54 quinn
* Fixed bugs in completeBER and (serious one in) ber_oid.
*
* Revision 1.4 1995/02/14 11:54:33 quinn
switch (o->direction)
{
case ODR_DECODE:
- if ((res = completeBER(o->bp, 1000)) <= 0) /* FIX THIS */
+ if ((res = completeBER(o->bp, o->left)) <= 0) /* FIX THIS */
+ {
+ o->error = OPROTO;
return 0;
+ }
(*p)->buf = nalloc(o, res);
memcpy((*p)->buf, o->bp, res);
(*p)->len = (*p)->size = res;
return 1;
case ODR_ENCODE:
if ((*p)->len > o->left)
+ {
+ o->error = OSPACE;
return 0;
+ }
memcpy(o->bp , (*p)->buf, (*p)->len);
o->bp += (*p)->len;
o->left -= (*p)->len;
return 1;
- default: return 0;
+ default: o->error = OOTHER; return 0;
}
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: ber_bit.c,v $
- * Revision 1.2 1995-02-03 17:04:31 quinn
+ * Revision 1.3 1995-03-08 12:12:04 quinn
+ * Added better error checking.
+ *
+ * Revision 1.2 1995/02/03 17:04:31 quinn
* *** empty log message ***
*
* Revision 1.1 1995/02/02 20:38:49 quinn
{
case ODR_DECODE:
if ((res = ber_declen(o->bp, &len)) < 0)
+ {
+ o->error = OPROTO;
return 0;
+ }
o->bp += res;
o->left -= res;
if (cons) /* fetch component strings */
}
/* primitive bitstring */
if (len < 0)
+ {
+ o->error = OOTHER;
return 0;
+ }
if (len == 0)
return 1;
if (len - 1 > ODR_BITMASK_SIZE)
+ {
+ o->error = OOTHER;
return 0;
+ }
o->bp++; /* silently ignore the unused-bits field */
o->left--;
len--;
return 1;
case ODR_ENCODE:
if ((res = ber_enclen(o->bp, p->top + 2, 5, 0)) < 0)
+ {
+ o->error = OOTHER;
return 0;
+ }
o->bp += res;
o->left -= res;
if (p->top + 2 > o->left)
+ {
+ o->error = OSPACE;
return 0;
+ }
*(o->bp++) = 0; /* no unused bits here */
o->left--;
if (p->top < 0)
o->left -= p->top +1;
return 1;
case ODR_PRINT: return 1;
- default: return 0;
+ default: o->error = OOTHER; return 0;
}
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: ber_bool.c,v $
- * Revision 1.2 1995-02-09 15:51:45 quinn
+ * Revision 1.3 1995-03-08 12:12:06 quinn
+ * Added better error checking.
+ *
+ * Revision 1.2 1995/02/09 15:51:45 quinn
* Works better now.
*
* Revision 1.1 1995/02/02 16:21:51 quinn
switch (o->direction)
{
case ODR_ENCODE:
+ if (!o->left)
+ {
+ o->error = OSPACE;
+ return 0;
+ }
if (ber_enclen(o->bp, 1, 1, 1) != 1)
+ {
+ o->error = OOTHER;
return 0;
+ }
o->bp++;
o->left--;
*(o->bp++) = (unsigned char) *val;
return 1;
case ODR_DECODE:
if ((res = ber_declen(b, &len)) < 0)
+ {
+ o->error = OPROTO;
return 0;
+ }
if (len != 1)
+ {
+ o->error = OPROTO;
return 0;
+ }
o->bp+= res;
o->left -= res;
*val = *b;
return 1;
case ODR_PRINT:
return 1;
- default: return 0;
+ default: o->error = OOTHER; return 0;
}
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: ber_int.c,v $
- * Revision 1.3 1995-02-09 15:51:46 quinn
+ * Revision 1.4 1995-03-08 12:12:07 quinn
+ * Added better error checking.
+ *
+ * Revision 1.3 1995/02/09 15:51:46 quinn
* Works better now.
*
* Revision 1.2 1995/02/07 17:52:58 quinn
{
case ODR_DECODE:
if ((res = ber_decinteger(o->bp, val)) <= 0)
+ {
+ o->error = OPROTO;
return 0;
+ }
o->bp += res;
o->left -= res;
return 1;
case ODR_ENCODE:
if ((res = ber_encinteger(o->bp, *val, o->left)) <= 0)
+ {
+ o->error = OSPACE;
return 0;
+ }
o->bp += res;
o->left -= res;
return 1;
case ODR_PRINT: return 1;
- default: return 0;
+ default: o->error = OOTHER; return 0;
}
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: ber_null.c,v $
- * Revision 1.2 1995-02-09 15:51:46 quinn
+ * Revision 1.3 1995-03-08 12:12:09 quinn
+ * Added better error checking.
+ *
+ * Revision 1.2 1995/02/09 15:51:46 quinn
* Works better now.
*
* Revision 1.1 1995/02/02 16:21:52 quinn
switch (o->direction)
{
case ODR_ENCODE:
+ if (!o->left)
+ {
+ o->error = OSPACE;
+ return 0;
+ }
*(o->bp++) = 0X00;
o->left--;
#ifdef ODR_DEBUG
return 1;
case ODR_DECODE:
if (*(o->bp++) != 0X00)
+ {
+ o->error = OPROTO;
return 0;
+ }
o->left--;
#ifdef ODR_DEBUG
fprintf(stderr, "[NULL]\n");
#endif
return 1;
case ODR_PRINT: return 1;
- default: return 0;
+ default: o->error = OOTHER; return 0;
}
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: ber_oct.c,v $
- * Revision 1.4 1995-02-10 15:55:28 quinn
+ * Revision 1.5 1995-03-08 12:12:10 quinn
+ * Added better error checking.
+ *
+ * Revision 1.4 1995/02/10 15:55:28 quinn
* Bug fixes, mostly.
*
* Revision 1.3 1995/02/03 17:04:34 quinn
{
case ODR_DECODE:
if ((res = ber_declen(o->bp, &len)) < 0)
+ {
+ o->error = OPROTO;
return 0;
+ }
o->bp += res;
o->left -= res;
if (cons) /* fetch component strings */
}
/* primitive octetstring */
if (len < 0)
+ {
+ o->error = OOTHER;
return 0;
+ }
if (len + 1 > p->size - p->len)
{
c = nalloc(o, p->size += len + 1);
return 1;
case ODR_ENCODE:
if ((res = ber_enclen(o->bp, p->len, 5, 0)) < 0)
+ {
+ o->error = OOTHER;
return 0;
+ }
o->bp += res;
o->left -= res;
if (p->len == 0)
return 1;
if (p->len > o->left)
+ {
+ o->error = OSPACE;
return 0;
+ }
memcpy(o->bp, p->buf, p->len);
o->bp += p->len;
o->left -= p->len;
return 1;
case ODR_PRINT: return 1;
- default: return 0;
+ default: o->error = OOTHER; return 0;
}
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: ber_oid.c,v $
- * Revision 1.3 1995-03-01 08:40:56 quinn
+ * Revision 1.4 1995-03-08 12:12:11 quinn
+ * Added better error checking.
+ *
+ * Revision 1.3 1995/03/01 08:40:56 quinn
* Smallish changes.
*
* Revision 1.2 1995/02/14 20:39:55 quinn
{
case ODR_DECODE:
if ((res = ber_declen(o->bp, &len)) < 1)
+ {
+ o->error = OPROTO;
return 0;
+ }
if (len < 0)
+ {
+ o->error = OPROTO;
return 0;
+ }
o->bp += res;
o->left -= res;
if (len == 0)
do
{
if (!len)
+ {
+ o->error = OPROTO;
return 0;
+ }
p[pos] <<= 7;
p[pos] |= *o->bp & 0X7F;
len--;
o->bp++;
o->left--;
if (p[0] < 0 && p[1] <= 0)
+ {
+ o->error = ODATA;
return 0;
+ }
p[1] = p[0] * 40 + p[1];
for (pos = 1; p[pos] >= 0; pos++)
{
}
while (id);
if (n > o->left)
+ {
+ o->error = OSPACE;
return 0;
+ }
o->left -= n;
while (n--)
*(o->bp++) = octs[n] | ((n > 0) << 7);
}
if (ber_enclen(lenp, (o->bp - lenp) - 1, 1, 1) != 1)
+ {
+ o->error = OOTHER;
return 0;
+ }
return 1;
- default: return 0;
+ default: o->error = OOTHER; return 0;
}
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: ber_tag.c,v $
- * Revision 1.6 1995-02-14 11:54:33 quinn
+ * Revision 1.7 1995-03-08 12:12:13 quinn
+ * Added better error checking.
+ *
+ * Revision 1.6 1995/02/14 11:54:33 quinn
* Adjustments.
*
* Revision 1.5 1995/02/10 18:57:24 quinn
*
* Should perhaps be odr_tag?
*/
-int ber_tag(ODR o, void *p, int class, int tag, int *constructed)
+int ber_tag(ODR o, void *p, int class, int tag, int *constructed, int opt)
{
static int lclass = -1, ltag, br, lcons; /* save t&c rather than
decoding twice */
{
case ODR_ENCODE:
if (!*pp)
+ {
+ if (!opt)
+ o->error = OREQUIRED;
return 0;
+ }
if ((rd = ber_enctag(o->bp, class, tag, *constructed, o->left))
<=0)
+ {
+ o->error = OSPACE;
return -1;
+ }
o->bp += rd;
o->left -= rd;
#ifdef ODR_DEBUG
return 1;
case ODR_DECODE:
if (o->stackp > -1 && !odr_constructed_more(o))
+ {
+ if (!opt)
+ o->error = OREQUIRED;
return 0;
+ }
if (lclass < 0)
{
if ((br = ber_dectag(o->bp, &lclass, <ag, &lcons)) <= 0)
+ {
+ o->error = OPROTO;
return 0;
+ }
#ifdef ODR_DEBUG
fprintf(stderr, "\n[class=%d,tag=%d,cons=%d]", lclass, ltag,
lcons);
return 1;
}
else
+ {
+ if (!opt)
+ o->error = OREQUIRED;
return 0;
- case ODR_PRINT: return *pp != 0;
- default: return 0;
+ }
+ case ODR_PRINT:
+ if (!*pp && !opt)
+ o->error = OREQUIRED;
+ return *pp != 0;
+ default: o->error = OOTHER; return 0;
}
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: odr.c,v $
- * Revision 1.5 1995-03-07 13:28:57 quinn
+ * Revision 1.6 1995-03-08 12:12:15 quinn
+ * Added better error checking.
+ *
+ * Revision 1.5 1995/03/07 13:28:57 quinn
* *** empty log message ***
*
* Revision 1.4 1995/03/07 13:16:13 quinn
char *odr_errlist[] =
{
"No (unknown) error",
- "Memoy allocation failed",
+ "Memory allocation failed",
"System error",
"No space in buffer",
"Required data element missing",
"Unexpected tag",
- "Other error"
+ "Other error",
+ "Protocol error",
+ "Malformed data"
};
void odr_perror(ODR o, char *message)
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: odr_any.c,v $
- * Revision 1.1 1995-02-09 15:51:47 quinn
+ * Revision 1.2 1995-03-08 12:12:18 quinn
+ * Added better error checking.
+ *
+ * Revision 1.1 1995/02/09 15:51:47 quinn
* Works better now.
*
*/
*/
int odr_any(ODR o, Odr_any **p, int opt)
{
- if (o->direction == ODR_ENCODE && !*p)
- return opt;
+ if (o->error)
+ return 0;
if (o->direction == ODR_PRINT)
{
fprintf(o->print, "%sANY (len=%d)\n", odr_indent(o), (*p)->len);
if (ber_any(o, p))
return 1;
*p = 0;
+ if (!opt)
+ o->error = OREQUIRED;
return opt;
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: odr_bit.c,v $
- * Revision 1.5 1995-02-10 18:57:25 quinn
+ * Revision 1.6 1995-03-08 12:12:19 quinn
+ * Added better error checking.
+ *
+ * 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
{
int res, cons = 0;
+ if (o->error)
+ return 0;
if (o->t_class < 0)
{
o->t_class = ODR_UNIVERSAL;
o->t_tag = ODR_BITSTRING;
}
- 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, opt)) < 0)
return 0;
if (!res)
return opt;
if (o->direction == ODR_PRINT)
{
- fprintf(o->print, "%sBITSTRING(len=%d)\n", odr_indent(o), (*p)->top + 1);
+ fprintf(o->print, "%sBITSTRING(len=%d)\n", odr_indent(o),
+ (*p)->top + 1);
return 1;
}
if (o->direction == ODR_DECODE)
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: odr_bool.c,v $
- * Revision 1.3 1995-02-10 18:57:25 quinn
+ * Revision 1.4 1995-03-08 12:12:20 quinn
+ * Added better error checking.
+ *
+ * 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
{
int res, cons = 0;
+ if (o->error)
+ return 0;
if (o->t_class < 0)
{
o->t_class = ODR_UNIVERSAL;
o->t_tag = ODR_BOOLEAN;
}
- 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, opt)) < 0)
return 0;
if (!res)
return opt;
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: odr_choice.c,v $
- * Revision 1.2 1995-02-09 15:51:48 quinn
+ * Revision 1.3 1995-03-08 12:12:22 quinn
+ * Added better error checking.
+ *
+ * Revision 1.2 1995/02/09 15:51:48 quinn
* Works better now.
*
* Revision 1.1 1995/02/07 17:52:59 quinn
{
int i, cl = -1, tg, cn;
+ if (o->error)
+ return 0;
if (o->direction != ODR_DECODE && !*(char**)p)
return 0;
for (i = 0; arm[i].fun; i++)
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: odr_cons.c,v $
- * Revision 1.5 1995-02-10 18:57:25 quinn
+ * Revision 1.6 1995-03-08 12:12:23 quinn
+ * Added better error checking.
+ *
+ * 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
int res;
int cons = 1;
+ if (o->error)
+ return 0;
if (o->t_class < 0)
{
o->t_class = class;
o->t_tag = tag;
}
- 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, 1)) < 0)
return 0;
if (!res || !cons)
return 0;
int odr_constructed_more(ODR o)
{
+ if (o->error)
+ return 0;
if (o->stackp < 0)
return 0;
if (o->stack[o->stackp].len >= 0)
{
int res;
+ if (o->error)
+ return 0;
if (o->stackp < 0)
+ {
+ o->error = OOTHER;
return 0;
+ }
switch (o->direction)
{
case ODR_DECODE:
return 1;
}
else
+ {
+ o->error = OOTHER;
return 0;
+ }
}
else if (o->bp - o->stack[o->stackp].base !=
o->stack[o->stackp].len)
+ {
+ o->error = OOTHER;
return 0;
+ }
o->stackp--;
return 1;
case ODR_ENCODE:
if ((res = ber_enclen(o->stack[o->stackp].lenb,
o->bp - o->stack[o->stackp].base,
o->stack[o->stackp].lenlen, 1)) < 0)
- return 0;
+ {
+ o->error = OSPACE;
+ return 0;
+ }
if (res == 0) /* indefinite encoding */
{
*(o->bp++) = *(o->bp++) = 0;
o->stackp--;
return 1;
case ODR_PRINT: return 1;
- default: return 0;
+ default:
+ o->error = OOTHER;
+ return 0;
}
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: odr_int.c,v $
- * Revision 1.4 1995-02-10 18:57:25 quinn
+ * Revision 1.5 1995-03-08 12:12:25 quinn
+ * Added better error checking.
+ *
+ * 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
{
int res, cons = 0;
+ if (o->error)
+ return 0;
if (o->t_class < 0)
{
o->t_class = ODR_UNIVERSAL;
o->t_tag = ODR_INTEGER;
}
- 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, opt)) < 0)
return 0;
if (!res)
return opt;
return 1;
}
if (cons)
+ {
+ o->error = OPROTO;
return 0;
+ }
if (o->direction == ODR_DECODE)
*p = nalloc(o, sizeof(int));
return ber_integer(o, *p);
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: odr_null.c,v $
- * Revision 1.3 1995-02-10 18:57:25 quinn
+ * Revision 1.4 1995-03-08 12:12:26 quinn
+ * Added better error checking.
+ *
+ * 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
int res, cons = 0;
static int nullval = 0;
+ if (o->error)
+ return 0;
if (o->t_class < 0)
{
o->t_class = ODR_UNIVERSAL;
o->t_tag = ODR_NULL;
}
- 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, opt)) < 0)
return 0;
if (!res)
return opt;
return 1;
}
if (cons)
+ {
+ o->error = OPROTO;
return 0;
+ }
if (o->direction == ODR_DECODE)
*p = &nullval;
return ber_null(o, *p);
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: odr_oct.c,v $
- * Revision 1.6 1995-02-10 18:57:26 quinn
+ * Revision 1.7 1995-03-08 12:12:27 quinn
+ * Added better error checking.
+ *
+ * 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
{
int res, cons = 0;
+ if (o->error)
+ return 0;
if (o->t_class < 0)
{
o->t_class = ODR_UNIVERSAL;
o->t_tag = ODR_OCTETSTRING;
}
- 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, opt)) < 0)
return 0;
if (!res)
return opt;
}
if (ber_octetstring(o, *p, cons))
return 1;
- *p = 0;
+ o->error = OOTHER;
return 0;
}
int cons = 0, res;
Odr_oct *t;
+ if (o->error)
+ return 0;
if (o->t_class < 0)
{
o->t_class = ODR_UNIVERSAL;
o->t_tag = ODR_OCTETSTRING;
}
- 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, opt)) < 0)
return 0;
if (!res)
return opt;
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: odr_oid.c,v $
- * Revision 1.6 1995-03-01 08:40:56 quinn
+ * Revision 1.7 1995-03-08 12:12:29 quinn
+ * Added better error checking.
+ *
+ * Revision 1.6 1995/03/01 08:40:56 quinn
* Smallish changes.
*
* Revision 1.5 1995/02/10 18:57:26 quinn
{
int res, cons = 0;
+ if (o->error)
+ return 0;
if (o->t_class < 0)
{
o->t_class = ODR_UNIVERSAL;
o->t_tag = ODR_OID;
}
- 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, opt)) < 0)
return 0;
- if (!res || cons)
+ if (!res)
return opt;
+ if (cons)
+ {
+ o->error = OPROTO;
+ return 0;
+ }
if (o->direction == ODR_PRINT)
{
int i;
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: odr_seq.c,v $
- * Revision 1.6 1995-02-10 15:55:29 quinn
+ * Revision 1.7 1995-03-08 12:12:30 quinn
+ * Added better error checking.
+ *
+ * Revision 1.6 1995/02/10 15:55:29 quinn
* Bug fixes, mostly.
*
* Revision 1.5 1995/02/09 15:51:49 quinn
{
char **pp = (char**) p;
+ if (o->error)
+ return 0;
if (o->t_class < 0)
{
o->t_class = ODR_UNIVERSAL;
o->t_tag = ODR_SEQUENCE;
}
-
if (o->direction == ODR_DECODE)
*pp = 0;
if (odr_constructed_begin(o, p, o->t_class, o->t_tag))
if (!(*type)(o, *pp + i, 0))
return 0;
break;
- default: return 0;
+ default:
+ o->error = OOTHER;
+ return 0;
}
return odr_sequence_end(o);
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: odr_tag.c,v $
- * Revision 1.1 1995-02-02 16:21:54 quinn
+ * Revision 1.2 1995-03-08 12:12:31 quinn
+ * Added better error checking.
+ *
+ * Revision 1.1 1995/02/02 16:21:54 quinn
* First kick.
*
*/
int odr_implicit_settag(ODR o, int class, int tag)
{
+ if (o->error)
+ return 0;
if (o->t_class < 0)
{
o->t_class = class;