Browse Source

avoid unitialized local pointer variables to reduce hard-to-find bugs

doc_update_sequoia
Roker 5 years ago
parent
commit
bbe403a3bb
11 changed files with 42 additions and 79 deletions
  1. +3
    -8
      src/bloblist.c
  2. +2
    -5
      src/identity_list.c
  3. +7
    -14
      src/keymanagement.c
  4. +9
    -15
      src/message_api.c
  5. +5
    -8
      src/pEpEngine.c
  6. +2
    -5
      src/pgp_gpg.c
  7. +7
    -10
      src/pgp_netpgp.c
  8. +1
    -2
      src/platform_unix.c
  9. +2
    -5
      src/stringlist.c
  10. +3
    -6
      src/stringpair.c
  11. +1
    -1
      src/sync_actions.c

+ 3
- 8
src/bloblist.c View File

@ -44,13 +44,10 @@ DYNAMIC_API bloblist_t *new_bloblist(char *blob, size_t size, const char *mime_t
DYNAMIC_API void free_bloblist(bloblist_t *bloblist)
{
bloblist_t *curr;
bloblist_t *next;
curr = bloblist;
bloblist_t *curr = bloblist;
while (curr) {
next = curr->next;
bloblist_t *next = curr->next;
free(curr->value);
free(curr->mime_type);
free(curr->filename);
@ -61,8 +58,6 @@ DYNAMIC_API void free_bloblist(bloblist_t *bloblist)
DYNAMIC_API bloblist_t *bloblist_dup(const bloblist_t *src)
{
bloblist_t *bloblist = NULL;
assert(src);
if (src == NULL)
return NULL;
@ -75,7 +70,7 @@ DYNAMIC_API bloblist_t *bloblist_dup(const bloblist_t *src)
memcpy(blob2, src->value, src->size);
bloblist = new_bloblist(blob2, src->size, src->mime_type, src->filename);
bloblist_t *bloblist = new_bloblist(blob2, src->size, src->mime_type, src->filename);
if (bloblist == NULL)
goto enomem;
blob2 = NULL;


+ 2
- 5
src/identity_list.c View File

@ -64,13 +64,10 @@ DYNAMIC_API identity_list *identity_list_dup(const identity_list *src)
DYNAMIC_API void free_identity_list(identity_list *id_list)
{
identity_list *curr;
identity_list *next;
curr = id_list;
identity_list *curr = id_list;
while (curr) {
next = curr->next;
identity_list *next = curr->next;
free_identity(curr->ident);
free(curr);
curr = next;


+ 7
- 14
src/keymanagement.c View File

@ -26,7 +26,7 @@ PEP_STATUS elect_pubkey(
)
{
PEP_STATUS status;
stringlist_t *keylist;
stringlist_t *keylist = NULL;
char *_fpr = "";
identity->comm_type = PEP_ct_unknown;
@ -82,8 +82,8 @@ DYNAMIC_API PEP_STATUS update_identity(
PEP_SESSION session, pEp_identity * identity
)
{
pEp_identity *stored_identity;
pEp_identity* temp_id = NULL;
pEp_identity *stored_identity = NULL;
pEp_identity *temp_id = NULL;
PEP_STATUS status;
assert(session);
@ -201,7 +201,7 @@ DYNAMIC_API PEP_STATUS update_identity(
/* At this point, we either have a non-blacklisted fpr we can work */
/* with, or we've got nada. */
/* with, or we've got nada. */
if (EMPTYSTR(temp_id->fpr)) {
/* nada : set comm_type accordingly */
@ -308,13 +308,8 @@ DYNAMIC_API PEP_STATUS update_identity(
identity->flags = temp_id->flags;
exit_free :
if (stored_identity){
free_identity(stored_identity);
}
if (temp_id)
free_identity(temp_id);
free_identity(stored_identity);
free_identity(temp_id);
return status;
}
@ -416,7 +411,7 @@ PEP_STATUS _has_usable_priv_key(PEP_SESSION session, char* fpr,
PEP_STATUS _myself(PEP_SESSION session, pEp_identity * identity, bool do_keygen, bool ignore_flags)
{
pEp_identity *stored_identity;
pEp_identity *stored_identity = NULL;
PEP_STATUS status;
assert(session);
@ -489,7 +484,6 @@ PEP_STATUS _myself(PEP_SESSION session, pEp_identity * identity, bool do_keygen,
}
identity->flags = (identity->flags & 255) | stored_identity->flags;
free_identity(stored_identity);
}
@ -639,7 +633,6 @@ PEP_STATUS _myself(PEP_SESSION session, pEp_identity * identity, bool do_keygen,
}
return PEP_STATUS_OK;
}
DYNAMIC_API PEP_STATUS myself(PEP_SESSION session, pEp_identity * identity)


+ 9
- 15
src/message_api.c View File

@ -87,8 +87,6 @@ void add_opt_field(message *msg, const char *name, const char *value)
static char * combine_short_and_long(const char *shortmsg, const char *longmsg)
{
char * ptext;
assert(shortmsg);
assert(strcmp(shortmsg, "pEp") != 0);
@ -111,8 +109,8 @@ static char * combine_short_and_long(const char *shortmsg, const char *longmsg)
const char * const newlines = "\n\n";
const size_t NL_LEN = 2;
size_t bufsize = SUBJ_LEN + strlen(shortmsg) + NL_LEN + strlen(longmsg) + 1;
ptext = calloc(1, bufsize);
const size_t bufsize = SUBJ_LEN + strlen(shortmsg) + NL_LEN + strlen(longmsg) + 1;
char * ptext = calloc(1, bufsize);
assert(ptext);
if (ptext == NULL)
return NULL;
@ -709,14 +707,12 @@ static PEP_rating _rating(PEP_comm_type ct, PEP_rating rating)
static bool is_encrypted_attachment(const bloblist_t *blob)
{
char *ext;
assert(blob);
if (blob == NULL || blob->filename == NULL)
return false;
ext = strrchr(blob->filename, '.');
char *ext = strrchr(blob->filename, '.');
if (ext == NULL)
return false;
@ -944,9 +940,8 @@ bool import_attached_keys(
bool remove = false;
bloblist_t *bl;
int i = 0;
for (bl = msg->attachments; i < MAX_KEYS_TO_IMPORT && bl && bl->value;
for (bloblist_t *bl = msg->attachments; i < MAX_KEYS_TO_IMPORT && bl && bl->value;
bl = bl->next, i++)
{
if (bl && bl->value && bl->size && bl->size < MAX_KEY_SIZE
@ -962,9 +957,8 @@ bool import_attached_keys(
PEP_STATUS _attach_key(PEP_SESSION session, const char* fpr, message *msg)
{
char *keydata;
char *keydata = NULL;
size_t size;
bloblist_t *bl;
PEP_STATUS status = export_key(session, fpr, &keydata, &size);
assert(status == PEP_STATUS_OK);
@ -972,7 +966,7 @@ PEP_STATUS _attach_key(PEP_SESSION session, const char* fpr, message *msg)
return status;
assert(size);
bl = bloblist_add(msg->attachments, keydata, size, "application/pgp-keys",
bloblist_t *bl = bloblist_add(msg->attachments, keydata, size, "application/pgp-keys",
"pEpkey.asc");
if (msg->attachments == NULL && bl)
@ -1467,8 +1461,8 @@ PEP_STATUS combine_keylists(PEP_SESSION session, stringlist_t** verify_in,
stringlist_t* orig_verify = *verify_in;
stringlist_t* verify_curr;
stringlist_t* from_keys;
stringlist_t* verify_curr = NULL;
stringlist_t* from_keys = NULL;
/* FIXME: what to do if head needs to be null */
PEP_STATUS status = find_keys(session, from->address, &from_keys);
@ -1516,7 +1510,7 @@ PEP_STATUS combine_keylists(PEP_SESSION session, stringlist_t** verify_in,
free:
free_stringlist(from_keys);
return status;
return status;
}


+ 5
- 8
src/pEpEngine.c View File

@ -844,9 +844,6 @@ DYNAMIC_API PEP_STATUS trustwords(
)
{
const char *source = fingerprint;
char *buffer;
char *dest;
size_t fsize;
assert(session);
assert(fingerprint);
@ -860,13 +857,13 @@ DYNAMIC_API PEP_STATUS trustwords(
*words = NULL;
*wsize = 0;
buffer = calloc(1, MAX_TRUSTWORDS_SPACE);
char *buffer = calloc(1, MAX_TRUSTWORDS_SPACE);
assert(buffer);
if (buffer == NULL)
return PEP_OUT_OF_MEMORY;
dest = buffer;
char *dest = buffer;
fsize = strlen(fingerprint);
const size_t fsize = strlen(fingerprint);
if (!lang || !lang[0])
lang = "en";
@ -881,8 +878,8 @@ DYNAMIC_API PEP_STATUS trustwords(
while (source < fingerprint + fsize) {
PEP_STATUS _status;
uint16_t value;
char *word;
size_t _wsize;
char *word = NULL;
size_t _wsize = 0;
int j;
for (value=0, j=0; j < 4 && source < fingerprint + fsize; ) {


+ 2
- 5
src/pgp_gpg.c View File

@ -18,13 +18,12 @@ static bool ensure_config_values(stringlist_t *keys, stringlist_t *values, const
{
static char buf[MAX_LINELENGTH];
int r;
FILE *f;
stringlist_t *_k;
stringlist_t *_v;
unsigned int i;
unsigned int found = 0;
f = Fopen(config_file_path, "r");
FILE *f = Fopen(config_file_path, "r");
if (f == NULL && errno == ENOMEM)
return false;
@ -47,9 +46,7 @@ static bool ensure_config_values(stringlist_t *keys, stringlist_t *values, const
}
do {
char * s;
s = Fgets(buf, MAX_LINELENGTH, f);
char * s = Fgets(buf, MAX_LINELENGTH, f);
if (!feof(f)) {
assert(s);
if (s == NULL)


+ 7
- 10
src/pgp_netpgp.c View File

@ -291,16 +291,16 @@ static PEP_STATUS _validation_results(
}
if (vresult->validc && vresult->valid_sigs &&
!vresult->invalidc && !vresult->unknownc ) {
unsigned n;
stringlist_t *k;
// caller responsible to free
*_keylist = new_stringlist(NULL);
assert(*_keylist);
if (*_keylist == NULL) {
return PEP_OUT_OF_MEMORY;
}
k = *_keylist;
for (n = 0; n < vresult->validc; ++n) {
stringlist_t *k = *_keylist;
for (unsigned n = 0; n < vresult->validc; ++n) {
unsigned from = 0;
const pgp_key_t *signer;
char *fprstr = NULL;
@ -353,10 +353,7 @@ PEP_STATUS pgp_decrypt_and_verify(
char **ptext, size_t *psize, stringlist_t **keylist
)
{
pgp_memory_t *mem;
pgp_validation_t *vresult;
char *_ptext = NULL;
size_t _psize = 0;
PEP_STATUS result;
stringlist_t *_keylist = NULL;
@ -379,10 +376,10 @@ PEP_STATUS pgp_decrypt_and_verify(
*psize = 0;
*keylist = NULL;
vresult = malloc(sizeof(pgp_validation_t));
pgp_validation_t *vresult = malloc(sizeof(pgp_validation_t));
memset(vresult, 0x0, sizeof(pgp_validation_t));
mem = pgp_decrypt_and_validate_buf(netpgp.io, vresult, ctext, csize,
pgp_memory_t *mem = pgp_decrypt_and_validate_buf(netpgp.io, vresult, ctext, csize,
netpgp.secring, netpgp.pubring,
_armoured(ctext, csize, ARMOR_HEAD),
0 /* sshkeys */,
@ -392,7 +389,7 @@ PEP_STATUS pgp_decrypt_and_verify(
goto unlock_netpgp;
}
_psize = pgp_mem_len(mem);
const size_t _psize = pgp_mem_len(mem);
if (_psize){
if ((_ptext = malloc(_psize + 1)) == NULL) {
result = PEP_OUT_OF_MEMORY;


+ 1
- 2
src/platform_unix.c View File

@ -321,8 +321,7 @@ static bool ensure_gpg_agent_conf(const char **agent_conf){
if (!ensure_gpg_home(NULL, &dirname)) /* Then dirname won't be set. */
return false;
char *p;
p = stpncpy(agent_path, dirname, MAX_PATH);
char *p = stpncpy(agent_path, dirname, MAX_PATH);
ssize_t len = MAX_PATH - (p - agent_path) - 2;


+ 2
- 5
src/stringlist.c View File

@ -163,13 +163,10 @@ DYNAMIC_API stringlist_t *stringlist_delete(
DYNAMIC_API void free_stringlist(stringlist_t *stringlist)
{
stringlist_t *curr;
stringlist_t *next;
curr = stringlist;
stringlist_t *curr = stringlist;;
while (curr) {
next = curr->next;
stringlist_t *next = curr->next;
free(curr->value);
free(curr);
curr = next;


+ 3
- 6
src/stringpair.c View File

@ -160,8 +160,7 @@ DYNAMIC_API stringpair_list_t *stringpair_list_append(
return stringpair_list;
stringpair_list_t *_s = stringpair_list;
stringpair_list_t *_s2;
for (_s2 = second; _s2 != NULL; _s2 = _s2->next) {
for (stringpair_list_t *_s2 = second; _s2 != NULL; _s2 = _s2->next) {
stringpair_t *_sp = stringpair_dup(_s2->value);
if (_sp == NULL)
return NULL;
@ -180,8 +179,7 @@ DYNAMIC_API int stringpair_list_length(
{
int len = 0;
const stringpair_list_t *_sl;
for (_sl = stringpair_list; _sl && _sl->value; _sl = _sl->next)
for (const stringpair_list_t *_sl = stringpair_list; _sl && _sl->value; _sl = _sl->next)
len++;
return len;
@ -203,8 +201,7 @@ DYNAMIC_API stringpair_list_t *stringpair_list_find(
{
assert(key);
stringpair_list_t *_l;
for (_l = stringpair_list; _l; _l = _l->next) {
for (stringpair_list_t *_l = stringpair_list; _l; _l = _l->next) {
if (strcoll(key, _l->value->key) == 0)
return _l;
}


+ 1
- 1
src/sync_actions.c View File

@ -259,7 +259,7 @@ PEP_STATUS storeGroupKeys(
for (identity_list *il = group_keys; il && il->ident; il = il->next) {
// Check that identity isn't excluded from sync.
pEp_identity *stored_identity;
pEp_identity *stored_identity = NULL;
status = get_identity(session, il->ident->address, PEP_OWN_USERID,
&stored_identity);
if (status == PEP_STATUS_OK) {


Loading…
Cancel
Save