$Log$
+ Revision 580.92 2001/12/04 05:16:19 ajc
+ * mime_parser.c: change to memory allocation algorithm ... some badly done
+ messages were crashing the server
+
Revision 580.91 2001/12/03 22:48:16 ajc
* ooops. Look for the QR2_SYSTEM flag in QRflags2, not QRflags.
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
+
fp = fopen(pwfile, "r");
if (fp == NULL) return;
while (fgets(buf64, sizeof buf64, fp) != NULL) {
- decode_base64(buf, buf64);
+ decode_base64(buf, buf64, sizeof(buf64));
extract(hostbuf, buf, 0);
extract(portbuf, buf, 1);
extract(ubuf, buf, 2);
fp = fopen(pwfile, "w");
if (fp == NULL) fp = fopen("/dev/null", "w");
while (fgets(buf64, sizeof buf64, oldfp) != NULL) {
- decode_base64(buf, buf64);
+ decode_base64(buf, buf64, sizeof(buf64));
extract(hostbuf, buf, 0);
extract(portbuf, buf, 1);
extract(ubuf, buf, 2);
}
return;
}
+
if ((strcasecmp(encoding, "base64"))
&& (strcasecmp(encoding, "quoted-printable"))) {
lprintf(9, "ERROR: unknown MIME encoding '%s'\n", encoding);
* Allocate a buffer for the decoded data. The output buffer is the
* same size as the input buffer; this assumes that the decoded data
* will never be larger than the encoded data. This is a safe
- * assumption with base64, uuencode, and quoted-printable. Just to
- * be safe, we still pad the buffer a bit.
+ * assumption with base64, uuencode, and quoted-printable.
*/
- decoded = mallok(length + 1024);
+ lprintf(9, "About to allocate %d bytes for decoded part\n",
+ length+2048);
+ decoded = mallok(length+2048);
if (decoded == NULL) {
lprintf(9, "ERROR: cannot allocate memory.\n");
return;
}
+ lprintf(9, "Got it!\n");
+ lprintf(9, "Decoding %s\n", encoding);
if (!strcasecmp(encoding, "base64")) {
- bytes_decoded = decode_base64(decoded, part_start);
+ bytes_decoded = decode_base64(decoded, part_start, length);
}
else if (!strcasecmp(encoding, "quoted-printable")) {
bytes_decoded = decode_quoted_printable(decoded,
part_start, length);
}
+ lprintf(9, "Bytes decoded: %d\n", bytes_decoded);
if (bytes_decoded > 0) if (CallBack != NULL) {
CallBack(name, filename, fixed_partnum(partnum),
void imap_auth_login_user(char *cmd) {
char buf[SIZ];
- decode_base64(buf, cmd);
+ decode_base64(buf, cmd, SIZ);
CtdlLoginExistingUser(buf);
encode_base64(buf, "Password:");
cprintf("+ %s\r\n", buf);
void imap_auth_login_pass(char *cmd) {
char buf[SIZ];
- decode_base64(buf, cmd);
+ decode_base64(buf, cmd, SIZ);
if (CtdlTryPassword(buf) == pass_ok) {
cprintf("%s OK authentication succeeded\r\n", IMAP->authseq);
}
char buf[SIZ];
char username[SIZ];
- decode_base64(username, argbuf);
+ decode_base64(username, argbuf, SIZ);
lprintf(9, "Trying <%s>\n", username);
if (CtdlLoginExistingUser(username) == login_ok) {
encode_base64(buf, "Password:");
void smtp_get_pass(char *argbuf) {
char password[SIZ];
- decode_base64(password, argbuf);
+ decode_base64(password, argbuf, SIZ);
lprintf(9, "Trying <%s>\n", password);
if (CtdlTryPassword(password) == pass_ok) {
cprintf("235 Authentication successful.\r\n");
/* Uncomment this if you want to track memory leaks.
* This incurs some overhead, so don't use it unless you're debugging the code!
*/
-#define DEBUG_MEMORY_LEAKS
+/* #define DEBUG_MEMORY_LEAKS */
/*
* New format for a message in memory
/*
* Convert base64-encoded to binary. Returns the length of the decoded data.
+ * It will stop after reading 'length' bytes.
*/
-int decode_base64(char *dest, char *source)
+int decode_base64(char *dest, char *source, size_t length)
{
- int i;
+ int i, c;
int dpos = 0;
int spos = 0;
byte a[4], b[4], o[3];
for (i = 0; i < 4; i++) {
- int c = source[spos++];
+ if (spos >= length) {
+ return(dpos);
+ }
+ c = source[spos++];
if (c == 0) {
if (i > 0) {
int extract_int (char *source, int parmnum);
long int extract_long (char *source, long int parmnum);
void encode_base64(char *dest, char *source);
-int decode_base64(char *dest, char *source);
+int decode_base64(char *dest, char *source, size_t length);
void striplt(char *);
int haschar(char *st, int ch);
int collapsed_strcmp(char *s1, char *s2);