summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEzra Peisach <epeisach@mit.edu>1997-08-14 15:38:14 +0000
committerEzra Peisach <epeisach@mit.edu>1997-08-14 15:38:14 +0000
commit3144fb833f8e7eb4f8ac183d48404e5c68b295a2 (patch)
treeb4b9c11ffb122d1a0c54f45d611fa792a9332c21
parentf2952ba70fbf6694213996e318b633570d8dae24 (diff)
downloadkrb5-3144fb833f8e7eb4f8ac183d48404e5c68b295a2.tar.gz
krb5-3144fb833f8e7eb4f8ac183d48404e5c68b295a2.tar.xz
krb5-3144fb833f8e7eb4f8ac183d48404e5c68b295a2.zip
Changes from the Kerbnet release by Cygnus
* asn1buf.h (asn1buf_remove_octet, asn1buf_size, asn1buf_free, asn1buf_ensure_space, asn1buf_len): Add macro versions. (asn1buf_insert_octet) [__GNUC__ >= 2]: Ditto, using a GNU C extension. * asn1buf.c (asn1buf_remove_octet, asn1buf_size, asn1buf_free, asn1buf_ensure_space, asn1buf_len, asn1buf_insert_octet): Undef macros before defining as functions. [Kerbnet changes made by raeburn@cygnus.com] * asn1buf.h (asn1buf_expand): Remove "const" from int arg in prototype. * asn1buf.c (asn1buf_remove_charstring, asn1buf_create, asn1buf_remove_octetstring, asn12krb5_buf): Call malloc instead of calloc. (asn1buf_unparse, asn1buf_hex_unparse): Ditto. Also don't allocate extra byte, since sizeof(STRING) does count the trailing null. (asn1buf_expand): Adjust bound based on increment value used, not value specified by caller. [Kerbnet changes made by raeburn@cygnus.com] git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@10174 dc483132-0cff-0310-8789-dd5450dbe970
-rw-r--r--src/lib/krb5/asn.1/ChangeLog27
-rw-r--r--src/lib/krb5/asn.1/asn1buf.c42
-rw-r--r--src/lib/krb5/asn.1/asn1buf.h27
3 files changed, 77 insertions, 19 deletions
diff --git a/src/lib/krb5/asn.1/ChangeLog b/src/lib/krb5/asn.1/ChangeLog
index b1d5bf7896..c3b56a751e 100644
--- a/src/lib/krb5/asn.1/ChangeLog
+++ b/src/lib/krb5/asn.1/ChangeLog
@@ -1,3 +1,30 @@
+Thu Jul 31 15:38:10 1997 Ezra Peisach <epeisach@kangaroo.mit.edu>
+
+ * asn1buf.h (asn1buf_remove_octet, asn1buf_size, asn1buf_free,
+ asn1buf_ensure_space, asn1buf_len): Add macro versions.
+ (asn1buf_insert_octet) [__GNUC__ >= 2]: Ditto, using a GNU C
+ extension.
+ * asn1buf.c (asn1buf_remove_octet, asn1buf_size, asn1buf_free,
+ asn1buf_ensure_space, asn1buf_len, asn1buf_insert_octet): Undef
+ macros before defining as functions.
+ [Kerbnet changes made by raeburn@cygnus.com]
+
+Thu Jul 31 12:34:43 1997 Ezra Peisach <epeisach@mit.edu>
+
+ * asn1buf.h (asn1buf_expand): Remove "const" from int arg in
+ prototype.
+
+ * asn1buf.c (asn1buf_remove_charstring, asn1buf_create,
+ asn1buf_remove_octetstring, asn12krb5_buf): Call malloc instead of
+ calloc.
+ (asn1buf_unparse, asn1buf_hex_unparse): Ditto. Also don't
+ allocate extra byte, since sizeof(STRING) does count the trailing
+ null.
+ (asn1buf_expand): Adjust bound based on increment
+ value used, not value specified by caller.
+
+ [Kerbnet changes made by raeburn@cygnus.com]
+
Thu Jul 31 11:17:06 1997 Ezra Peisach <epeisach@mit.edu>
* Makefile.in (SRCS): Add / after $(srcdir) in SRCS line.
diff --git a/src/lib/krb5/asn.1/asn1buf.c b/src/lib/krb5/asn.1/asn1buf.c
index 822b26377d..94b4ac418d 100644
--- a/src/lib/krb5/asn.1/asn1buf.c
+++ b/src/lib/krb5/asn.1/asn1buf.c
@@ -54,7 +54,7 @@
asn1_error_code asn1buf_create(buf)
asn1buf ** buf;
{
- *buf = (asn1buf*)calloc(1,sizeof(asn1buf));
+ *buf = (asn1buf*)malloc(sizeof(asn1buf));
if (*buf == NULL) return ENOMEM;
(*buf)->base = NULL;
(*buf)->bound = NULL;
@@ -105,6 +105,9 @@ asn1_error_code asn1buf_destroy(buf)
return 0;
}
+#ifdef asn1buf_insert_octet
+#undef asn1buf_insert_octet
+#endif
asn1_error_code asn1buf_insert_octet(buf, o)
asn1buf * buf;
const int o;
@@ -148,6 +151,7 @@ asn1_error_code asn1buf_insert_charstring(buf, len, s)
return 0;
}
+#undef asn1buf_remove_octet
asn1_error_code asn1buf_remove_octet(buf, o)
asn1buf * buf;
asn1_octet * o;
@@ -169,7 +173,7 @@ asn1_error_code asn1buf_remove_octetstring(buf, len, s)
*s = 0;
return 0;
}
- *s = (asn1_octet*)calloc(len,sizeof(asn1_octet));
+ *s = (asn1_octet*)malloc(len*sizeof(asn1_octet));
if (*s == NULL)
return ENOMEM;
for(i=0; i<len; i++)
@@ -190,7 +194,7 @@ asn1_error_code asn1buf_remove_charstring(buf, len, s)
*s = 0;
return 0;
}
- *s = (char*)calloc(len,sizeof(char));
+ *s = (char*)malloc(len*sizeof(char));
if (*s == NULL) return ENOMEM;
for(i=0; i<len; i++)
(*s)[i] = (char)(buf->next)[i];
@@ -230,7 +234,7 @@ asn1_error_code asn12krb5_buf(buf, code)
(*code)->data = NULL;
(*code)->length = 0;
(*code)->length = asn1buf_len(buf);
- (*code)->data = (char*)calloc(((*code)->length)+1,sizeof(char));
+ (*code)->data = (char*)malloc((((*code)->length)+1)*sizeof(char));
for(i=0; i < (*code)->length; i++)
((*code)->data)[i] = (buf->base)[((*code)->length)-i-1];
((*code)->data)[(*code)->length] = '\0';
@@ -248,11 +252,11 @@ asn1_error_code asn1buf_unparse(buf, s)
{
if(*s != NULL) free(*s);
if(buf == NULL){
- *s = calloc(sizeof("<NULL>")+1, sizeof(char));
+ *s = malloc(sizeof("<NULL>"));
if(*s == NULL) return ENOMEM;
strcpy(*s,"<NULL>");
}else if(buf->base == NULL){
- *s = calloc(sizeof("<EMPTY>")+1, sizeof(char));
+ *s = malloc(sizeof("<EMPTY>"));
if(*s == NULL) return ENOMEM;
strcpy(*s,"<EMPTY>");
}else{
@@ -279,18 +283,18 @@ asn1_error_code asn1buf_hex_unparse(buf, s)
if(*s != NULL) free(*s);
if(buf == NULL){
- *s = calloc(sizeof("<NULL>")+1, sizeof(char));
+ *s = malloc(sizeof("<NULL>"));
if(*s == NULL) return ENOMEM;
strcpy(*s,"<NULL>");
}else if(buf->base == NULL){
- *s = calloc(sizeof("<EMPTY>")+1, sizeof(char));
+ *s = malloc(sizeof("<EMPTY>"));
if(*s == NULL) return ENOMEM;
strcpy(*s,"<EMPTY>");
}else{
int length = asn1buf_len(buf);
int i;
- *s = calloc(3*length, sizeof(char));
+ *s = malloc(3*length);
if(*s == NULL) return ENOMEM;
for(i = length-1; i >= 0; i--){
(*s)[3*(length-i-1)] = hexchar(((buf->base)[i]&0xF0)>>4);
@@ -305,6 +309,7 @@ asn1_error_code asn1buf_hex_unparse(buf, s)
/****************************************************************/
/* Private Procedures */
+#undef asn1buf_size
int asn1buf_size(buf)
const asn1buf * buf;
{
@@ -312,6 +317,7 @@ int asn1buf_size(buf)
return buf->bound - buf->base + 1;
}
+#undef asn1buf_free
int asn1buf_free(buf)
const asn1buf * buf;
{
@@ -319,6 +325,7 @@ int asn1buf_free(buf)
else return buf->bound - buf->next + 1;
}
+#undef asn1buf_ensure_space
asn1_error_code asn1buf_ensure_space(buf, amount)
asn1buf * buf;
const int amount;
@@ -333,7 +340,7 @@ asn1_error_code asn1buf_ensure_space(buf, amount)
asn1_error_code asn1buf_expand(buf, inc)
asn1buf * buf;
- const int inc;
+ int inc;
{
#define STANDARD_INCREMENT 200
int next_offset = buf->next - buf->base;
@@ -341,22 +348,21 @@ asn1_error_code asn1buf_expand(buf, inc)
if(buf->base == NULL) bound_offset = -1;
else bound_offset = buf->bound - buf->base;
+ if (inc < STANDARD_INCREMENT)
+ inc = STANDARD_INCREMENT;
+
if (buf->base == NULL)
- buf->base = malloc((asn1buf_size(buf)+(inc>STANDARD_INCREMENT ?
- inc : STANDARD_INCREMENT))
- * sizeof(asn1_octet));
+ buf->base = malloc((asn1buf_size(buf)+inc) * sizeof(asn1_octet));
else
buf->base = realloc(buf->base,
- (asn1buf_size(buf)+(inc>STANDARD_INCREMENT ?
- inc : STANDARD_INCREMENT))
- * sizeof(asn1_octet));
+ (asn1buf_size(buf)+inc) * sizeof(asn1_octet));
if(buf->base == NULL) return ENOMEM;
- buf->bound = (buf->base) + bound_offset + (inc > STANDARD_INCREMENT ?
- inc : STANDARD_INCREMENT);
+ buf->bound = (buf->base) + bound_offset + inc;
buf->next = (buf->base) + next_offset;
return 0;
}
+#undef asn1buf_len
int asn1buf_len(buf)
const asn1buf * buf;
{
diff --git a/src/lib/krb5/asn.1/asn1buf.h b/src/lib/krb5/asn.1/asn1buf.h
index f3f4a3f2e0..1aad777cb4 100644
--- a/src/lib/krb5/asn.1/asn1buf.h
+++ b/src/lib/krb5/asn.1/asn1buf.h
@@ -82,6 +82,12 @@ asn1_error_code asn1buf_insert_octet
/* requires *buf is allocated
effects Inserts o into the buffer *buf, expanding the buffer if
necessary. Returns ENOMEM memory is exhausted. */
+#if __GNUC__ >= 2
+#define asn1buf_insert_octet(BUF,O) \
+ (asn1buf_ensure_space ((BUF),1) \
+ ? /* leave this empty -- gcc returns value of first operand */ \
+ : (*(BUF)->next++ = (O), 0))
+#endif
asn1_error_code asn1buf_insert_octetstring
PROTOTYPE((asn1buf *buf, const int len, const asn1_octet *s));
@@ -105,6 +111,10 @@ asn1_error_code asn1buf_remove_octet
effects Returns *buf's current octet in *o and advances to
the next octet.
Returns ASN1_OVERRUN if *buf has already been exhuasted. */
+#define asn1buf_remove_octet(buf,o) \
+ (((buf)->next > (buf)->bound) \
+ ? ASN1_OVERRUN \
+ : ((*(o) = (asn1_octet)(*(((buf)->next)++))),0))
asn1_error_code asn1buf_remove_octetstring
PROTOTYPE((asn1buf *buf, const int len, asn1_octet **s));
@@ -155,11 +165,20 @@ int asn1buf_size
/* requires *buf has been created and not destroyed
effects Returns the total size
PROTOTYPE((in octets) of buf's octet buffer. */
+#define asn1buf_size(buf) \
+ (((buf) == NULL || (buf)->base == NULL) \
+ ? 0 \
+ : ((buf)->bound - (buf)->base + 1))
int asn1buf_free
PROTOTYPE((const asn1buf *buf));
/* requires *buf is allocated
effects Returns the number of unused, allocated octets in *buf. */
+#define asn1buf_free(buf) \
+ (((buf) == NULL || (buf)->base == NULL) \
+ ? 0 \
+ : ((buf)->bound - (buf)->next + 1))
+
asn1_error_code asn1buf_ensure_space
PROTOTYPE((asn1buf *buf, const int amount));
@@ -168,9 +187,14 @@ asn1_error_code asn1buf_ensure_space
effects If buf has less than amount octets of free space, then it is
expanded to have at least amount octets of free space.
Returns ENOMEM memory is exhausted. */
+#define asn1buf_ensure_space(buf,amount) \
+ ((asn1buf_free(buf) < (amount)) \
+ ? (asn1buf_expand((buf), (amount)-asn1buf_free(buf))) \
+ : 0)
+
asn1_error_code asn1buf_expand
- PROTOTYPE((asn1buf *buf, const int inc));
+ PROTOTYPE((asn1buf *buf, int inc));
/* requires *buf is allocated
modifies *buf
effects Expands *buf by allocating space for inc more octets.
@@ -180,5 +204,6 @@ int asn1buf_len
PROTOTYPE((const asn1buf *buf));
/* requires *buf is allocated
effects Returns the length of the encoding in *buf. */
+#define asn1buf_len(buf) ((buf)->next - (buf)->base)
#endif