Skip to content

Commit ecadbdd

Browse files
committed
Added checks on all memory allocations
1 parent 03bb733 commit ecadbdd

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ignore the produced binary
2+
cshatag
3+

cshatag.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ char * fhash(FILE *f, char *hex)
7474
}
7575

7676
unsigned char * hash;
77-
hash=malloc(HASHLEN);
77+
hash=calloc(1,HASHLEN);
78+
if(NULL == hash)
79+
{
80+
fprintf(stderr, "Insufficient memory for hashing file");
81+
exit(EXIT_FAILURE);
82+
}
7883
SHA256_Final(hash, &c);
7984

8085
//printf("%s\n",bin2hex(hash,HASHLEN));
@@ -184,7 +189,14 @@ char * formatxa(xa_t s)
184189
char * buf;
185190
char * prettysha;
186191
int buflen=HASHLEN*2+100;
187-
buf=malloc(buflen);
192+
buf=calloc(1,buflen);
193+
194+
if(NULL == buf)
195+
{
196+
fprintf(stderr, "Insufficient space to store hash stringed");
197+
exit(EXIT_FAILURE);
198+
}
199+
188200
if(strlen(s.sha256)>0)
189201
prettysha=s.sha256;
190202
else

0 commit comments

Comments
 (0)