summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-11-17 01:18:23 -0800
committerKaz Kylheku <kaz@kylheku.com>2022-11-17 01:18:23 -0800
commitd4d65c7b85a3f0c7f3fb4adefd20f629368b1e2e (patch)
tree2e035bbc8e30cba85b04590e49a9a0bf1d9f3fe0
parentd659a67d021e9549baf61879469f1ad21591fbbf (diff)
downloadtxr-d4d65c7b85a3f0c7f3fb4adefd20f629368b1e2e.tar.gz
txr-d4d65c7b85a3f0c7f3fb4adefd20f629368b1e2e.tar.bz2
txr-d4d65c7b85a3f0c7f3fb4adefd20f629368b1e2e.zip
crypt: reduce ridiculous stack usage.
* sysif.c (crypt_wrap): Dynamically allocate struct crypt_data instead, because it's over 128K wide, resulting in a huge stack frame size.
-rw-r--r--sysif.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/sysif.c b/sysif.c
index 2043354d..5af269d5 100644
--- a/sysif.c
+++ b/sysif.c
@@ -2072,8 +2072,8 @@ static val crypt_wrap(val wkey, val wsalt)
char *key = utf8_dup_to(cwkey);
char *salt = utf8_dup_to(cwsalt);
#if HAVE_CRYPT_R
- struct crypt_data cd;
- char *hash = (cd.initialized = 0, crypt_r(key, salt, &cd));
+ struct crypt_data *cd = coerce(struct crypt_data *, chk_malloc(sizeof *cd));
+ char *hash = (cd->initialized = 0, crypt_r(key, salt, cd));
#else
char *hash = crypt(key, salt);
#endif
@@ -2081,8 +2081,13 @@ static val crypt_wrap(val wkey, val wsalt)
free(key);
free(salt);
- if (hash != 0)
- return string_utf8(hash);
+ if (hash != 0) {
+ val ret = string_utf8(hash);
+ free(cd);
+ return ret;
+ }
+
+ free(cd);
uw_ethrowf(error_s, lit("crypt failed: ~d/~s"), num(errno),
errno_to_str(errno), nao);