]> granicus.if.org Git - apache/commitdiff
tweak error handling when reading the pid file
authorJeff Trawick <trawick@apache.org>
Sat, 14 Aug 2004 10:49:43 +0000 (10:49 +0000)
committerJeff Trawick <trawick@apache.org>
Sat, 14 Aug 2004 10:49:43 +0000 (10:49 +0000)
previously strtol() would look at unitialized
storage, but now the string is terminated where
the data read ends

give user a hint about removing the file if we can't
read/parse it properly

(somehow I ended up with a truncated httpd.pid on my
own system, leading to these tweaks)

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@104651 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
server/log.c
server/mpm_common.c

diff --git a/CHANGES b/CHANGES
index e657eb6320e0103159f50fc069b1742b30b8526e..e60d198c10779048aaa868d7a84543f1f3ff1a91 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,8 @@ Changes with Apache 2.1.0-dev
 
   [Remove entries to the current 2.0 section below, when backported]
 
+  *) Improve error handling for corrupted pid files.  [Jeff Trawick]
+
   *) mod_proxy.c and proxy_util.c: Enable compiling on 2.0-HEAD 
      (for backwards compatibility):
      Avoids mod_ssl.h (not included in 2.0-HEAD) and
index 16574ab22ef15c589cb463722747fe742eff8101..0d6835a47fa5855180d9f9cd1b83da6fce1b478d 100644 (file)
@@ -672,9 +672,7 @@ AP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename,
         return rv;
     }
 
-    /* Ensure null-termination, so that strtol doesn't go crazy. */
     buf = apr_palloc(p, BUFFER_SIZE);
-    buf[BUFFER_SIZE - 1] = '\0';
 
     rv = apr_file_read_full(pid_file, buf, BUFFER_SIZE - 1, &bytes_read);
     if (rv != APR_SUCCESS && rv != APR_EOF) {
@@ -683,10 +681,11 @@ AP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename,
 
     /* If we fill the buffer, we're probably reading a corrupt pid file.
      * To be nice, let's also ensure the first char is a digit. */
-    if (bytes_read == BUFFER_SIZE - 1 || !apr_isdigit(*buf)) {
+    if (bytes_read == 0 || bytes_read == BUFFER_SIZE - 1 || !apr_isdigit(*buf)) {
         return APR_EGENERAL;
     }
 
+    buf[bytes_read] = '\0';
     *mypid = strtol(buf, &endptr, 10);
 
     apr_file_close(pid_file);
index 36d8e6de1708dabd10ba0432dd73e437d311d776..101a0af7793c5fd89f641c5a45ac42d7cd578817 100644 (file)
@@ -728,6 +728,8 @@ int ap_signal_server(int *exit_status, apr_pool_t *pconf)
         if (rv != APR_ENOENT) {
             ap_log_error(APLOG_MARK, APLOG_STARTUP, rv, NULL,
                          "Error retrieving pid file %s", ap_pid_fname);
+            ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
+                         "Remove it before continuing if it is corrupted.");
             *exit_status = 1;
             return 1;
         }