Package: sarg
Version: 2.2.2-1

when running sarg with "show_read_statistics no" in sarg.conf it
failed with error Segmentation fault.

i build sarg with -ggdb and run it in gdb, and this is backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000405015 in compar (a=0x18, b=0x5374cc) at util.c:1119
1119    { if( *(int *)a > *(int *)b ) return 1;
(gdb) backtrace
#0  0x0000000000405015 in compar (a=0x18, b=0x5374cc) at util.c:1119
#1  0x00002b57b9785ace in bsearch () from /lib/libc.so.6
#2  0x0000000000408a52 in main (argc=9, argv=0x7ffff146bd98) at log.c:799

strace show interesting info:

open("/tmp/head", O_RDONLY)             = 3
...
read(3, "1190518343.459    193 172.29.6.9"..., 4096) = 4096
lseek(3, 0, SEEK_SET)                   = 0
...
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=815, ...}) = 0
...
stat("/etc/localtime", {st_mode=S_IFREG|0644, st_size=815, ...}) = 0
read(3, "1190518343.459    193 172.29.6.9"..., 4096) = 4096
--- SIGSEGV (Segmentation fault) @ 0 (0) ---

Did you see that read() reading the same data? This is because lseek()
used at log.c:736 change offset in file descriptor(!) not offset in
fp_in stream. So after reading 4096 bytes fgets() will started from
begining of file. This damage arguments of  bsearch() and result to a
sigsegv.
Setting "show_read_statistics yes" prevent sigsegv, because at
log.c:769 called rewind(fp_in) - this reopen fp_in and update library
buffers.

Simple patch - use fseek() instead of lseek():

--- sarg_2.2.2.orig/log.c
+++ sarg_2.2.2/log.c
@@ -733,7 +733,7 @@
       getword(val3,arqtt,'_');
       sprintf(period,"%s-%s",val2,val3);
       sarglog=1;
-   } else lseek(fileno(fp_in), 0, 0);
+   } else fseek(fp_in, 0, 0);

    if(strcmp(ParsedOutputLog, "no") != 0 && !sarglog) {
       if(access(ParsedOutputLog,R_OK) != 0) {



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to