Nageswara R Sastry
2012-Jul-27 10:34 UTC
[PATCH] btrfs-progs: btrfs-image.c: Added NULL pointer check.
Check for the return value of ''open_ctree()'' before dereferencing it. Signed-off-by: Nageswara R Sastry <nasastry@in.ibm.com> --- btrfs-image.c | 1 + 1 file changed, 1 insertion(+) diff --git a/btrfs-image.c b/btrfs-image.c index f2bbcc8..2a33a55 100644 --- a/btrfs-image.c +++ b/btrfs-image.c @@ -491,6 +491,7 @@ static int create_metadump(const char *input, FILE *out, int num_threads, int ret; root = open_ctree(input, 0, 0); + BUG_ON(!root); BUG_ON(root->nodesize != root->leafsize); ret = metadump_init(&metadump, root, out, num_threads, -- 1.7.11.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Stefan Behrens
2012-Jul-27 11:09 UTC
Re: [PATCH] btrfs-progs: btrfs-image.c: Added NULL pointer check.
On Fri, 27 Jul 2012 16:04:14 +0530, Nageswara R Sastry wrote:> Check for the return value of ''open_ctree()'' before dereferencing it. > > Signed-off-by: Nageswara R Sastry <nasastry@in.ibm.com> > --- > btrfs-image.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/btrfs-image.c b/btrfs-image.c > index f2bbcc8..2a33a55 100644 > --- a/btrfs-image.c > +++ b/btrfs-image.c > @@ -491,6 +491,7 @@ static int create_metadump(const char *input, FILE *out, int num_threads, > int ret; > > root = open_ctree(input, 0, 0); > + BUG_ON(!root); > BUG_ON(root->nodesize != root->leafsize); > > ret = metadump_init(&metadump, root, out, num_threads, >In general, explicit BUG_ON() checks for a NULL pointer are not added to the Linux kernel if the pointer is dereferenced afterwards. When the NULL area is accessed, you get a general protection fault including the call trace and a dump of all registers. Adding explicit BUG_ON(ptr !NULL) adds overhead without bringing any additional information. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Stefan Behrens
2012-Jul-27 11:40 UTC
Re: [PATCH] btrfs-progs: btrfs-image.c: Added NULL pointer check.
On Fri, 27 Jul 2012 13:09:53 +0200, Stefan Behrens wrote:> On Fri, 27 Jul 2012 16:04:14 +0530, Nageswara R Sastry wrote: >> Check for the return value of ''open_ctree()'' before dereferencing it. >> >> Signed-off-by: Nageswara R Sastry <nasastry@in.ibm.com> >> --- >> btrfs-image.c | 1 + >> 1 file changed, 1 insertion(+) >> >> diff --git a/btrfs-image.c b/btrfs-image.c >> index f2bbcc8..2a33a55 100644 >> --- a/btrfs-image.c >> +++ b/btrfs-image.c >> @@ -491,6 +491,7 @@ static int create_metadump(const char *input, FILE *out, int num_threads, >> int ret; >> >> root = open_ctree(input, 0, 0); >> + BUG_ON(!root); >> BUG_ON(root->nodesize != root->leafsize); >> >> ret = metadump_init(&metadump, root, out, num_threads, >> > > In general, explicit BUG_ON() checks for a NULL pointer are not added to > the Linux kernel if the pointer is dereferenced afterwards. When the > NULL area is accessed, you get a general protection fault including the > call trace and a dump of all registers. Adding explicit BUG_ON(ptr !> NULL) adds overhead without bringing any additional information.Please ignore and excuse my noise from before. Your patch is for btrfs-progs, not for the kernel. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Maybe Matching Threads
- kernel BUG at fs/btrfs/volumes.c:3707 still not fixed in 3.7.1 (btrfs-zero-log required) but shown as "RIP btrfs_num_copies"
- Off topic: Tcl/Tk outside R.
- [LLVMdev] Status of LLVM's atomic intrinsics
- CAM Target Layer and Linux (continued)
- [LLVMdev] lli -force-interpreter complains about external function