[syslog-ng] [PATCH] logproto: Fix log_proto_file_writer_flush()'s partial construction.

Szalay Attila sasa at balabit.hu
Sat Oct 29 11:01:43 CEST 2011


On Fri, 2011-10-28 at 23:10 +0200, Gergely Nagy wrote:
> After the fix, when the starting position is buffer[i0].length - ofs,
>  we get the correct value of 200, and all is well.
> 
> Reported-by: SZALAY Attila <sasa at balabit.hu>
> Signed-off-by: Gergely Nagy <algernon at balabit.hu>
> ---
>  lib/logproto.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/lib/logproto.c b/lib/logproto.c
> index bdf9695..5047c98 100644
> --- a/lib/logproto.c
> +++ b/lib/logproto.c
> @@ -299,7 +299,7 @@ log_proto_file_writer_flush(LogProto *s)
>        /* allocate and copy the remaning data */
>        self->partial = (guchar *)g_malloc(self->partial_len);
>        ofs = sum - rc; /* the length of the remaning (not processed) chunk in the first message */
> -        memcpy(self->partial, self->buffer[i0].iov_base + rc - (i0 > 0 ? (sum - self->buffer[i0 - 1].iov_len) : 0), ofs);
> +      memcpy(self->partial, self->buffer[i0].iov_len - ofs, ofs);
>        i = i0 + 1;
>        while (i < self->buf_count)
>          {

I think this patch has some problem too.

My advise is th following line:
memcpy(self->partial, self->buffer[i0].iov_base + (self->buffer[i0].iov_len - ofs), ofs);

But I think that the following patch is a bit more readable:


Reported-by: SZALAY Attila <sasa at balabit.hu>
Signed-off-by: SZALAY Attila <sasa at balabit.hu>
diff --git a/lib/logproto.c b/lib/logproto.c
index 9ee6ec5..43f015f 100644
--- a/lib/logproto.c
+++ b/lib/logproto.c
@@ -271,7 +271,7 @@ static LogProtoStatus
 log_proto_file_writer_flush(LogProto *s)
 {
   LogProtoFileWriter *self = (LogProtoFileWriter *)s;
-  gint rc, i, i0, sum, ofs;
+  gint rc, i, i0, sum, ofs, pos;
 
   /* we might be called from log_writer_deinit() without having a buffer at all */
 
@@ -314,7 +314,8 @@ log_proto_file_writer_flush(LogProto *s)
       /* allocate and copy the remaning data */
       self->partial = (guchar *)g_malloc(self->partial_len);
       ofs = sum - rc; /* the length of the remaning (not processed) chunk in the first message */
-        memcpy(self->partial, self->buffer[i0].iov_base + rc - (i0 > 0 ? (sum - self->buffer[i0 - 1].iov_len) : 0), ofs);
+      pos = self->buffer[i0].iov_len - ofs;
+      memcpy(self->partial, self->buffer[i0].iov_base + pos, ofs);
       i = i0 + 1;
       while (i < self->buf_count)
         {


-- 
Attila Szalay
Support (L3) Team Leader

e-mail: attila.szalay at balabit.com
phone: +36 1 398 6707

BalaBit IT Security
www.balabit.com
H-1117 Budapest, Aliz street 2.


This Communication is Confidential. We only send and receive email on
the basis of the term set out at http://www.balabit.com/disclaimer/.




More information about the syslog-ng mailing list