mime_hdr_new(char *name, char *value)
{
MIME_HEADER *mhdr;
- char *tmpname, *tmpval, *p;
+ char *tmpname = NULL, *tmpval = NULL, *p;
int c;
+
if (name) {
if (!(tmpname = BUF_strdup(name)))
- return NULL;
+ goto err;
for (p = tmpname; *p; p++) {
c = (unsigned char)*p;
if (isupper(c)) {
*p = c;
}
}
- } else
- tmpname = NULL;
+ }
if (value) {
if (!(tmpval = BUF_strdup(value)))
- return NULL;
+ goto err;
for (p = tmpval; *p; p++) {
c = (unsigned char)*p;
if (isupper(c)) {
*p = c;
}
}
- } else tmpval = NULL;
- mhdr = malloc(sizeof(MIME_HEADER));
- if (!mhdr) {
- OPENSSL_free(tmpname);
- return NULL;
}
+ mhdr = malloc(sizeof(MIME_HEADER));
+ if (!mhdr)
+ goto err;
mhdr->name = tmpname;
mhdr->value = tmpval;
if (!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) {
free(mhdr);
- return NULL;
+ goto err;
}
return mhdr;
+err:
+ free(tmpname);
+ free(tmpval);
+ return NULL;
}
static int
mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
{
- char *tmpname, *tmpval, *p;
+ char *tmpname = NULL, *tmpval = NULL, *p;
int c;
MIME_PARAM *mparam;
if (name) {
tmpname = BUF_strdup(name);
if (!tmpname)
- return 0;
+ goto err;
for (p = tmpname; *p; p++) {
c = (unsigned char)*p;
if (isupper(c)) {
*p = c;
}
}
- } else
- tmpname = NULL;
+ }
if (value) {
tmpval = BUF_strdup(value);
if (!tmpval)
- return 0;
- } else
- tmpval = NULL;
+ goto err;
+ }
/* Parameter values are case sensitive so leave as is */
mparam = malloc(sizeof(MIME_PARAM));
if (!mparam)
- return 0;
+ goto err;
mparam->param_name = tmpname;
mparam->param_value = tmpval;
sk_MIME_PARAM_push(mhdr->params, mparam);
return 1;
+err:
+ free(tmpname);
+ free(tmpval);
+ return 0;
}
static int
ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
return NULL;
}
- if (oct)
- *oct = octmp;
} else
octmp = *oct;
if (!(octmp->length = i2d(obj, NULL))) {
ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR);
- return NULL;
+ goto err;
}
if (!(p = malloc (octmp->length))) {
ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
- return NULL;
+ goto err;
}
octmp->data = p;
i2d (obj, &p);
+ if (oct)
+ *oct = octmp;
return octmp;
+err:
+ if (!oct || octmp != *oct)
+ ASN1_STRING_free(octmp);
+ return NULL;
}
#endif
ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE);
return NULL;
}
- if (oct)
- *oct = octmp;
} else
octmp = *oct;
if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) {
ASN1err(ASN1_F_ASN1_ITEM_PACK, ASN1_R_ENCODE_ERROR);
- return NULL;
+ goto err;
}
if (!octmp->data) {
ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE);
- return NULL;
+ goto err;
}
+ if (oct)
+ *oct = octmp;
return octmp;
+err:
+ if (!oct || octmp != *oct)
+ ASN1_STRING_free(octmp);
+ return NULL;
}
/* Extract an ASN1 object from an ASN1_STRING */
mime_hdr_new(char *name, char *value)
{
MIME_HEADER *mhdr;
- char *tmpname, *tmpval, *p;
+ char *tmpname = NULL, *tmpval = NULL, *p;
int c;
+
if (name) {
if (!(tmpname = BUF_strdup(name)))
- return NULL;
+ goto err;
for (p = tmpname; *p; p++) {
c = (unsigned char)*p;
if (isupper(c)) {
*p = c;
}
}
- } else
- tmpname = NULL;
+ }
if (value) {
if (!(tmpval = BUF_strdup(value)))
- return NULL;
+ goto err;
for (p = tmpval; *p; p++) {
c = (unsigned char)*p;
if (isupper(c)) {
*p = c;
}
}
- } else tmpval = NULL;
- mhdr = malloc(sizeof(MIME_HEADER));
- if (!mhdr) {
- OPENSSL_free(tmpname);
- return NULL;
}
+ mhdr = malloc(sizeof(MIME_HEADER));
+ if (!mhdr)
+ goto err;
mhdr->name = tmpname;
mhdr->value = tmpval;
if (!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) {
free(mhdr);
- return NULL;
+ goto err;
}
return mhdr;
+err:
+ free(tmpname);
+ free(tmpval);
+ return NULL;
}
static int
mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
{
- char *tmpname, *tmpval, *p;
+ char *tmpname = NULL, *tmpval = NULL, *p;
int c;
MIME_PARAM *mparam;
if (name) {
tmpname = BUF_strdup(name);
if (!tmpname)
- return 0;
+ goto err;
for (p = tmpname; *p; p++) {
c = (unsigned char)*p;
if (isupper(c)) {
*p = c;
}
}
- } else
- tmpname = NULL;
+ }
if (value) {
tmpval = BUF_strdup(value);
if (!tmpval)
- return 0;
- } else
- tmpval = NULL;
+ goto err;
+ }
/* Parameter values are case sensitive so leave as is */
mparam = malloc(sizeof(MIME_PARAM));
if (!mparam)
- return 0;
+ goto err;
mparam->param_name = tmpname;
mparam->param_value = tmpval;
sk_MIME_PARAM_push(mhdr->params, mparam);
return 1;
+err:
+ free(tmpname);
+ free(tmpval);
+ return 0;
}
static int
ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
return NULL;
}
- if (oct)
- *oct = octmp;
} else
octmp = *oct;
if (!(octmp->length = i2d(obj, NULL))) {
ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR);
- return NULL;
+ goto err;
}
if (!(p = malloc (octmp->length))) {
ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
- return NULL;
+ goto err;
}
octmp->data = p;
i2d (obj, &p);
+ if (oct)
+ *oct = octmp;
return octmp;
+err:
+ if (!oct || octmp != *oct)
+ ASN1_STRING_free(octmp);
+ return NULL;
}
#endif
ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE);
return NULL;
}
- if (oct)
- *oct = octmp;
} else
octmp = *oct;
if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) {
ASN1err(ASN1_F_ASN1_ITEM_PACK, ASN1_R_ENCODE_ERROR);
- return NULL;
+ goto err;
}
if (!octmp->data) {
ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE);
- return NULL;
+ goto err;
}
+ if (oct)
+ *oct = octmp;
return octmp;
+err:
+ if (!oct || octmp != *oct)
+ ASN1_STRING_free(octmp);
+ return NULL;
}
/* Extract an ASN1 object from an ASN1_STRING */