summaryrefslogtreecommitdiffstats
path: root/support
diff options
context:
space:
mode:
Diffstat (limited to 'support')
-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
*/