• Tales from the crypt(), part 2.

    From Kaz Kylheku@21:1/5 to All on Thu Nov 17 08:45:58 2022
    I'm looking at function stack sizes with the GCC -fstack-usage function.
    In a sea of small stack sizes, I suddenly spot:

    sysif.c:2067:12:crypt_wrap 131280 dynamic,bounded
    ^^^^^^

    Jawdrop; 128K stack frame? Yagoddabekiddingme.

    This is the current version, where I dropped the bullshit validation
    code we discussed to death some weeks ago.

    static val crypt_wrap(val wkey, val wsalt)
    {
    val self = lit("crypt");
    const wchar_t *cwkey = c_str(wkey, self);
    const wchar_t *cwsalt = c_str(wsalt, self);
    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));
    #else
    char *hash = crypt(key, salt);
    #endif

    free(key);
    free(salt);

    if (hash != 0)
    return string_utf8(hash);

    uw_ethrowf(error_s, lit("crypt failed: ~d/~s"), num(errno),
    errno_to_str(errno), nao);
    }

    It has to be the crypt_data structure; and indeed it looks like this:

    struct crypt_data
    {
    char keysched[16 * 8];
    char sb0[32768];
    char sb1[32768];
    char sb2[32768];
    char sb3[32768];
    /* end-of-aligment-critical-data */
    char crypt_3_buf[14];
    char current_salt[2];
    long int current_saltbits;
    int direction, initialized;
    };

    Security through prodigality? :)

    I would have made it sb[4][32768] if there were no way to evade the extravagancy; but I suspect the author reveled also in the importune
    obesity of the declaration.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)