summaryrefslogtreecommitdiff
path: root/pith/smime.c
diff options
context:
space:
mode:
Diffstat (limited to 'pith/smime.c')
-rw-r--r--pith/smime.c50
1 files changed, 26 insertions, 24 deletions
diff --git a/pith/smime.c b/pith/smime.c
index 07e22919..e330d1c9 100644
--- a/pith/smime.c
+++ b/pith/smime.c
@@ -1,10 +1,6 @@
-#if !defined(lint) && !defined(DOS)
-static char rcsid[] = "$Id: smime.c 1176 2008-09-29 21:16:42Z hubert@u.washington.edu $";
-#endif
-
/*
* ========================================================================
- * Copyright 2013-2021 Eduardo Chappa
+ * Copyright 2013-2022 Eduardo Chappa
* Copyright 2008 University of Washington
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -203,7 +199,7 @@ setup_pwdcert(void **pwdcert)
struct stat sbuf;
char pathdir[MAXPATH+1], pathkey[MAXPATH+1], fpath[MAXPATH+1], pathcert[MAXPATH+1];
char fpath2[MAXPATH+1], prompt[MAILTMPLEN];
- char *keyfile, *certfile, *text;
+ char *keyfile, *certfile, *text = NULL;
EVP_PKEY *pkey = NULL;
X509 *pcert = NULL;
PERSONAL_CERT *pc, *pc2 = NULL;
@@ -445,7 +441,7 @@ setup_pwdcert(void **pwdcert)
int
smime_expunge_cert(WhichCerts ctype)
{
- int count, removed;
+ int count = 0, removed;
CertList *cl, *dummy, *data;
char *path, buf[MAXPATH+1];
char *contents;
@@ -640,7 +636,7 @@ import_certificate(WhichCerts ctype, PERSONAL_CERT *p_cert, char *fname)
if(ctype == Password){
char PrivateKeyPath[MAXPATH+1], PublicCertPath[MAXPATH+1], s[MAXPATH+1];
char full_name_key[MAXPATH+1], full_name_cert[MAXPATH+1];
- char *use_this_file;
+ char *use_this_file = NULL;
char prompt[500];
EVP_PKEY *key = p_cert ? p_cert->key : NULL;
@@ -664,7 +660,7 @@ import_certificate(WhichCerts ctype, PERSONAL_CERT *p_cert, char *fname)
if(key != NULL
|| (key = load_pkey_with_prompt(full_filename, NULL, prompt, NULL)) != NULL){
BIO *ins = NULL;
- X509 *cert = p_cert ? p_cert->cert : NULL, *cert2;
+ X509 *cert = p_cert ? p_cert->cert : NULL;
strncpy(full_name_key, full_filename, sizeof(full_filename));
full_name_key[sizeof(full_name_key)-1] = '\0';
@@ -782,15 +778,16 @@ import_certificate(WhichCerts ctype, PERSONAL_CERT *p_cert, char *fname)
text = decrypt_file((char *)tmp, NULL, pwdcert);
if(text != NULL){
if(pc == NULL){
- pc = fs_get(sizeof(PERSONAL_CERT));
- memset((void *)pc, 0, sizeof(PERSONAL_CERT));
filename[strlen(filename)-strlen(EXTCERT(Private))] = '\0';
- pc->name = cpystr(filename);
- snprintf(buf, sizeof(buf), "%s%s", filename, EXTCERT(Public));
- buf[sizeof(buf)-1] = '\0';
- pc->cname = cpystr(buf);
- pc->key = key;
- pc->cert = cert;
+ if(strlen(filename) + strlen(EXTCERT(Public)) < MAXPATH){
+ pc = fs_get(sizeof(PERSONAL_CERT));
+ memset((void *)pc, 0, sizeof(PERSONAL_CERT));
+ pc->name = cpystr(filename);
+ pc->cname = fs_get(strlen(filename) + strlen(EXTCERT(Public)) + 1);
+ sprintf(pc->cname, "%s%s", filename, EXTCERT(Public));
+ pc->key = key;
+ pc->cert = cert;
+ }
}
if(encrypt_file((char *)tmp, text, pc)){ /* we did it! */
@@ -855,7 +852,7 @@ import_certificate(WhichCerts ctype, PERSONAL_CERT *p_cert, char *fname)
if(!ps_global->smime->privatecertlist){
ps_global->smime->privatecertlist = fs_get(sizeof(CertList));
- memset((void *)DATACERT(ctype), 0, sizeof(CertList));
+ memset((void *) ps_global->smime->privatecertlist, 0, sizeof(CertList));
}
for(s = t = filename; (t = strstr(s, ".key")) != NULL; s = t + 1);
@@ -1151,15 +1148,16 @@ app_RAND_write_file(const char *file)
CertList *
certlist_from_personal_certs(PERSONAL_CERT *pc)
{
- CertList *cl;
+ CertList *cl = NULL;
X509 *x;
if(pc == NULL)
return NULL;
- if((x = get_cert_for(pc->name, Public, 1)) != NULL)
+ if((x = get_cert_for(pc->name, Public, 1)) != NULL){
cl = smime_X509_to_cert_info(x, pc->name);
- cl->next = certlist_from_personal_certs(pc->next);
+ cl->next = certlist_from_personal_certs(pc->next);
+ }
return cl;
}
@@ -1929,9 +1927,11 @@ copy_dir_to_container(WhichCerts which, char *contents)
fpath[sizeof(fpath) - 1] = '\0';
}
else if(ret_dir){
- if(strlen(dstpath) + strlen(configcontainer) - strlen(ret_dir) + 1 < sizeof(dstpath))
- snprintf(fpath, sizeof(fpath), "%s%c%s",
- dstpath, tempfile[strlen(ret_dir)], configcontainer);
+ if(strlen(dstpath) + strlen(configcontainer) + 2 < sizeof(dstpath))
+ snprintf(fpath, sizeof(fpath), "%.*s%c%.*s",
+ (int) strlen(dstpath), dstpath,
+ tempfile[strlen(ret_dir)],
+ (int) (sizeof(fpath) - strlen(dstpath) - 1), configcontainer);
else
ret = -1;
}
@@ -3067,6 +3067,7 @@ do_detached_signature_verify(BODY *b, long msgno, char *section)
dprint((9, "do_detached_signature_verify(msgno=%ld type=%d subtype=%s section=%s)", msgno, b->type, b->subtype ? b->subtype : "NULL", (section && *section) ? section : (section != NULL) ? "Top" : "NULL"));
smime_init();
+ mimetext = bodytext = NULL;
/* if it was signed and then encrypted, use the decrypted text
* to check the validity of the signature
@@ -3265,6 +3266,7 @@ decrypt_file(char *fp, int *rv, PERSONAL_CERT *pc)
long unsigned int len;
void *ret;
+ if(rv) *rv = -1; /* assume failure */
if(pc == NULL || (text = read_file(fp, 0)) == NULL || *text == '\0')
return NULL;