[PATCH] syslog() segv fix under memory shortage
Jakub Jelinek
jakub@redhat.com
Fri Apr 16 03:02:00 GMT 2004
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
More information about the Libc-alpha
mailing list