Fix segfault when logging messages > 1024 characters:
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 13 Jan 2011 14:35:14 +0000 (14:35 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 13 Jan 2011 14:35:14 +0000 (14:35 +0000)
- problem in log4c, workarounded in configuration (needed any non-zero buffer)
- new test added

org.glite.lbjp-common.log/Makefile
org.glite.lbjp-common.log/config/log4crc
org.glite.lbjp-common.log/config/log4crc.debugging
org.glite.lbjp-common.log/tests/log4crc [new file with mode: 0644]
org.glite.lbjp-common.log/tests/test.c [new file with mode: 0644]

index 80846d0..26b420d 100644 (file)
@@ -16,7 +16,7 @@ log4c_prefix=/usr
 version=${module.version}
 
 CC=gcc
-VPATH=${top_srcdir}/interface:${top_srcdir}/src
+VPATH=${top_srcdir}/interface:${top_srcdir}/src:${top_srcdir}/tests
 
 LOG4C_CFLAGS:=-I${log4c_prefix}/include
 LOG4C_LIBS:=-L${log4c_prefix}/${libdir} -L${log4c_prefix}/lib -llog4c
@@ -78,10 +78,14 @@ clean:
        rm -rvf *.o *.lo .libs lib*
        rm -rvf log.xml project/ rpmbuild/ RPMS/ tgz/ debian/
 
-check:
+check: test
+       LOG4C_RCPATH=${top_srcdir}/tests ./test
 
 ${LTLIB}: ${LOBJS}
        ${LINK} ${version_info} -o $@ $+ ${LOG4C_LIBS}
 
+test: test.o
+       ${LINK} -o $@ $+ ${LTLIB} ${LOG4C_LIBS}
+
 %.o %.lo: %.c
        ${COMPILE} -c $<
index bb473b5..f567e20 100644 (file)
@@ -4,7 +4,7 @@
 <log4c version="1.2.1">
 
         <config>
-                <bufsize>0</bufsize>
+                <bufsize>512</bufsize>
                 <debug level="0"/>
                 <nocleanup>0</nocleanup>
         </config>
index 7e21543..3966378 100644 (file)
@@ -4,7 +4,7 @@
 <log4c version="1.2.1">
 
         <config>
-                <bufsize>0</bufsize>
+                <bufsize>512</bufsize>
                 <debug level="0"/>
                 <nocleanup>0</nocleanup>
         </config>
diff --git a/org.glite.lbjp-common.log/tests/log4crc b/org.glite.lbjp-common.log/tests/log4crc
new file mode 100644 (file)
index 0000000..575056f
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE log4c SYSTEM "">
+
+<log4c version="1.2.1">
+       <config>
+               <bufsize>512</bufsize>
+               <debug level="0"/>
+               <nocleanup>0</nocleanup>
+       </config>
+
+       <category name="root" priority="notice"/>
+       <category name="miaow" priority="debug" appender="stderr"/>
+       <appender name="stderr" type="stream" layout="basic"/>
+
+       <layout name="basic" type="basic"/>
+       <layout name="dated" type="dated"/>
+</log4c>
diff --git a/org.glite.lbjp-common.log/tests/test.c b/org.glite.lbjp-common.log/tests/test.c
new file mode 100644 (file)
index 0000000..524cb4e
--- /dev/null
@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "log.h"
+
+int main() {
+       char *line = NULL;
+       size_t i, n;
+       const char *testcat = "miaow";
+
+       n = 10000;
+       line = malloc(n);
+       for (i = 0; i < n; i++) line[i] = (i % 64) ? 'A' : '\n';
+       line[n - 3] = '#';
+       line[n - 2] = '\n';
+       line[n - 1] = '\0';
+       
+
+       if (glite_common_log_init()) {
+               fprintf(stderr,"glite_common_log_init() failed, exiting.");
+               return 2;
+       }
+
+       glite_common_log(testcat, LOG_PRIORITY_ERROR, "%s", line);
+       glite_common_log(testcat, LOG_PRIORITY_DEBUG, "%s", line);
+       printf("%s\n", line);
+
+       glite_common_log_fini();
+
+       free(line);
+       return 0;
+}