(vsyslog): calculate length of new format string correctly
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8283 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -44,12 +44,23 @@ RCSID("$Id$");
|
|||||||
|
|
||||||
#include "roken.h"
|
#include "roken.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* the theory behind this is that we might be trying to call vsyslog
|
||||||
|
* when there's no memory left, and we should try to be as useful as
|
||||||
|
* possible. And the format string should say something about what's
|
||||||
|
* failing.
|
||||||
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
simple_vsyslog(int pri, const char *fmt, va_list ap)
|
simple_vsyslog(int pri, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
syslog (pri, "%s", fmt);
|
syslog (pri, "%s", fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* do like syslog but with a `va_list'
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
vsyslog(int pri, const char *fmt, va_list ap)
|
vsyslog(int pri, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
@@ -57,10 +68,11 @@ vsyslog(int pri, const char *fmt, va_list ap)
|
|||||||
const char *p;
|
const char *p;
|
||||||
char *p2;
|
char *p2;
|
||||||
int saved_errno = errno;
|
int saved_errno = errno;
|
||||||
int fmtlen = strlen (fmt);
|
int fmt_len = strlen (fmt);
|
||||||
|
int fmt2_len = fmt_len;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
fmt2 = malloc (fmtlen + 1);
|
fmt2 = malloc (fmt_len + 1);
|
||||||
if (fmt2 == NULL) {
|
if (fmt2 == NULL) {
|
||||||
simple_vsyslog (pri, fmt, ap);
|
simple_vsyslog (pri, fmt, ap);
|
||||||
return;
|
return;
|
||||||
@@ -74,7 +86,8 @@ vsyslog(int pri, const char *fmt, va_list ap)
|
|||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
pos = p2 - fmt2;
|
pos = p2 - fmt2;
|
||||||
tmp = realloc (fmt2, fmtlen + 1 + e_len - 2);
|
fmt2_len += e_len - 2;
|
||||||
|
tmp = realloc (fmt2, fmt2_len + 1);
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
free (fmt2);
|
free (fmt2);
|
||||||
simple_vsyslog (pri, fmt, ap);
|
simple_vsyslog (pri, fmt, ap);
|
||||||
|
Reference in New Issue
Block a user