Skip to content

Commit

Permalink
Added checks on all memory allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
oriansj committed Sep 17, 2016
1 parent 03bb733 commit ecadbdd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore the produced binary
cshatag

16 changes: 14 additions & 2 deletions cshatag.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ char * fhash(FILE *f, char *hex)
}

unsigned char * hash;
hash=malloc(HASHLEN);
hash=calloc(1,HASHLEN);
if(NULL == hash)
{
fprintf(stderr, "Insufficient memory for hashing file");
exit(EXIT_FAILURE);
}
SHA256_Final(hash, &c);

//printf("%s\n",bin2hex(hash,HASHLEN));
Expand Down Expand Up @@ -184,7 +189,14 @@ char * formatxa(xa_t s)
char * buf;
char * prettysha;
int buflen=HASHLEN*2+100;
buf=malloc(buflen);
buf=calloc(1,buflen);

if(NULL == buf)
{
fprintf(stderr, "Insufficient space to store hash stringed");
exit(EXIT_FAILURE);
}

if(strlen(s.sha256)>0)
prettysha=s.sha256;
else
Expand Down

0 comments on commit ecadbdd

Please sign in to comment.