if (!taglen && indef) { get_eoc(); } \
next_tag()
+/*
+ * error_if_bad_tag
+ *
+ * Checks that the next tag is the expected one; returns with an error
+ * if not.
+ */
+#define error_if_bad_tag(tagexpect) \
+ if (tagnum != (tagexpect)) { return (tagnum < (tagexpect)) ? ASN1_MISPLACED_FIELD : ASN1_MISSING_FIELD; }
+
/*
* get_field
*
* verification of tag numbers.
*/
#define get_field(var, tagexpect, decoder) \
- if (tagnum > (tagexpect)) return ASN1_MISSING_FIELD; \
- if (tagnum < (tagexpect)) return ASN1_MISPLACED_FIELD; \
+ error_if_bad_tag(tagexpect); \
if ((asn1class != CONTEXT_SPECIFIC || construction != CONSTRUCTED) \
&& (tagnum || taglen || asn1class != UNIVERSAL)) \
return ASN1_BAD_ID; \
/* similar to get_field_body */
#define get_lenfield(len, var, tagexpect, decoder) \
- if (tagnum > (tagexpect)) return ASN1_MISSING_FIELD; \
- if (tagnum < (tagexpect)) return ASN1_MISPLACED_FIELD; \
+ error_if_bad_tag(tagexpect); \
if ((asn1class != CONTEXT_SPECIFIC || construction != CONSTRUCTED) \
&& (tagnum || taglen || asn1class != UNIVERSAL)) \
return ASN1_BAD_ID; \
asn1_error_code asn1buf_destroy(asn1buf **buf)
{
if (*buf != NULL) {
- if ((*buf)->base != NULL) free((*buf)->base);
+ free((*buf)->base);
free(*buf);
*buf = NULL;
}
asn1_error_code asn1buf_unparse(const asn1buf *buf, char **s)
{
- if(*s != NULL) free(*s);
+ free(*s);
if(buf == NULL){
*s = malloc(sizeof("<NULL>"));
if(*s == NULL) return ENOMEM;
((d)<=15 ? ('A'+(d)-10) :\
'X'))
- if(*s != NULL) free(*s);
+ free(*s);
if(buf == NULL){
*s = malloc(sizeof("<NULL>"));
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. */
+#ifndef CONFIG_SMALL
#define asn1buf_ensure_space(buf,amount) \
((asn1buf_free(buf) < (amount)) \
? (asn1buf_expand((buf), (amount)-asn1buf_free(buf))) \
: 0)
+#endif
asn1_error_code asn1buf_expand
/* requires *buf is allocated
effects Inserts o into the buffer *buf, expanding the buffer if
necessary. Returns ENOMEM memory is exhausted. */
-#if ((__GNUC__ >= 2) && !defined(ASN1BUF_OMIT_INLINE_FUNCS))
+#if ((__GNUC__ >= 2) && !defined(ASN1BUF_OMIT_INLINE_FUNCS)) && !defined(CONFIG_SMALL)
extern __inline__ asn1_error_code asn1buf_insert_octet(asn1buf *buf, const int o)
{
asn1_error_code retval;
/*
* src/lib/krb5/asn.1/krb5_decode.c
*
- * Copyright 1994 by the Massachusetts Institute of Technology.
+ * Copyright 1994, 2008 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
if (indef) { get_eoc(); }\
next_tag()
+/*
+ * error_if_bad_tag
+ *
+ * Checks that the next tag is the expected one; returns with an error
+ * if not.
+ */
+#define error_if_bad_tag(tagexpect) \
+ if (tagnum != (tagexpect)) { clean_return ((tagnum < (tagexpect)) ? ASN1_MISPLACED_FIELD : ASN1_MISSING_FIELD); }
+
/* decode a field (<[UNIVERSAL id]> <length> <contents>)
check that the id number == tagexpect then
decode into var
get the next tag */
#define get_field(var,tagexpect,decoder)\
-if(tagnum > (tagexpect)) clean_return(ASN1_MISSING_FIELD);\
-if(tagnum < (tagexpect)) clean_return(ASN1_MISPLACED_FIELD);\
+error_if_bad_tag(tagexpect);\
if(asn1class != CONTEXT_SPECIFIC || construction != CONSTRUCTED)\
clean_return(ASN1_BAD_ID);\
get_field_body(var,decoder)
/* decode a field w/ its length (for string types) */
#define get_lenfield(len,var,tagexpect,decoder)\
-if(tagnum > (tagexpect)) clean_return(ASN1_MISSING_FIELD);\
-if(tagnum < (tagexpect)) clean_return(ASN1_MISPLACED_FIELD);\
+error_if_bad_tag(tagexpect);\
if(asn1class != CONTEXT_SPECIFIC || construction != CONSTRUCTED)\
clean_return(ASN1_BAD_ID);\
get_lenfield_body(len,var,decoder)
#define cleanup_manual()\
return 0;
-#define free_field(rep,f) if ((rep)->f) free((rep)->f)
+#define free_field(rep,f) free((rep)->f)
#define clear_field(rep,f) (*(rep))->f = 0
krb5_error_code decode_krb5_authenticator(const krb5_data *code, krb5_authenticator **rep)
cleanup_manual();
error_out:
if (rep && *rep) {
- if ((*rep)->replyKey.contents)
- free((*rep)->replyKey.contents);
- if ((*rep)->asChecksum.contents)
- free((*rep)->asChecksum.contents);
+ free((*rep)->replyKey.contents);
+ free((*rep)->asChecksum.contents);
free(*rep);
*rep = NULL;
}
asn1buf_destroy (&buf);
if (ret != 0 && *code != NULL) {
- if ((*code)->data != NULL)
- free ((*code)->data);
+ free ((*code)->data);
free (*code);
}
*buf = tmp;
last:
- if (ret != 0 && *val != NULL)
+ if (ret != 0)
free (*val);
return ret;
}
last:
if (ret != 0) {
- if (key->key_data_contents[0] != NULL) {
- free (key->key_data_contents[0]);
- key->key_data_contents[0] = NULL;
- }
- if (key->key_data_contents[1] != NULL) {
- free (key->key_data_contents[1]);
- key->key_data_contents[1] = NULL;
- }
+ free (key->key_data_contents[0]);
+ key->key_data_contents[0] = NULL;
+ free (key->key_data_contents[1]);
+ key->key_data_contents[1] = NULL;
}
return ret;
}
if (ret != 0) {
int i;
for (i = 0; i < *n_key_data; i++) {
- if ((*out)[i].key_data_contents[0] != NULL)
- free ((*out)[i].key_data_contents[0]);
- if ((*out)[i].key_data_contents[1] != NULL)
- free ((*out)[i].key_data_contents[1]);
+ free ((*out)[i].key_data_contents[0]);
+ free ((*out)[i].key_data_contents[1]);
}
free (*out);
*out = NULL;