Browse code

fix (v)syslog format string problem

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@539 77e5149b-7576-45b1-b177-96237e5ba77b

Tomasz Kojm authored on 2004/05/06 18:38:23
Showing 2 changed files
... ...
@@ -1,3 +1,9 @@
1
+Thu May  6 11:34:40 CEST 2004 (tk)
2
+----------------------------------
3
+  * shared/output: logg: work around a problem with superfluous control
4
+		   characters passed to (v)syslog (reported by
5
+		   Chris Conn <cconn*abacom.com>)
6
+
1 7
 Wed May  5 13:33:12 BST 2004 (trog)
2 8
 -----------------------------------
3 9
   * libclamav/vba_extract.c: Do endian conversion in Word6 macro code.
... ...
@@ -97,12 +97,14 @@ int logg(const char *str, ...)
97 97
 {
98 98
 	va_list args;
99 99
 	struct flock fl;
100
-	char *pt, *timestr;
100
+	char *pt, *timestr, vbuff[1025];
101 101
 	time_t currtime;
102 102
 	struct stat sb;
103 103
 	mode_t old_umask;
104 104
 
105 105
 
106
+    va_start(args, str);
107
+
106 108
     if(logg_file) {
107 109
 #ifdef CL_THREAD_SAFE
108 110
 	pthread_mutex_lock(&logg_mutex);
... ...
@@ -158,20 +160,18 @@ int logg(const char *str, ...)
158 158
 	    }
159 159
 	}
160 160
 
161
-	va_start(args, str);
162 161
 
163 162
 	if(*str == '!') {
164 163
 	    fprintf(logg_fd, "ERROR: ");
165
-	    vfprintf(logg_fd, str+1, args);
164
+	    vfprintf(logg_fd, str + 1, args);
166 165
 	} else if(*str == '^') {
167 166
 	    fprintf(logg_fd, "WARNING: ");
168
-	    vfprintf(logg_fd, str+1, args);
167
+	    vfprintf(logg_fd, str + 1, args);
169 168
 	} else if(*str == '*') {
170 169
 	    if(logg_verbose)
171
-		vfprintf(logg_fd, str+1, args);
170
+		vfprintf(logg_fd, str + 1, args);
172 171
 	} else vfprintf(logg_fd, str, args);
173 172
 
174
-	va_end(args);
175 173
 
176 174
 	fflush(logg_fd);
177 175
 
... ...
@@ -183,32 +183,30 @@ int logg(const char *str, ...)
183 183
 #if defined(USE_SYSLOG) && !defined(C_AIX)
184 184
     if(logg_syslog) {
185 185
 
186
-      /* SYSLOG logging - no need for locking, mutexes, times & stuff ... :-) */
187
-
188
-#ifndef vsyslog
189
-#define vsyslog(a,b,c)	{ \
190
-	char my_tmp[4096]; \
191
-	vsnprintf(my_tmp,4095,b,c); \
192
-	my_tmp[4095]=0; \
193
-	syslog(a,my_tmp); }
194
-#endif
195
-
196
-	va_start(args, str);
197
-
198
-	if(*str == '!') {
199
-	    vsyslog(LOG_ERR, str+1, args);
200
-	} else if(*str == '^') {
201
-	    vsyslog(LOG_WARNING, str+1, args);
202
-	} else if(*str == '*') {
186
+	/* due to a problem with superfluous control characters (which
187
+	 * vsnprintf() handles correctly) in (v)syslog we have to remove
188
+	 * them in a final string
189
+	 */
190
+	vsnprintf(vbuff, 1024, str, args);
191
+	vbuff[1024] = 0;
192
+
193
+	while((pt = strchr(vbuff, '%')))
194
+	    *pt = '_';
195
+
196
+	if(vbuff[0] == '!') {
197
+	    syslog(LOG_ERR, vbuff + 1);
198
+	} else if(vbuff[0] == '^') {
199
+	    syslog(LOG_WARNING, vbuff + 1);
200
+	} else if(vbuff[0] == '*') {
203 201
 	    if(logg_verbose) {
204
-		vsyslog(LOG_DEBUG, str+1, args);
202
+		syslog(LOG_DEBUG, vbuff + 1);
205 203
 	    }
206
-	} else vsyslog(LOG_INFO, str, args);
204
+	} else syslog(LOG_INFO, vbuff);
207 205
 
208
-	va_end(args);
209 206
     }
210 207
 #endif
211 208
 
209
+    va_end(args);
212 210
     return 0;
213 211
 }
214 212