You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by mi...@apache.org on 2013/11/17 21:10:28 UTC
svn commit: r1542803 - in /httpd/httpd/branches/2.4.x: CHANGES STATUS
include/ap_slotmem.h modules/slotmem/mod_slotmem_shm.c
Author: minfrin
Date: Sun Nov 17 20:10:28 2013
New Revision: 1542803
URL: http://svn.apache.org/r1542803
Log:
slotmem_shm: Error detection
trunk patch: https://svn.apache.org/viewvc?view=revision&revision=1540161
https://svn.apache.org/viewvc?view=revision&revision=1540163
https://svn.apache.org/viewvc?view=revision&revision=1540178
https://svn.apache.org/viewvc?view=revision&revision=1540179
https://svn.apache.org/viewvc?view=revision&revision=1540220
http://svn.apache.org/viewvc?view=revision&revision=r1542413
2.4.x patch: http://people.apache.org/~jim/patches/slotmem-error2.patch
Submitted by: jim
Reviewed by: jorton, minfrin
Modified:
httpd/httpd/branches/2.4.x/CHANGES
httpd/httpd/branches/2.4.x/STATUS
httpd/httpd/branches/2.4.x/include/ap_slotmem.h
httpd/httpd/branches/2.4.x/modules/slotmem/mod_slotmem_shm.c
Modified: httpd/httpd/branches/2.4.x/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/CHANGES?rev=1542803&r1=1542802&r2=1542803&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/CHANGES [utf-8] (original)
+++ httpd/httpd/branches/2.4.x/CHANGES [utf-8] Sun Nov 17 20:10:28 2013
@@ -2,6 +2,8 @@
Changes with Apache 2.4.7
+ *) slotmem_shm: Error detection. [Jim Jagielski]
+
*) event: Use skiplist data structure (requires APR 1.5).
[Jim Jagielski]
Modified: httpd/httpd/branches/2.4.x/STATUS
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/STATUS?rev=1542803&r1=1542802&r2=1542803&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/STATUS (original)
+++ httpd/httpd/branches/2.4.x/STATUS Sun Nov 17 20:10:28 2013
@@ -97,15 +97,6 @@ RELEASE SHOWSTOPPERS:
PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
[ start all new proposals below, under PATCHES PROPOSED. ]
- * slotmem_shm: Error detection
- trunk patch: https://svn.apache.org/viewvc?view=revision&revision=1540161
- https://svn.apache.org/viewvc?view=revision&revision=1540163
- https://svn.apache.org/viewvc?view=revision&revision=1540178
- https://svn.apache.org/viewvc?view=revision&revision=1540179
- https://svn.apache.org/viewvc?view=revision&revision=1540220
- http://svn.apache.org/viewvc?view=revision&revision=r1542413
- 2.4.x patch: http://people.apache.org/~jim/patches/slotmem-error2.patch
- +1: jim, jorton, minfrin
PATCHES PROPOSED TO BACKPORT FROM TRUNK:
Modified: httpd/httpd/branches/2.4.x/include/ap_slotmem.h
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/include/ap_slotmem.h?rev=1542803&r1=1542802&r2=1542803&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/include/ap_slotmem.h (original)
+++ httpd/httpd/branches/2.4.x/include/ap_slotmem.h Sun Nov 17 20:10:28 2013
@@ -39,6 +39,7 @@
#include "apr_shm.h"
#include "apr_global_mutex.h"
#include "apr_file_io.h"
+#include "apr_md5.h"
#if APR_HAVE_UNISTD_H
#include <unistd.h> /* for getpid() */
Modified: httpd/httpd/branches/2.4.x/modules/slotmem/mod_slotmem_shm.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/slotmem/mod_slotmem_shm.c?rev=1542803&r1=1542802&r2=1542803&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/slotmem/mod_slotmem_shm.c (original)
+++ httpd/httpd/branches/2.4.x/modules/slotmem/mod_slotmem_shm.c Sun Nov 17 20:10:28 2013
@@ -178,6 +178,7 @@ static void store_slotmem(ap_slotmem_ins
apr_status_t rv;
apr_size_t nbytes;
const char *storename;
+ unsigned char digest[APR_MD5_DIGESTSIZE];
storename = slotmem_filename(slotmem->gpool, slotmem->name, 1);
@@ -200,20 +201,27 @@ static void store_slotmem(ap_slotmem_ins
}
nbytes = (slotmem->desc.size * slotmem->desc.num) +
(slotmem->desc.num * sizeof(char)) + AP_UNSIGNEDINT_OFFSET;
- /* XXX: Error handling */
- apr_file_write_full(fp, slotmem->persist, nbytes, NULL);
+ apr_md5(digest, slotmem->persist, nbytes);
+ rv = apr_file_write_full(fp, slotmem->persist, nbytes, NULL);
+ if (rv == APR_SUCCESS) {
+ rv = apr_file_write_full(fp, digest, APR_MD5_DIGESTSIZE, NULL);
+ }
apr_file_close(fp);
+ if (rv != APR_SUCCESS) {
+ apr_file_remove(storename, slotmem->gpool);
+ }
}
}
-/* should be apr_status_t really */
-static void restore_slotmem(void *ptr, const char *name, apr_size_t size,
- apr_pool_t *pool)
+static apr_status_t restore_slotmem(void *ptr, const char *name, apr_size_t size,
+ apr_pool_t *pool)
{
const char *storename;
apr_file_t *fp;
apr_size_t nbytes = size;
- apr_status_t rv;
+ apr_status_t rv = APR_SUCCESS;
+ unsigned char digest[APR_MD5_DIGESTSIZE];
+ unsigned char digest2[APR_MD5_DIGESTSIZE];
storename = slotmem_filename(pool, name, 1);
@@ -224,20 +232,42 @@ static void restore_slotmem(void *ptr, c
rv = apr_file_open(&fp, storename, APR_READ | APR_WRITE, APR_OS_DEFAULT,
pool);
if (rv == APR_SUCCESS) {
- apr_finfo_t fi;
- if (apr_file_info_get(&fi, APR_FINFO_SIZE, fp) == APR_SUCCESS) {
- if (fi.size == nbytes) {
- apr_file_read(fp, ptr, &nbytes);
+ rv = apr_file_read(fp, ptr, &nbytes);
+ if ((rv == APR_SUCCESS || rv == APR_EOF) && nbytes == size) {
+ rv = APR_SUCCESS; /* for successful return @ EOF */
+ /*
+ * if at EOF, don't bother checking md5
+ * - backwards compatibility
+ * */
+ if (apr_file_eof(fp) != APR_EOF) {
+ apr_size_t ds = APR_MD5_DIGESTSIZE;
+ rv = apr_file_read(fp, digest, &ds);
+ if ((rv == APR_SUCCESS || rv == APR_EOF) &&
+ ds == APR_MD5_DIGESTSIZE) {
+ rv = APR_SUCCESS;
+ apr_md5(digest2, ptr, nbytes);
+ if (memcmp(digest, digest2, APR_MD5_DIGESTSIZE)) {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
+ APLOGNO(02551) "bad md5 match");
+ rv = APR_EGENERAL;
+ }
+ }
}
else {
- apr_file_close(fp);
- apr_file_remove(storename, pool);
- return;
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
+ APLOGNO(02552) "at EOF... bypassing md5 match check (old persist file?)");
}
}
+ else if (nbytes != size) {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
+ APLOGNO(02553) "Expected %" APR_SIZE_T_FMT ": Read %" APR_SIZE_T_FMT,
+ size, nbytes);
+ rv = APR_EGENERAL;
+ }
apr_file_close(fp);
}
}
+ return rv;
}
static apr_status_t cleanup_slotmem(void *param)
@@ -395,8 +425,16 @@ static apr_status_t slotmem_create(ap_sl
* sense if the restore fails? Any?
*/
if (type & AP_SLOTMEM_TYPE_PERSIST) {
- restore_slotmem(ptr, fname, dsize, pool);
- restored = 1;
+ rv = restore_slotmem(ptr, fname, dsize, pool);
+ if (rv == APR_SUCCESS) {
+ restored = 1;
+ }
+ else {
+ /* just in case, re-zero */
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
+ APLOGNO(02554) "could not restore %s", fname);
+ memset(ptr, 0, dsize);
+ }
}
}