1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-28 07:21:54 +03:00
samba-mirror/source3/smbd
Jeremy Allison 894358a8f3 r13915: Fixed a very interesting class of realloc() bugs found by Coverity.
realloc can return NULL in one of two cases - (1) the realloc failed,
(2) realloc succeeded but the new size requested was zero, in which
case this is identical to a free() call.

The error paths dealing with these two cases should be different,
but mostly weren't. Secondly the standard idiom for dealing with
realloc when you know the new size is non-zero is the following :

 tmp = realloc(p, size);
 if (!tmp) {
    SAFE_FREE(p);
    return error;
 } else {
    p = tmp;
 }

However, there were *many* *many* places in Samba where we were
using the old (broken) idiom of :

 p = realloc(p, size)
 if (!p) {
    return error;
 }

which will leak the memory pointed to by p on realloc fail.

This commit (hopefully) fixes all these cases by moving to
a standard idiom of :

 p = SMB_REALLOC(p, size)
 if (!p) {
    return error;
 }

Where if the realloc returns null due to the realloc failing
or size == 0 we *guarentee* that the storage pointed to by p
has been freed. This allows me to remove a lot of code that
was dealing with the standard (more verbose) method that required
a tmp pointer. This is almost always what you want. When a
realloc fails you never usually want the old memory, you
want to free it and get into your error processing asap.

For the 11 remaining cases where we really do need to keep the
old pointer I have invented the new macro SMB_REALLOC_KEEP_OLD_ON_ERROR,
which can be used as follows :

 tmp = SMB_REALLOC_KEEP_OLD_ON_ERROR(p, size);
 if (!tmp) {
    SAFE_FREE(p);
    return error;
 } else {
    p = tmp;
 }

SMB_REALLOC_KEEP_OLD_ON_ERROR guarentees never to free the
pointer p, even on size == 0 or realloc fail. All this is
done by a hidden extra argument to Realloc(), BOOL free_old_on_error
which is set appropriately by the SMB_REALLOC and SMB_REALLOC_KEEP_OLD_ON_ERROR
macros (and their array counterparts).

It remains to be seen what this will do to our Coverity bug count :-).

Jeremy.
(This used to be commit 1d710d06a2)
2007-10-10 11:10:59 -05:00
..
aio.c r11283: Move to using sival_int from sival_ptr. Part of bug #2922. 2007-10-10 11:05:10 -05:00
blocking.c r10656: BIG merge from trunk. Features not copied over 2007-10-10 11:04:48 -05:00
change_trust_pw.c r10656: BIG merge from trunk. Features not copied over 2007-10-10 11:04:48 -05:00
chgpasswd.c r13711: * Correctly handle acb_info/acct_flags as uint32 not as uint16. 2007-10-10 11:10:25 -05:00
close.c r13748: Don't reference memory after we just freed it (Doh!). 2007-10-10 11:10:52 -05:00
conn.c r13571: Replace all calls to talloc_free() with thye TALLOC_FREE() 2007-10-10 11:10:14 -05:00
connection.c r10656: BIG merge from trunk. Features not copied over 2007-10-10 11:04:48 -05:00
dfree.c r11190: Fix enhancement request #3192. 2007-10-10 11:05:06 -05:00
dir.c r13293: Rather a big patch I'm afraid, but this should fix bug #3347 2007-10-10 11:06:21 -05:00
dosmode.c r11943: Don't reset attrs to zero in EA get - we are adding 2007-10-10 11:05:38 -05:00
error.c r11137: Compile with only 2 warnings (I'm still working on that code) on a gcc4 2007-10-10 11:05:02 -05:00
fake_file.c r13293: Rather a big patch I'm afraid, but this should fix bug #3347 2007-10-10 11:06:21 -05:00
fileio.c r9985: Move the all the strict sync logic into file_sync(). 2007-10-10 11:03:30 -05:00
filename.c r11945: Make us follow the newly documented pathname processing rules: 2007-10-10 11:05:38 -05:00
files.c r13293: Rather a big patch I'm afraid, but this should fix bug #3347 2007-10-10 11:06:21 -05:00
ipc.c r7882: Looks like a large patch - but what it actually does is make Samba 2007-10-10 10:58:00 -05:00
lanman.c r13915: Fixed a very interesting class of realloc() bugs found by Coverity. 2007-10-10 11:10:59 -05:00
mangle_hash2.c r12522: Try and fix bug #2926 by removing setlocale(LC_ALL, "C") 2007-10-10 11:05:58 -05:00
mangle_hash.c r12522: Try and fix bug #2926 by removing setlocale(LC_ALL, "C") 2007-10-10 11:05:58 -05:00
mangle_map.c Merge from HEAD: 2003-03-17 22:56:13 +00:00
mangle.c r7842: With the patch I sent Steve yesterday this gives us complete POSIX pathnames. 2007-10-10 10:57:59 -05:00
map_username.c r13771: BUG 3534: ignore lines in the username map file with no right hand list rather than bailing out 2007-10-10 11:10:53 -05:00
message.c r12043: It's amazing the warnings you find when compiling on a 64-bit 2007-10-10 11:05:42 -05:00
msdfs.c r13915: Fixed a very interesting class of realloc() bugs found by Coverity. 2007-10-10 11:10:59 -05:00
negprot.c r13647: Fix for standalone Samba servers and XP clients. Reverts 2007-10-10 11:10:21 -05:00
noquotas.c Removed version number from file header. 2002-01-30 06:08:46 +00:00
notify_fam.c r13484: Add missing semi-colon. 2007-10-10 11:10:05 -05:00
notify_hash.c r13482: Push the FAM notification file descriptor into the select 2007-10-10 11:10:05 -05:00
notify_kernel.c r13482: Push the FAM notification file descriptor into the select 2007-10-10 11:10:05 -05:00
notify.c r13482: Push the FAM notification file descriptor into the select 2007-10-10 11:10:05 -05:00
ntquotas.c r13316: Let the carnage begin.... 2007-10-10 11:06:23 -05:00
nttrans.c r13915: Fixed a very interesting class of realloc() bugs found by Coverity. 2007-10-10 11:10:59 -05:00
open.c r13694: Committing patch from Aleksey Fedoseev <aleksey at fedoseev dot net> to NULL 2007-10-10 11:10:24 -05:00
oplock_irix.c r13724: Remove unused variable. Bug #3559 from 2007-10-10 11:10:51 -05:00
oplock_linux.c r12735: After talking to Tridge and Jeremy... This needs to be made more generic 2007-10-10 11:06:02 -05:00
oplock.c r13571: Replace all calls to talloc_free() with thye TALLOC_FREE() 2007-10-10 11:10:14 -05:00
password.c r13915: Fixed a very interesting class of realloc() bugs found by Coverity. 2007-10-10 11:10:59 -05:00
pipes.c r11511: A classic "friday night check-in" :-). This moves much 2007-10-10 11:05:19 -05:00
posix_acls.c r13759: As pointed out by Volker, it isn't much good creating 2007-10-10 11:10:52 -05:00
process.c r13571: Replace all calls to talloc_free() with thye TALLOC_FREE() 2007-10-10 11:10:14 -05:00
quotas.c r12477: Remove a gcc -O6 warning 2007-10-10 11:05:57 -05:00
reply.c r13571: Replace all calls to talloc_free() with thye TALLOC_FREE() 2007-10-10 11:10:14 -05:00
sec_ctx.c r13571: Replace all calls to talloc_free() with thye TALLOC_FREE() 2007-10-10 11:10:14 -05:00
server.c r13571: Replace all calls to talloc_free() with thye TALLOC_FREE() 2007-10-10 11:10:14 -05:00
service.c r13571: Replace all calls to talloc_free() with thye TALLOC_FREE() 2007-10-10 11:10:14 -05:00
session.c r13915: Fixed a very interesting class of realloc() bugs found by Coverity. 2007-10-10 11:10:59 -05:00
sesssetup.c r13604: Fix for bug #3512 "use spnego=no" and "server signing=auto" cause client to disconnect after negprot" 2007-10-10 11:10:19 -05:00
share_access.c r13571: Replace all calls to talloc_free() with thye TALLOC_FREE() 2007-10-10 11:10:14 -05:00
srvstr.c (merge from HEAD) 2003-03-22 13:47:42 +00:00
statcache.c r10186: More 64-bit warning fixes. 2007-10-10 11:03:36 -05:00
statvfs.c r11233: Forgot to add the statvfs file. Oops. 2007-10-10 11:05:08 -05:00
trans2.c r13915: Fixed a very interesting class of realloc() bugs found by Coverity. 2007-10-10 11:10:59 -05:00
uid.c r13571: Replace all calls to talloc_free() with thye TALLOC_FREE() 2007-10-10 11:10:14 -05:00
utmp.c r1325: Always use GetTimeOfDay() (wrapper). Ensure ldap replication 2007-10-10 10:52:06 -05:00
vfs-wrap.c r11232: Added ab's POSIX statvfs vfs call. Sorry for the delay ab. 2007-10-10 11:05:08 -05:00
vfs.c r11428: Fix bug #3192 by actually hooking up the dfree caching 2007-10-10 11:05:15 -05:00