diff options
author | Stefan Fritsch <sf@apache.org> | 2012-12-25 21:16:17 +0000 |
---|---|---|
committer | Stefan Fritsch <sf@apache.org> | 2012-12-25 21:16:17 +0000 |
commit | 93d536555aafa741ea22edae473cfb1df7085b01 (patch) | |
tree | 1d6437289f173753d0124970185d7e7b3eb0e4dd /support/passwd_common.c | |
parent | 6a1c04e803ae19c19a82d69ee218e01ca01c7ab9 (diff) | |
download | httpd-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
Diffstat (limited to 'support/passwd_common.c')
-rw-r--r-- | support/passwd_common.c | 20 |
1 files changed, 20 insertions, 0 deletions
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 " |