diff --git a/libntfs-3g/index.c b/libntfs-3g/index.c index efe18d89..b28f9496 100644 --- a/libntfs-3g/index.c +++ b/libntfs-3g/index.c @@ -2050,6 +2050,8 @@ static INDEX_ENTRY *ntfs_index_walk_down(INDEX_ENTRY *ie, ictx->ir = (INDEX_ROOT*)NULL; ictx->ib = (INDEX_BLOCK*)ntfs_malloc(ictx->block_size); + if (!ictx->ib) + return NULL; ictx->pindex = 1; ictx->is_in_root = FALSE; } else { diff --git a/libntfs-3g/security.c b/libntfs-3g/security.c index acee0a5e..e60a5b45 100644 --- a/libntfs-3g/security.c +++ b/libntfs-3g/security.c @@ -1646,6 +1646,8 @@ static struct CACHED_PERMISSIONS *enter_cache(struct SECURITY_CONTEXT *scx, cacheblock = (struct CACHED_PERMISSIONS*) malloc(sizeof(struct CACHED_PERMISSIONS) << CACHE_PERMISSIONS_BITS); + if (!cacheblock) + return NULL; pcache->cachetable[index1] = cacheblock; for (i=0; i<(1 << CACHE_PERMISSIONS_BITS); i++) cacheblock[i].valid = 0; diff --git a/ntfsprogs/ntfsrecover.c b/ntfsprogs/ntfsrecover.c index 19366491..aedd89b8 100644 --- a/ntfsprogs/ntfsrecover.c +++ b/ntfsprogs/ntfsrecover.c @@ -301,6 +301,10 @@ struct ATTR *getattrentry(unsigned int key, unsigned int lth) } else { attrtable = (struct ATTR**) malloc(sizeof(struct ATTR*)); + if (!attrtable){ + free(pa); + return NULL; + } attrtable[0] = pa; } pa->key = key; @@ -349,6 +353,8 @@ static const struct BUFFER *read_buffer(CONTEXT *ctx, unsigned int num) if (!buffer) { buffer = (struct BUFFER*) malloc(sizeof(struct BUFFER) + blocksz); + if (!buffer) + return NULL; buffer->size = blocksz; buffer->rnum = num + 1; /* forced to being read */ buffer->safe = FALSE; @@ -2474,6 +2480,8 @@ static u16 overlapshow(CONTEXT *ctx, u16 k, u32 blk, const struct BUFFER *buf, if ((space >= LOG_RECORD_HEAD_SZ) && (size > space)) { fullrec = (char*)malloc(size); + if (!fullrec) + return 0; if (size <= (space + nextspace)) { /* Overlap on two blocks */ memcpy(fullrec,&data[k],space); @@ -3356,6 +3364,8 @@ static TRISTATE backoverlap(CONTEXT *ctx, int blk, && (size > space) && (size < MAXRECSIZE)) { fullrec = (char*)malloc(size); + if (!fullrec) + return T_ERR; memcpy(fullrec,&data[k],space); if (size <= (space + nextspace)) memcpy(&fullrec[space], nextdata + blkheadsz, diff --git a/ntfsprogs/utils.c b/ntfsprogs/utils.c index 31522da3..1c99fb98 100644 --- a/ntfsprogs/utils.c +++ b/ntfsprogs/utils.c @@ -975,6 +975,10 @@ struct mft_search_ctx * mft_get_search_ctx(ntfs_volume *vol) } ctx = (struct mft_search_ctx*)calloc(1, sizeof *ctx); + if(!ctx){ + errno = ENOMEM; + return NULL; + } ctx->mft_num = -1; ctx->vol = vol;