fsck.gfs2: Plug memory leak in check_system_dir()
PATCH 1/5 fsck.gfs2: Plug memory leak in check_system_dir()
Spotted by coverity: Variable "filename" going out of scope leaks the storage it points to.
--- gfs2/fsck/pass2.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
gfs2/fsck/pass2.c +2 -0
@@ -667,6 +667,7 @@ static int check_system_dir(struct gfs2_inode *sysinode, const char *dirname, filename_len))) {log_err (_ ("Unable to zero name string\n" )); stack; +free (filename);return -1 ; }memcpy (filename, tmp_name, filename_len);
@@ -678,6 +679,7 @@ static int check_system_dir(struct gfs2_inode *sysinode, const char *dirname,if (error) {log_err (_ ("Error adding directory %s: %s\n" ), filename,strerror (errno)); +free (filename);return -errno; }if (cur_blks != sysinode->i_di.di_blocks)
Signature · 1 line
1.7.7.5
PATCH 2/5 fsck.gfs2: Fix null pointer deref in check_system_dir()
Spotted by coverity: Dereferencing null variable "sysinode".
--- gfs2/fsck/pass2.c | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
gfs2/fsck/pass2.c +8 -3
@@ -623,10 +623,15 @@ static int check_system_dir(struct gfs2_inode *sysinode, const char *dirname,log_info (_ ("Checking system directory inode '%s'\n" ), dirname); -if (sysinode) { - iblock = sysinode->i_di.di_num.no_addr; - ds.q =block_type (iblock); +if (!sysinode) { +log_err (_ ("Failed to check '%s': sysinode is null\n" ), dirname); + stack; +return -1 ; } + + iblock = sysinode->i_di.di_num.no_addr; + ds.q =block_type (iblock); + pass2_fxns.private = (void *) &ds;if (ds.q == gfs2_bad_block) {/* First check that the directory's metatree is valid */
Signature · 1 line
1.7.7.5
PATCH 3/5 fsck.gfs2: Plug a leak in find_block_ref()
In reply to Andrew PriceSpotted by coverity: Variable "ip" going out of scope leaks the storage it points to.
--- gfs2/fsck/pass1b.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
gfs2/fsck/pass1b.c +1 -0
@@ -344,6 +344,7 @@ static int find_block_ref(struct gfs2_sbd *sdp, uint64_t inode)log_debug (_ ("Block %lld (0x%llx) is not gfs2 metadata.\n" ), (unsigned long long )inode, (unsigned long long )inode); +fsck_inode_put (&ip);return 1 ; }/* Check to see if this inode was referenced by another by mistake */
Signature · 1 line
1.7.7.5
PATCH 4/5 fsck.gfs2: Remove unused hash.c, hash.h
In reply to Andrew PriceThe functions in hash.c aren't being used so it can be removed.
--- gfs2/fsck/Makefile.am | 4 +- gfs2/fsck/hash.c | 93 ------------------------------------------------ gfs2/fsck/hash.h | 7 ---- gfs2/fsck/inode_hash.c | 1 - gfs2/fsck/metawalk.c | 1 - 5 files changed, 2 insertions(+), 104 deletions(-) delete mode 100644 gfs2/fsck/hash.c delete mode 100644 gfs2/fsck/hash.h
gfs2/fsck/Makefile.am +2 -2
@@ -10,10 +10,10 @@ sbindir := $(shell rpl=0; test '$(exec_prefix):$(sbindir)' = /usr:/usr/sbin \ sbin_PROGRAMS = fsck.gfs2 -noinst_HEADERS = eattr.h fs_bits.h fsck.h fs_recovery.h hash.h \ +noinst_HEADERS = eattr.h fs_bits.h fsck.h fs_recovery.h \ inode_hash.h link.h lost_n_found.h metawalk.h util.h -fsck_gfs2_SOURCES = eattr.c fs_recovery.c hash.c initialize.c \ +fsck_gfs2_SOURCES = eattr.c fs_recovery.c initialize.c \ inode_hash.c link.c lost_n_found.c main.c metawalk.c \ pass1b.c pass1.c pass1c.c pass2.c pass3.c pass4.c \ pass5.c rgrepair.c util.c
gfs2/fsck/hash.c deleted +0 -93
93 lines not on this page · raw message
gfs2/fsck/hash.h deleted +0 -7
@@ -1,7 +0,0 @@ -#ifndef _HASH_H -#define _HASH_H - -uint32_t fsck_hash (const void *data,unsigned int len); -uint32_t fsck_hash_more (const void *data,unsigned int len,uint32_t hash); - -#endif /* _HASH_H */
gfs2/fsck/inode_hash.c +0 -1
@@ -7,7 +7,6 @@#include "libgfs2.h" #include "osi_list.h" -#include "hash.h" #include "inode_hash.h" #include "fsck.h" #define _ (String) gettext(String)
gfs2/fsck/metawalk.c +0 -1
@@ -16,7 +16,6 @@#include "fsck.h" #include "util.h" #include "metawalk.h" -#include "hash.h" #include "inode_hash.h" #define COMFORTABLE_BLKS 5242880/* 20GB in 4K blocks */
Signature · 1 line
1.7.7.5
PATCH 5/5 mkfs.gfs2: Improve error messages
In reply to Andrew PriceCurrently mkfs.gfs2 does not warn that the lock table has been omitted, it just complains about a missing colon in the lock table. It also prefixes error messages with the absolute path of the source file. This patch removes the path from error messages (in mkfs and edit) and adds a check for an empty lock table.
--- gfs2/edit/hexedit.h | 1 - gfs2/mkfs/gfs2_mkfs.h | 1 - gfs2/mkfs/main_mkfs.c | 4 ++++ 3 files changed, 4 insertions(+), 2 deletions(-)
gfs2/edit/hexedit.h +0 -1
@@ -129,7 +129,6 @@ static __inline__ __attribute__((noreturn, format (printf, 1, 2)))void die (const char *fmt, ...) {va_list ap; -fprintf (stderr,"%s: " , __FILE__);va_start (ap, fmt);vfprintf (stderr, fmt, ap);va_end (ap);
gfs2/mkfs/gfs2_mkfs.h +0 -1
@@ -24,7 +24,6 @@ static __inline__ __attribute__((noreturn, format (printf, 1, 2)))void die (const char *fmt, ...) {va_list ap; -fprintf (stderr,"%s: " , __FILE__);va_start (ap, fmt);vfprintf (stderr, fmt, ap);va_end (ap);
gfs2/mkfs/main_mkfs.c +4 -0
@@ -257,6 +257,10 @@ static void test_locking(char *lockproto, char *locktable)/* Nolock is always ok. */ }else if (strcmp (lockproto,"lock_gulm" ) ==0 ||strcmp (lockproto,"lock_dlm" ) ==0 ) { +if (locktable ==NULL || *locktable =='\0' ) { +fprintf (stderr,_ ("No lock table specified.\n" )); +exit (-1 ); + }for (c = locktable; *c; c++) {if (isspace (*c))die (_ ("locktable error: contains space characters\n" ));
Signature · 1 line
1.7.7.5
PATCH 5/5 mkfs.gfs2: Improve error messages
Hi,
Those all look good to me. Thanks,
Steve.
Quoted 52 lines · Andrew Price
Currently mkfs.gfs2 does not warn that the lock table has been omitted, it just complains about a missing colon in the lock table. It also prefixes error messages with the absolute path of the source file. This patch removes the path from error messages (in mkfs and edit) and adds a check for an empty lock table.
Signed-off-by Andrew Price <[email protected]>--- gfs2/edit/hexedit.h | 1 - gfs2/mkfs/gfs2_mkfs.h | 1 - gfs2/mkfs/main_mkfs.c | 4 ++++ 3 files changed, 4 insertions(+), 2 deletions(-)gfs2/edit/hexedit.h +0
-1@@ -129,7 +129,6 @@ static __inline__ __attribute__((noreturn, format (printf, 1, 2)))void die (const char *fmt, ...) {va_list ap; -fprintf (stderr,"%s: " , __FILE__);va_start (ap, fmt);vfprintf (stderr, fmt, ap);va_end (ap);gfs2/mkfs/gfs2_mkfs.h +0
-1@@ -24,7 +24,6 @@ static __inline__ __attribute__((noreturn, format (printf, 1, 2)))void die (const char *fmt, ...) {va_list ap; -fprintf (stderr,"%s: " , __FILE__);va_start (ap, fmt);vfprintf (stderr, fmt, ap);va_end (ap);gfs2/mkfs/main_mkfs.c +4
-0@@ -257,6 +257,10 @@ static void test_locking(char *lockproto, char *locktable)/* Nolock is always ok. */ }else if (strcmp (lockproto,"lock_gulm" ) ==0 ||strcmp (lockproto,"lock_dlm" ) ==0 ) { +if (locktable ==NULL || *locktable =='\0' ) { +fprintf (stderr,_ ("No lock table specified.\n" )); +exit (-1 ); + }for (c = locktable; *c; c++) {if (isspace (*c))die (_ ("locktable error: contains space characters\n" ));