diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-11-17 01:18:23 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-11-17 01:18:23 -0800 |
commit | a5686c55fe54f537315ad4f1515525758e6b9973 (patch) | |
tree | 2e035bbc8e30cba85b04590e49a9a0bf1d9f3fe0 | |
parent | cc0d1b09bbababddafb8ae26d0446b6d28096217 (diff) | |
download | txr-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.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -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); |