This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: [PATCH] syslog() segv fix under memory shortage
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Ulrich Drepper <drepper at redhat dot com>, GOTO Masanori <gotom at debian dot or dot jp>
- Cc: libc-alpha at sources dot redhat dot com
- Date: Thu, 15 Apr 2004 17:10:48 +0200
- Subject: Re: [PATCH] syslog() segv fix under memory shortage
- References: <81oepttrwk.wl@omega.webmasters.gr.jp>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Apr 15, 2004 at 08:14:03PM +0900, GOTO Masanori wrote:
> This patch fixes misc/syslog.c:vsyslog() segv. When memory is
> shortage, open_memstream() in vsyslog() can't allocate buffer, and
> then uses local buffer "failbuf". At last in vsyslog(), free() is
> called everytime even for local buffer, then it goes segv. This patch
> adds a flag that indicates the buffer is local or not.
__libc_cleanup_push/pop cannot be used that way.
It would expand to:
if (__builtin_expect(need_free, 1))
do {
magic;
(void)__writev (...);
if (__builtin_expect(need_free, 1))
some_more_magic;
} while (0)
How about this instead:
2004-04-16 Jakub Jelinek <jakub@redhat.com>
* misc/syslog.c (vsyslog): Avoid freeing failbuf.
--- libc/misc/syslog.c.jj 2003-09-25 17:44:37.000000000 +0200
+++ libc/misc/syslog.c 2004-04-15 19:17:21.069878549 +0200
@@ -237,7 +237,7 @@ vsyslog(pri, fmt, ap)
v->iov_len = 1;
}
- __libc_cleanup_push (free, buf);
+ __libc_cleanup_push (free, buf == failbuf ? NULL : buf);
/* writev is a cancellation point. */
(void)__writev(STDERR_FILENO, iov, v - iov + 1);
@@ -305,7 +305,8 @@ vsyslog(pri, fmt, ap)
__libc_cleanup_pop (0);
__libc_lock_unlock (syslog_lock);
- free (buf);
+ if (buf != failbuf)
+ free (buf);
}
libc_hidden_def (vsyslog)
Jakub