summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Fritsch <sf@apache.org>2012-12-25 21:16:17 +0000
committerStefan Fritsch <sf@apache.org>2012-12-25 21:16:17 +0000
commit93d536555aafa741ea22edae473cfb1df7085b01 (patch)
tree1d6437289f173753d0124970185d7e7b3eb0e4dd
parent6a1c04e803ae19c19a82d69ee218e01ca01c7ab9 (diff)
downloadhttpd-93d536555aafa741ea22edae473cfb1df7085b01.tar.gz
htdbm, htpasswd: print error message if out of memory
PR: 54345 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1425775 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--support/htdbm.c1
-rw-r--r--support/htpasswd.c1
-rw-r--r--support/passwd_common.c20
-rw-r--r--support/passwd_common.h6
4 files changed, 28 insertions, 0 deletions
diff --git a/support/htdbm.c b/support/htdbm.c
index a99a232267..1452d7a0eb 100644
--- a/support/htdbm.c
+++ b/support/htdbm.c
@@ -110,6 +110,7 @@ static apr_status_t htdbm_init(apr_pool_t **pool, htdbm_t **hdbm)
#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);
diff --git a/support/htpasswd.c b/support/htpasswd.c
index 51219c0d96..0989fd81b3 100644
--- a/support/htpasswd.c
+++ b/support/htpasswd.c
@@ -274,6 +274,7 @@ int main(int argc, const char * const argv[])
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;
diff --git a/support/passwd_common.c b/support/passwd_common.c
index ab720279c2..7636835902 100644
--- a/support/passwd_common.c
+++ b/support/passwd_common.c
@@ -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 "
diff --git a/support/passwd_common.h b/support/passwd_common.h
index 67b66da161..672ad5c3c7 100644
--- a/support/passwd_common.h
+++ b/support/passwd_common.h
@@ -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
*/