From 1941e57b6eecfc622ccb0cb9ec085d949a8132df Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Thu, 23 Jan 2003 22:57:16 +0000 Subject: [PATCH] Fixes for memory alloc error in charset functions --- ChangeLog | 4 ++++ TODO | 2 ++ lib/charconv.c | 34 ++++++++++++++++------------------ lib/charset.c | 38 -------------------------------------- mbfido/rfc2ftn.c | 15 ++++++++++----- 5 files changed, 32 insertions(+), 61 deletions(-) diff --git a/ChangeLog b/ChangeLog index bf4bbaaf..ab128ae2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,10 @@ v0.37.01 14-Jan-2003. if you need to downgrade. Spanish templates and macros added to the examples. + common.a: + Remove a bug which very seldom crashed mbfido with charset + translation. Do we really need charset conversion? + mbtask: Arcmail for non-CM nodes and Txx nodes is now sent during the node's opening hours or ZMH. diff --git a/TODO b/TODO index 4342b7b3..df9e8aea 100644 --- a/TODO +++ b/TODO @@ -43,6 +43,8 @@ mbsebbs: N: If a new mailcheck takes longer then the idle timeout, the user is disconnected as soon as the mailcheck is ready. + N: In mail areas for only Alias names, the normal usernames show up. + mbfido: U: Code cleanup and make a structure in this program. Remove duplicate or similar functions. diff --git a/lib/charconv.c b/lib/charconv.c index b860f2e8..9cbd0547 100644 --- a/lib/charconv.c +++ b/lib/charconv.c @@ -139,29 +139,27 @@ char *strnkconv(const char *src, int incode, int outcode, int n) char *strkconv(const char *src, int incode, int outcode) { - static char *dest; + static char *dest; + int bytes = 1; - if ((incode==outcode) && (incode!=CHRS_NOTSET) && (incode!=CHRS_AUTODETECT)) - return (char *)src; + if ((incode==outcode) && (incode!=CHRS_NOTSET) && (incode!=CHRS_AUTODETECT)) + return (char *)src; - if (!src) - return NULL; + if (!src) + return NULL; - if((incode == CHRS_AUTODETECT) || (incode == CHRS_NOTSET)) { - if (LANG_BITS == 16) { - incode = iso2022_detectcode((char *)src,incode); - } + if((incode == CHRS_AUTODETECT) || (incode == CHRS_NOTSET)) { + if (LANG_BITS == 16) { + bytes = 2; + incode = iso2022_detectcode((char *)src,incode); } + } - if(dest) - free(dest); - /* FIXME: should be - * dest = (char *)malloc((strlen(src) + 1) + (6 * "number of \n + 1")); - */ - dest = (char *)malloc(((strlen(src) + 1) * 2) + 6 ); - - kconv((char *)src, &dest, incode, outcode); - return dest; + if(dest) + free(dest); + dest = (char *)malloc((strlen(src) + 1) + ((6 * bytes) + 1)); + kconv((char *)src, &dest, incode, outcode); + return dest; } diff --git a/lib/charset.c b/lib/charset.c index 2a57e0fc..224a737e 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -386,41 +386,3 @@ void writechrs(int code, FILE *pkt, int ispkt) } -// WORDT NIET GEBRUIKT ?? -void writecharset(int code, FILE *pip, rfcmsg *msg, rfcmsg *kmsg) -{ - char *p, *charset=NULL; - - charset=getcharset(code); - - if ((p=hdr((char *)"Mime-Version",msg))) fprintf(pip,(char *)"Mime-Version:%s",p); - else if ((p=hdr((char *)"RFC-Mime-Version",kmsg))) fprintf(pip,(char *)"Mime-Version: %s",p); - else if ((p=hdr((char *)"Mime-Version",kmsg))) fprintf(pip,(char *)"Mime-Version: %s",p); - else if ((charset) && (code != CHRS_NOTSET)) fprintf(pip,"Mime-Version: 1.0\n"); - - if ((p=hdr((char *)"Content-Type",msg))) fprintf(pip,"Content-Type:%s",p); - else if ((p=hdr((char *)"RFC-Content-Type",kmsg))) fprintf(pip,"Content-Type: %s",p); - else if ((p=hdr((char *)"Content-Type",kmsg))) fprintf(pip,"Content-Type: %s",p); - else if ((charset) && (code != CHRS_NOTSET)) - { - if ((p=hdr((char *)"FSCHTML",kmsg)) || (p=hdr((char *)"HTML",kmsg))) - fprintf(pip,"Content-Type: text/html; charset=%s\n",charset); - else - fprintf(pip,"Content-Type: text/plain; charset=%s\n",charset); - } - - if ((p=hdr((char *)"Content-Length",msg))) fprintf(pip,"Content-Length%s",p); - else if ((p=hdr((char *)"RFC-Content-Length",kmsg))) fprintf(pip,"Content-Length: %s",p); - else if ((p=hdr((char *)"Content-Length",kmsg))) fprintf(pip,"Content-Length: %s",p); - - if ((p=hdr((char *)"Content-Transfer-Encoding",msg))) fprintf(pip,"Content-Transfer-Encoding:%s",p); - else if ((p=hdr((char *)"RFC-Content-Transfer-Encoding",kmsg))) fprintf(pip,"Content-Transfer-Encoding: %s",p); - else if ((p=hdr((char *)"Content-Transfer-Encoding",kmsg))) fprintf(pip,"Content-Transfer-Encoding: %s",p); - else if ((charset) && (code == CHRS_ISO_8859_1_QP)) fprintf(pip,"Content-Transfer-Encoding: quoted-printable\n"); - else if ((charset) && (code != CHRS_NOTSET)) { fprintf(pip,"Content-Transfer-Encoding: "); - if ((code == CHRS_ASCII || code == CHRS_UTF_7)) fprintf(pip,"7bit\n"); - else if (strncasecmp(charset,"iso-2022-",9) == 0) fprintf(pip,"7bit\n"); - else fprintf(pip,"8bit\n"); /* all others are 8 bit */ - } -} - diff --git a/mbfido/rfc2ftn.c b/mbfido/rfc2ftn.c index 14aa6783..63d577cb 100644 --- a/mbfido/rfc2ftn.c +++ b/mbfido/rfc2ftn.c @@ -500,11 +500,13 @@ int rfc2ftn(FILE *fp, faddr *recipient) } } - hdrsize += 8 + strlen(getchrs(outcode)); - fprintf(ofp, "\001CHRS: %s\n", getchrs(outcode)); - if (html_message) { - hdrsize += 9; - fprintf(ofp, "\1HTML: 5\n"); + if (getchrs(outcode) != NULL) { + hdrsize += 8 + strlen(getchrs(outcode)); + fprintf(ofp, "\001CHRS: %s\n", getchrs(outcode)); + if (html_message) { + hdrsize += 9; + fprintf(ofp, "\1HTML: 5\n"); + } } if (CFG.allowcontrol && (!hdr((char *)"X-FTN-ACUPDATE",msg)) && (p=hdr((char *)"Control",msg))) { @@ -531,6 +533,7 @@ int rfc2ftn(FILE *fp, faddr *recipient) fprintf(ofp, "\1TID:"); kludgewrite(temp, ofp); } + if ((splitpart == 0) || (hdrsize < MAXHDRSIZE)) { for (tmp = msg; tmp; tmp = tmp->next) { if ((!strncmp(tmp->key,"X-Fsc-",6)) || (!strncmp(tmp->key,"X-FTN-",6) && @@ -573,6 +576,7 @@ int rfc2ftn(FILE *fp, faddr *recipient) } } } + /* ZConnect are X-ZC-*: in usenet, \1ZC-*: in FTN */ for (tmp=msg;tmp;tmp=tmp->next) if ((!strncmp(tmp->key,"X-ZC-",5))) { @@ -625,6 +629,7 @@ int rfc2ftn(FILE *fp, faddr *recipient) charwrite(hdrconv(tmp->val, incode, outcode),ofp); } } + if (rfcheaders) charwrite((char *)"\n",ofp); if ((hdr((char *)"X-FTN-SOT",msg)) || (sot_kludge))