[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[hurd] 39/87: libports: avoid realloc(3) corner case
From: |
Samuel Thibault |
Subject: |
[hurd] 39/87: libports: avoid realloc(3) corner case |
Date: |
Sun, 09 Nov 2014 11:05:02 +0000 |
This is an automated email from the git hooks/post-receive script.
sthibault pushed a commit to branch upstream
in repository hurd.
commit 8821d8a213008eb723414c6c70de384830ea10d7
Author: Justus Winter <address@hidden>
Date: Mon Jun 16 17:34:22 2014 +0200
libports: avoid realloc(3) corner case
If the size argument is 0, realloc may either return NULL, or return a
pointer that is only valid for use with free(3). In either case, the
memory is freed. So if realloc would return NULL (it does not on
GNU), the current code would double free p.
Found using the Clang Static Analyzer.
* libports/bucket-iterate.c (_ports_bucket_class_iterate): Avoid
calling realloc if no ports were matched.
---
libports/bucket-iterate.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libports/bucket-iterate.c b/libports/bucket-iterate.c
index babc204..2d1b00d 100644
--- a/libports/bucket-iterate.c
+++ b/libports/bucket-iterate.c
@@ -65,7 +65,7 @@ _ports_bucket_class_iterate (struct port_bucket *bucket,
}
pthread_mutex_unlock (&_ports_lock);
- if (n != nr_items)
+ if (n != 0 && n != nr_items)
{
/* We allocated too much. Release unused memory. */
void **new = realloc (p, n * sizeof *p);
--
Alioth's /usr/local/bin/git-commit-notice on
/srv/git.debian.org/git/pkg-hurd/hurd.git
- [hurd] 28/87: term: improve the demuxer, (continued)
- [hurd] 28/87: term: improve the demuxer, Samuel Thibault, 2014/11/09
- [hurd] 27/87: Add the random translator to prog-subdirs, Samuel Thibault, 2014/11/09
- [hurd] 33/87: Merge procfs into the Hurd repository, Samuel Thibault, 2014/11/09
- [hurd] 34/87: Add the procfs translator to prog-subdirs, Samuel Thibault, 2014/11/09
- [hurd] 36/87: ftpfs: fix error handling in refresh_dir, Samuel Thibault, 2014/11/09
- [hurd] 29/87: hurd: fix receiver lookup in termctty_open_terminal, Samuel Thibault, 2014/11/09
- [hurd] 35/87: Add mach_debug defs rules, Samuel Thibault, 2014/11/09
- [hurd] 37/87: libshouldbeinlibc: fix dead initialization in fmt_named_interval, Samuel Thibault, 2014/11/09
- [hurd] 32/87: Prepare the procfs translator to be merged into the Hurd sources, Samuel Thibault, 2014/11/09
- [hurd] 38/87: trans/fakeroot: fix error handling, Samuel Thibault, 2014/11/09
- [hurd] 39/87: libports: avoid realloc(3) corner case,
Samuel Thibault <=
- [hurd] 40/87: libdiskfs: add permission check to file_chflags, Samuel Thibault, 2014/11/09
- [hurd] 31/87: Merge branch 'merge-random', Samuel Thibault, 2014/11/09
- [hurd] 41/87: libdiskfs: expose the ST_NOATIME flag, Samuel Thibault, 2014/11/09
- [hurd] 43/87: ext2fs: use correct type for block numbers, Samuel Thibault, 2014/11/09
- [hurd] 42/87: libdiskfs: fix deadlock, Samuel Thibault, 2014/11/09
- [hurd] 44/87: libpipe: fix calls to pipe_send with no data, Samuel Thibault, 2014/11/09
- [hurd] 24/87: ext2fs: fix type of retry_dotdot, Samuel Thibault, 2014/11/09
- [hurd] 23/87: ext2fs: fix type of blockaddr, Samuel Thibault, 2014/11/09
- [hurd] 30/87: utils/settrans: implement settrans --start, Samuel Thibault, 2014/11/09
- [hurd] 25/87: Prepare the random translator to be merged into the Hurd sources, Samuel Thibault, 2014/11/09