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
commita5686c55fe54f537315ad4f1515525758e6b9973 (patch)
tree2e035bbc8e30cba85b04590e49a9a0bf1d9f3fe0
parentcc0d1b09bbababddafb8ae26d0446b6d28096217 (diff)
downloadtxr-a5686c55fe54f537315ad4f1515525758e6b9973.tar.gz
txr-a5686c55fe54f537315ad4f1515525758e6b9973.tar.bz2
txr-a5686c55fe54f537315ad4f1515525758e6b9973.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);