asn1: Fix warnings

This commit is contained in:
Nicolas Williams
2021-03-27 22:49:22 -05:00
parent 80dceccdd6
commit 1fe3d293e1
8 changed files with 46 additions and 35 deletions

View File

@@ -453,10 +453,8 @@ dotype(unsigned char *buf, size_t len, char **argv, size_t *size)
char *s;
s = sorted_types[i].print(v, indent_flag ? ASN1_PRINT_INDENT : 0);
if (!s) {
ret = errno;
if (!s)
err(1, "Could not print %s\n", typename);
}
if (!quiet_flag)
printf("%s\n", s);
free(s);

View File

@@ -900,6 +900,8 @@ test_heim_oid_format_same(const char *str, const heim_oid *oid)
ret = der_heim_oid_cmp(&o2, oid);
der_free_oid(&o2);
if (ret != 0)
return 1;
return 0;
}

View File

@@ -105,7 +105,7 @@ print_heim_any(const heim_any *data, int flags)
free(s);
s = NULL;
if (r > -1)
r = asprintf(&s, "\"%s\"", s2);
(void) asprintf(&s, "\"%s\"", s2);
free(s2);
return s;
}
@@ -155,7 +155,7 @@ print_HEIM_ANY(const heim_any *data, int flags)
free(s);
s = NULL;
if (r > -1)
r = asprintf(&s, "\"%s\"", s2);
(void) asprintf(&s, "\"%s\"", s2);
free(s2);
return s;
}
@@ -205,7 +205,7 @@ print_heim_any_set(const heim_any_set *data, int flags)
free(s);
s = NULL;
if (r > -1)
r = asprintf(&s, "\"%s\"", s2);
(void) asprintf(&s, "\"%s\"", s2);
free(s2);
return s;
}
@@ -261,7 +261,7 @@ print_HEIM_ANY_SET(const heim_any_set *data, int flags)
free(s);
s = NULL;
if (r > -1)
r = asprintf(&s, "\"%s\"", s2);
(void) asprintf(&s, "\"%s\"", s2);
free(s2);
return s;
}

View File

@@ -461,23 +461,24 @@ encode_type (const char *name, const Type *t, const char *tmpstr)
if (replace_tag)
fprintf(codefile,
"{ unsigned char *psave_%s = p;\n"
"{ unsigned char *psave_%s = p, *pfree_%s = NULL;\n"
"size_t l2_%s, lensave_%s = len;\n"
"len = length_%s(%s);\n"
/* Allocate a temp buffer for the encoder */
"if ((p = malloc(len)) == NULL) return ENOMEM;\n"
"if ((p = pfree_%s = malloc(len)) == NULL) return ENOMEM;\n"
/* Make p point to the last byte of the allocated buf */
"p += len - 1;\n",
tmpstr, tmpstr, tmpstr,
t->subtype->symbol->gen_name, name);
tmpstr, tmpstr, tmpstr, tmpstr,
t->subtype->symbol->gen_name, name, tmpstr);
/* XXX Currently we generate code that leaks `pfree_%s` here. */
c = encode_type (name, t->subtype, tname);
/* Explicit non-UNIVERSAL tags are always constructed */
if (!c && t->tag.tagclass != ASN1_C_UNIV && t->tag.tagenv == TE_EXPLICIT)
c = 1;
if (replace_tag)
fprintf(codefile,
"if (len) abort();\n"
"if (len) { free(pfree_%s); return EINVAL; }\n"
/*
* Here we have `p' pointing to one byte before the buffer
* we allocated above.
@@ -551,8 +552,8 @@ encode_type (const char *name, const Type *t, const char *tmpstr)
* \
* +-- psave_<fieldName>
*/
"e = der_put_tag(psave_%s, %zu, %s, %s, %d, &l2_%s);\n"
"if (e) return e;\n"
"e = der_put_tag(psave_%s, %lu, %s, %s, %d, &l2_%s);\n"
"if (e) { free(pfree_%s); return e; }\n"
/* Restore `len' and adjust it (see `p' below) */
"len = lensave_%s - (l + %zu - asn1_tag_length_%s);\n"
/*
@@ -561,7 +562,7 @@ encode_type (const char *name, const Type *t, const char *tmpstr)
*/
"ret += %zu - asn1_tag_length_%s;\n"
/* Free the buffer and restore `p' */
"free(p + 1);\n"
"free(pfree_%s);\n"
/*
* Make `p' point into the original buffer again, to one
* byte before the bytes we wrote:
@@ -572,8 +573,8 @@ encode_type (const char *name, const Type *t, const char *tmpstr)
* \
* +-- p
*/
"p = psave_%s - (1 + %zu - asn1_tag_length_%s); }\n",
tmpstr, tmpstr, t->subtype->symbol->name,
"p = psave_%s - (1 + %lu - asn1_tag_length_%s); }\n",
tmpstr, tmpstr, tmpstr, t->subtype->symbol->name,
tmpstr, t->subtype->symbol->name, t->subtype->symbol->name,
tmpstr, length_tag(t->tag.tagvalue),
classname(t->tag.tagclass),
@@ -581,9 +582,9 @@ encode_type (const char *name, const Type *t, const char *tmpstr)
t->tag.tagvalue,
tmpstr,
tmpstr, length_tag(t->tag.tagvalue), t->subtype->symbol->name,
tmpstr, tmpstr, length_tag(t->tag.tagvalue), t->subtype->symbol->name,
length_tag(t->tag.tagvalue), t->subtype->symbol->name,
tmpstr, length_tag(t->tag.tagvalue), t->subtype->symbol->name);
tmpstr, tmpstr, length_tag(t->tag.tagvalue), t->subtype->symbol->name);
else
fprintf(codefile,
"e = der_put_length_and_tag (p, len, ret, %s, %s, %s, &l);\n"

View File

@@ -56,6 +56,7 @@ free_type (const char *name, const Type *t, int preserve)
free_primitive ("heim_integer", name);
break;
}
/* fallthrough */
case TBoolean:
case TEnumerated :
case TNull:

View File

@@ -579,12 +579,12 @@ defval(struct templatehead *temp, Member *m)
if (t->members)
dv = "A1_DV_INTEGER32"; /* XXX Enum size assumptions! No good! */
else if (t->range->min < 0 &&
else if (t->range && t->range->min < 0 &&
(t->range->min < INT_MIN || t->range->max > INT_MAX))
dv = "A1_DV_INTEGER64";
else if (t->range->min < 0)
else if (t->range && t->range->min < 0)
dv = "A1_DV_INTEGER32";
else if (t->range->max > UINT_MAX)
else if (t->range && t->range->max > UINT_MAX)
dv = "A1_DV_INTEGER64";
else
dv = "A1_DV_INTEGER32";
@@ -627,9 +627,11 @@ defval(struct templatehead *temp, Member *m)
sz -= len;
p += len;
}
len = snprintf(p, sz, " }");
if ((len = snprintf(p, sz, " }")) >= sz)
abort();
sz -= len;
p += len;
if (sz != 0)
abort();
add_line(temp, "{ A1_OP_DEFVAL|A1_DV_INTEGER, ~0, (void *)(uintptr_t)\"%s\" }", s);
free(s);
@@ -733,6 +735,9 @@ sort_object_set(IOSObjectSet *os, /* Object set to sort fields of */
}
*nobjsp = nobjs;
if (nobjs == 0)
return;
if ((objects = calloc(nobjs, sizeof(*objects))) == NULL)
err(1, "Out of memory");
*objectsp = objects;
@@ -755,7 +760,7 @@ sort_object_set(IOSObjectSet *os, /* Object set to sort fields of */
static void
template_object_set(IOSObjectSet *os, Field *typeidfield, Field *opentypefield)
{
IOSObject **objects;
IOSObject **objects = NULL;
IOSObject *o;
struct tlist *tl;
size_t nobjs, i;

View File

@@ -331,7 +331,6 @@ der_print_heim_oid_sym(const heim_oid *oid, char delim, char **strp)
*strp = s1;
return 0;
}
p = s2 + strlen(s1) + 1;
for (p = s2 + strlen(s1) + 1; *p; p++) {
if (*p == '_')
*p = '-';

View File

@@ -831,6 +831,8 @@ _asn1_decode(const struct asn1_template *t, unsigned flags,
if (ret) {
if (t->tt & A1_FLAG_OPTIONAL) {
} else if (t->tt & A1_FLAG_DEFAULT) {
if (!tdefval)
return ASN1_PARSE_ERROR; /* Can't happen */
/*
* Defaulted field not present in encoding, presumably,
* though we should really look more carefully at `ret'.
@@ -897,6 +899,8 @@ _asn1_decode(const struct asn1_template *t, unsigned flags,
data = olddata;
break;
} else if (t->tt & A1_FLAG_DEFAULT) {
if (!tdefval)
return ASN1_PARSE_ERROR; /* Can't happen */
/*
* Defaulted field not present in encoding, presumably,
* though we should really look more carefully at `ret'.
@@ -1586,10 +1590,9 @@ _asn1_encode(const struct asn1_template *t, unsigned char *p, size_t len, const
}
if (ret == 0) {
/* Copy the encoding where it belongs */
len -= l; p -= l;
psave -= (datalen + l - oldtaglen);
lensave -= (datalen + l - oldtaglen);
memcpy(psave + 1, p + 1, datalen + l - oldtaglen);
memcpy(psave + 1, p + 1 - l, datalen + l - oldtaglen);
p = psave;
len = lensave;
}
@@ -2287,7 +2290,7 @@ _asn1_free(const struct asn1_template *t, void *data)
*(void **)el = 0;
} else if (f && f->release)
(f->release)(el);
else
else if (f)
memset(el, 0, f->size);
}
if (t->tt & A1_FLAG_OPTIONAL) {
@@ -2833,7 +2836,7 @@ _asn1_copy_open_type(const struct asn1_template *t, /* object set template */
*dtop = NULL;
if ((valto = calloc(len, sizeof(valto[0]))) == NULL)
ret = ENOMEM;
for (i = 0, len = *lenfromp; ret == 0 && i < len; (*lentop)++, i++) {
for (i = 0, len = *lenfromp; ret == 0 && i < len; i++) {
if (valfrom[i] == NULL) {
valto[i] = NULL;
continue;
@@ -2842,17 +2845,19 @@ _asn1_copy_open_type(const struct asn1_template *t, /* object set template */
ret = ENOMEM;
else
ret = _asn1_copy(tactual_type->ptr, valfrom[i], valto[i]);
(*lentop)++;
}
for (i = 0; ret && i < len; i++) {
for (i = 0; ret && i < (*lentop); i++) {
if (valto[i]) {
_asn1_free(tactual_type->ptr, valto[i]);
free(valto[i]);
}
}
if (ret)
if (ret) {
free(valto);
else
*lentop = 0;
} else
*dtop = valto;
return ret;
}
@@ -2920,9 +2925,9 @@ _asn1_copy(const struct asn1_template *t, const void *from, void *to)
/* A1_OP_TYPE_DECORATE_EXTERN */
if (t->tt & A1_FLAG_HEIM_OBJ)
*(heim_object_t *)tel = heim_retain(*(void **)fel);
else if (f->copy)
else if (f && f->copy)
ret = (f->copy)(fel, tel);
else
else if (f)
memset(tel, 0, f->size);
}