You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by jo...@apache.org on 2007/03/07 14:44:16 UTC
svn commit: r515565 - /httpd/httpd/trunk/support/logresolve.c
Author: jorton
Date: Wed Mar 7 05:44:15 2007
New Revision: 515565
URL: http://svn.apache.org/viewvc?view=rev&rev=515565
Log:
* support/logresolve.c (main): Simplify to avoid conditionals in handling
of lines without spaces: ensure a newline is printed for the cache-hit
path and fix a crash in apr_file_printf for the cache-miss path.
Modified:
httpd/httpd/trunk/support/logresolve.c
Modified: httpd/httpd/trunk/support/logresolve.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/logresolve.c?view=diff&rev=515565&r1=515564&r2=515565
==============================================================================
--- httpd/httpd/trunk/support/logresolve.c (original)
+++ httpd/httpd/trunk/support/logresolve.c Wed Mar 7 05:44:15 2007
@@ -205,6 +205,8 @@
cache = apr_hash_make(pool);
while (apr_file_gets(line, 2048, infile) == APR_SUCCESS) {
+ char dummy[] = " " APR_EOL_STR;
+
if (line[0] == '\0') {
continue;
}
@@ -223,13 +225,14 @@
if ((space = strchr(line, ' ')) != NULL) {
*space = '\0';
}
+ else {
+ space = dummy;
+ }
/* See if we have it in our cache */
hostname = (char *) apr_hash_get(cache, line, APR_HASH_KEY_STRING);
if (hostname) {
- apr_file_printf(outfile, "%s", hostname);
- if (space)
- apr_file_printf(outfile, " %s", space + 1);
+ apr_file_printf(outfile, "%s %s", hostname, space + 1);
cachehits++;
continue;
}
@@ -239,7 +242,7 @@
if (status != APR_SUCCESS) {
/* Not an IP address */
withname++;
- if (space) *space = ' ';
+ *space = ' ';
apr_file_puts(line, outfile);
continue;
}
@@ -259,12 +262,12 @@
status = apr_getnameinfo(&hostname, ip, 0) != APR_SUCCESS;
if (status || hostname == NULL) {
/* Could not perform a reverse lookup */
- if (space) *space = ' ';
+ *space = ' ';
apr_file_puts(line, outfile);
noreverse++;
/* Add to cache */
- if (space) *space = '\0';
+ *space = '\0';
apr_hash_set(cache, line, APR_HASH_KEY_STRING,
apr_pstrdup(pool, line));
continue;
@@ -280,12 +283,12 @@
if (status == APR_SUCCESS ||
memcmp(ipdouble->ipaddr_ptr, ip->ipaddr_ptr, ip->ipaddr_len)) {
/* Double-lookup failed */
- if (space) *space = ' ';
+ *space = ' ';
apr_file_puts(line, outfile);
doublefailed++;
/* Add to cache */
- if (space) *space = '\0';
+ *space = '\0';
apr_hash_set(cache, line, APR_HASH_KEY_STRING,
apr_pstrdup(pool, line));
continue;