From: Art Cancro Date: Thu, 17 Jan 2008 05:08:46 +0000 (+0000) Subject: dtable/etable initialization code in libcitadel was X-Git-Tag: v7.86~2587 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=df7df08f76c54e628a9bf50a560056a1b0b83d2f dtable/etable initialization code in libcitadel was not complete. CtdlEncodeBase64() still initialized upon each call -- and it was initializing dtable, not etable, causing dtable to have the wrong data the next time CtdlDecodeBase64() is called. Fixed. Also noticed that WebCit was not calling the initialization function at all, so this has probably been broken ever since the move to libcitadel. Fixed this too. --- diff --git a/libcitadel/lib/tools.c b/libcitadel/lib/tools.c index e07b60fee..61e49f0d0 100644 --- a/libcitadel/lib/tools.c +++ b/libcitadel/lib/tools.c @@ -309,18 +309,6 @@ size_t CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen, int li int dpos = 0; int thisline = 0; - /** Fill dtable with character encodings. */ - - for (i = 0; i < 26; i++) { - dtable[i] = 'A' + i; - dtable[26 + i] = 'a' + i; - } - for (i = 0; i < 10; i++) { - dtable[52 + i] = '0' + i; - } - dtable[62] = '+'; - dtable[63] = '/'; - while (!hiteof) { byte igroup[3], ogroup[4]; int c, n; @@ -335,16 +323,16 @@ size_t CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen, int li igroup[n] = (byte) c; } if (n > 0) { - ogroup[0] = dtable[igroup[0] >> 2]; + ogroup[0] = etable[igroup[0] >> 2]; ogroup[1] = - dtable[((igroup[0] & 3) << 4) | + etable[((igroup[0] & 3) << 4) | (igroup[1] >> 4)]; ogroup[2] = - dtable[((igroup[1] & 0xF) << 2) | + etable[((igroup[1] & 0xF) << 2) | (igroup[2] >> 6)]; - ogroup[3] = dtable[igroup[2] & 0x3F]; + ogroup[3] = etable[igroup[2] & 0x3F]; - /** + /* * Replace characters in output stream with "=" pad * characters if fewer than three characters were * read from the end of the input stream. @@ -391,8 +379,6 @@ int CtdlDecodeBase64(char *dest, const char *source, size_t length) int dpos = 0; int spos = 0; - - /*CONSTANTCONDITION*/ while (TRUE) { byte a[4], b[4], o[3]; diff --git a/webcit/webserver.c b/webcit/webserver.c index 22e525849..0b47ce872 100644 --- a/webcit/webserver.c +++ b/webcit/webserver.c @@ -821,7 +821,8 @@ int main(int argc, char **argv) lprintf(9, "Changing directory to %s\n", socket_dir); if (chdir(webcitdir) != 0) { perror("chdir"); - } + } + CtdlInitBase64Table(); initialize_viewdefs(); initialize_axdefs();