httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r1425775 - in /httpd/httpd/trunk/support: htdbm.c htpasswd.c passwd_common.c passwd_common.h
Date Tue, 25 Dec 2012 21:16:17 GMT
Author: sf
Date: Tue Dec 25 21:16:17 2012
New Revision: 1425775

URL: http://svn.apache.org/viewvc?rev=1425775&view=rev
Log:
htdbm, htpasswd: print error message if out of memory

PR: 54345

Modified:
    httpd/httpd/trunk/support/htdbm.c
    httpd/httpd/trunk/support/htpasswd.c
    httpd/httpd/trunk/support/passwd_common.c
    httpd/httpd/trunk/support/passwd_common.h

Modified: httpd/httpd/trunk/support/htdbm.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/htdbm.c?rev=1425775&r1=1425774&r2=1425775&view=diff
==============================================================================
--- httpd/httpd/trunk/support/htdbm.c (original)
+++ httpd/httpd/trunk/support/htdbm.c Tue Dec 25 21:16:17 2012
@@ -110,6 +110,7 @@ static apr_status_t htdbm_init(apr_pool_
 #endif
 
     apr_pool_create( pool, NULL);
+    apr_pool_abort_set(abort_on_oom, *pool);
     apr_file_open_stderr(&errfile, *pool);
     apr_signal(SIGINT, (void (*)(int)) htdbm_interrupted);
 

Modified: httpd/httpd/trunk/support/htpasswd.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/htpasswd.c?rev=1425775&r1=1425774&r2=1425775&view=diff
==============================================================================
--- httpd/httpd/trunk/support/htpasswd.c (original)
+++ httpd/httpd/trunk/support/htpasswd.c Tue Dec 25 21:16:17 2012
@@ -274,6 +274,7 @@ int main(int argc, const char * const ar
     apr_app_initialize(&argc, &argv, NULL);
     atexit(terminate);
     apr_pool_create(&pool, NULL);
+    apr_pool_abort_set(abort_on_oom, pool);
     apr_file_open_stderr(&errfile, pool);
     ctx.pool = pool;
     ctx.alg = ALG_APMD5;

Modified: httpd/httpd/trunk/support/passwd_common.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/passwd_common.c?rev=1425775&r1=1425774&r2=1425775&view=diff
==============================================================================
--- httpd/httpd/trunk/support/passwd_common.c (original)
+++ httpd/httpd/trunk/support/passwd_common.c Tue Dec 25 21:16:17 2012
@@ -46,6 +46,24 @@
 
 apr_file_t *errfile;
 
+int abort_on_oom(int rc)
+{
+    const char *buf = "Error: out of memory\n";
+    int written, count = strlen(buf);
+    do {
+        written = write(STDERR_FILENO, buf, count);
+        if (written == count)
+            break;
+        if (written > 0) {
+            buf += written;
+            count -= written;
+        }
+    } while (written >= 0 || errno == EINTR);
+    abort();
+    /* NOTREACHED */
+    return 0;
+}
+
 static int generate_salt(char *s, size_t size, const char **errstr,
                          apr_pool_t *pool)
 {
@@ -207,6 +225,8 @@ int mkhash(struct passwd_ctx *ctx)
         apr_cpystrn(ctx->out, cbuf, ctx->out_len - 1);
         if (strlen(pw) > 8) {
             char *truncpw = strdup(pw);
+            if (truncpw == NULL)
+                abort_on_oom(0);
             truncpw[8] = '\0';
             if (!strcmp(ctx->out, crypt(truncpw, salt))) {
                 apr_file_printf(errfile, "Warning: Password truncated to 8 "

Modified: httpd/httpd/trunk/support/passwd_common.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/passwd_common.h?rev=1425775&r1=1425774&r2=1425775&view=diff
==============================================================================
--- httpd/httpd/trunk/support/passwd_common.h (original)
+++ httpd/httpd/trunk/support/passwd_common.h Tue Dec 25 21:16:17 2012
@@ -84,6 +84,12 @@ struct passwd_ctx {
     } passwd_src;
 };
 
+
+/*
+ * To be used as apr_pool_abort_fn
+ */
+int abort_on_oom(int rc);
+
 /*
  * Write a line to the file. On error, print a message and exit
  */



Mime
View raw message