From 0f0a226ad17a90a214339efc590bfb71b4848a77 Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Sat, 14 Aug 2004 10:49:43 +0000 Subject: [PATCH] tweak error handling when reading the pid file 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 | 2 ++ server/log.c | 5 ++--- server/mpm_common.c | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index e657eb6320..e60d198c10 100644 --- 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 diff --git a/server/log.c b/server/log.c index 16574ab22e..0d6835a47f 100644 --- a/server/log.c +++ b/server/log.c @@ -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); diff --git a/server/mpm_common.c b/server/mpm_common.c index 36d8e6de17..101a0af779 100644 --- a/server/mpm_common.c +++ b/server/mpm_common.c @@ -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; } -- 2.50.1