lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1182175456.13184.7.camel@kleikamp.austin.ibm.com>
Date:	Mon, 18 Jun 2007 09:04:16 -0500
From:	Dave Kleikamp <shaggy@...ux.vnet.ibm.com>
To:	Jim Meyering <jim@...ering.net>
Cc:	linux-ext4@...r.kernel.org
Subject: Re: avoid leak upon failed realloc

On Sat, 2007-06-16 at 19:31 +0200, Jim Meyering wrote:
> Here's a tiny fix to avoid a leak when realloc fails:
> 
> 2007-06-16  Jim Meyering  <jim@...ering.net>
> 
> 	* tdb.c (tdb_append): Don't leak a buffer when realloc fails.
> 
> diff -r 777972a573b3 lib/ext2fs/tdb.c
> --- a/lib/ext2fs/tdb.c	Fri Jun 15 18:05:09 2007 +0200
> +++ b/lib/ext2fs/tdb.c	Sat Jun 16 19:28:50 2007 +0200
> @@ -3460,8 +3460,15 @@ int tdb_append(struct tdb_context *tdb,
>  	if (dbuf.dptr == NULL) {
>  		dbuf.dptr = (unsigned char *)malloc(new_dbuf.dsize);
>  	} else {
> -		dbuf.dptr = (unsigned char *)realloc(dbuf.dptr,
> -						     dbuf.dsize + new_dbuf.dsize);
> +		unsigned char *new_dptr
> +		  = (unsigned char *)realloc(dbuf.dptr,
> +					     dbuf.dsize + new_dbuf.dsize);
> +		if (new_dptr == NULL) {
> +			free(dbuf.dptr);
> +			dbuf.dptr = NULL;
> +		} else {
> +			dbuf.dptr = new_dptr;
> +		}

Not a big deal, but this part could be simplified to:

		if (new_dptr == NULL)
			free(dbuf.dptr);
		dbuf.dptr = new_dptr;

>  	}
> 
>  	if (dbuf.dptr == NULL) {
> 
> Signed-off-by: Jim Meyering <jim@...ering.net>
-- 
David Kleikamp
IBM Linux Technology Center

-
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ