public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
* gfs2-utils: master - hexedit: avoid NULL dereference upon failed malloc
@ 2009-07-02 11:05 Jim Meyering
  0 siblings, 0 replies; only message in thread
From: Jim Meyering @ 2009-07-02 11:05 UTC (permalink / raw)
  To: cluster-cvs-relay

Gitweb:        http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitdiff;h=3b256287f994e564ec7a6c580003d77029a246bf
Commit:        3b256287f994e564ec7a6c580003d77029a246bf
Parent:        c1309888b4824577cc334f3fcdb2b9bbcbe4a84b
Author:        Jim Meyering <meyering@redhat.com>
AuthorDate:    Wed Jun 17 16:54:03 2009 +0200
Committer:     Jim Meyering <meyering@redhat.com>
CommitterDate: Thu Jul 2 13:04:05 2009 +0200

hexedit: avoid NULL dereference upon failed malloc

* gfs2/edit/hexedit.c (display_indirect): Avoid unchecked malloc
by declaring more_indir on the stack.
---
 gfs2/edit/hexedit.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index f9b9bb4..5c66995 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -1416,13 +1416,12 @@ static int display_indirect(struct iinfo *ind, int indblocks, int level, uint64_
 			file_offset = 0;
 		if (!termlines && ((level + 1 < di.di_height) ||
 				   (S_ISDIR(di.di_mode) && !level))) {
-			struct iinfo *more_indir;
 			int more_ind;
 			char *tmpbuf;
 			
-			more_indir = malloc(sizeof(struct iinfo));
 			tmpbuf = malloc(sbd.bsize);
 			if (tmpbuf) {
+				struct iinfo more_indir;
 				lseek(sbd.device_fd,
 				      ind->ii[pndx].block * sbd.bsize,
 				      SEEK_SET);
@@ -1437,20 +1436,19 @@ static int display_indirect(struct iinfo *ind, int indblocks, int level, uint64_
 						(unsigned long long)ind->ii[pndx].block);
 					exit(-1);
 				}
-				memset(more_indir, 0, sizeof(struct iinfo));
+				memset(&more_indir, 0, sizeof(struct iinfo));
 				if (S_ISDIR(di.di_mode)) {
-					do_leaf_extended(tmpbuf, more_indir);
-					display_leaf(more_indir);
+					do_leaf_extended(tmpbuf, &more_indir);
+					display_leaf(&more_indir);
 				} else {
 					more_ind = do_indirect_extended(tmpbuf,
-									more_indir);
-					display_indirect(more_indir,
+									&more_indir);
+					display_indirect(&more_indir,
 							 more_ind, level + 1,
 							 file_offset);
 				}
 				free(tmpbuf);
 			}
-			free(more_indir);
 		}
 		print_entry_ndx = pndx; /* restore after recursion */
 		eol(0);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-07-02 11:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-02 11:05 gfs2-utils: master - hexedit: avoid NULL dereference upon failed malloc Jim Meyering

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).