Browse code

rfc2426_escape is now thread safe

git-svn: trunk@1966

Nigel Horne authored on 2006/05/13 02:11:28
Showing 1 changed files
... ...
@@ -27,15 +27,13 @@
27 27
  * Notice that this code has yet to be sanitised, and audited. Use at your
28 28
  *	peril
29 29
  * FIXME: lots of memory leaks on error returns
30
- * FIXME: rfc*_datetime_format routines are not thread safe
31
- * FIXME: valgrind has a field day on this code :-(
32 30
  *
33 31
  * TODO: This code works by converting into an mbox - it would be better to
34 32
  *	save the attachments directly rather than encode to base64, then have
35 33
  *	cli_mbox decode it
36 34
  * TODO: Remove the vcard handling
37 35
  */
38
-static	char	const	rcsid[] = "$Id: pst.c,v 1.25 2006/05/08 08:55:13 nigelhorne Exp $";
36
+static	char	const	rcsid[] = "$Id: pst.c,v 1.26 2006/05/12 17:11:28 nigelhorne Exp $";
39 37
 
40 38
 #if HAVE_CONFIG_H
41 39
 #include "clamav-config.h"	/* must come first */
... ...
@@ -445,7 +443,7 @@ static	size_t	_pst_ff_getID2block(pst_file *pf, u_int32_t id2, pst_index2_ll *id
445 445
 static	size_t _pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, struct holder *h);
446 446
 static	size_t _pst_ff_compile_ID(pst_file *pf, u_int32_t id, struct holder *h, int32_t size);
447 447
 
448
-size_t	pst_fwrite(const void*ptr, size_t size, size_t nmemb, FILE*stream);
448
+static	size_t	pst_fwrite(const void*ptr, size_t size, size_t nmemb, FILE*stream);
449 449
 char * _pst_wide_to_single(char *wt, int32_t size);
450 450
 static	unsigned	char	*lzfu_decompress(const unsigned char* rtfcomp, size_t *nbytes);
451 451
 
... ...
@@ -455,7 +453,7 @@ static	const	struct	tm	*fileTimeToStructTM(const FILETIME *filetime);
455 455
 static	int	pst_decode(const char *dir, int desc);
456 456
 static	char	*base64_encode(const unsigned char *data, size_t size);
457 457
 static	int	chr_count(const char *str, char x);
458
-static	const	char	*rfc2426_escape(const char *str);
458
+static	const	char	*rfc2426_escape(const char *str, char **buf);
459 459
 static	size_t	write_email_body(FILE *f, const char *body);
460 460
 static	char	*my_stristr(const char *haystack, const char *needle);
461 461
 
... ...
@@ -1101,7 +1099,7 @@ _pst_build_id_ptr(pst_file *pf, int32_t offset, int32_t depth, int32_t start_val
1101 1101
     }
1102 1102
     if (buf) free (buf);
1103 1103
     return 2;
1104
-  } else {
1104
+  }
1105 1105
     // this is then probably a table of offsets to more tables.
1106 1106
     cli_dbgmsg("Reading Table Items\n");
1107 1107
 
... ...
@@ -1183,10 +1181,6 @@ _pst_build_id_ptr(pst_file *pf, int32_t offset, int32_t depth, int32_t start_val
1183 1183
     if (buf) free (buf);
1184 1184
     cli_dbgmsg("End of table of pointers\n");
1185 1185
     return 3;
1186
-  }
1187
-  cli_dbgmsg("ERROR ** Shouldn't be here!\n");
1188
-
1189
-  return 1;
1190 1186
 }
1191 1187
 
1192 1188
 #define DESC_BLOCK_SIZE 520
... ...
@@ -4514,15 +4508,14 @@ _pst_ff_compile_ID(pst_file *pf, u_int32_t id, struct holder *h, int32_t size)
4514 4514
   return size;
4515 4515
 }
4516 4516
 
4517
-size_t pst_fwrite(const void*ptr, size_t size, size_t nmemb, FILE*stream) {
4518
-  size_t r;
4519
-  if (ptr != NULL)
4520
-    r = fwrite(ptr, size, nmemb, stream);
4521
-  else {
4522
-    r = 0;
4523
-    cli_warnmsg("An attempt to write a NULL Pointer was made\n");
4524
-  }
4525
-  return r;
4517
+static size_t
4518
+pst_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
4519
+{
4520
+	if (ptr == NULL) {
4521
+		cli_warnmsg("An attempt to write a NULL Pointer was made\n");
4522
+		return 0;
4523
+	}
4524
+	return fwrite(ptr, size, nmemb, stream);
4526 4525
 }
4527 4526
 
4528 4527
 char * _pst_wide_to_single(char *wt, int32_t size) {
... ...
@@ -4647,26 +4640,26 @@ chr_count(const char *str, char x)
4647 4647
 }
4648 4648
 
4649 4649
 static const char *
4650
-rfc2426_escape(const char *str)
4650
+rfc2426_escape(const char *str, char **buf)
4651 4651
 {
4652
-	static char* buf = NULL;
4653 4652
 	const char *a;
4654 4653
 	char *b;
4655 4654
 	int x, y, z;
4656 4655
 
4657 4656
 	if(str == NULL)
4658
-		return NULL;
4657
+		return "";
4659 4658
 
4660 4659
 	/* calculate space required to escape all the following characters */
4661 4660
 	x = strlen(str) +(y=(chr_count(str, ',')*2) + (chr_count(str, '\\')*2) + (chr_count(str, ';')*2) + (chr_count(str, '\n')*2));
4662 4661
 	z = chr_count(str, '\r');
4663 4662
 
4664
-	if (y == 0 && z == 0) /* there isn't any extra space required */
4663
+	if (y == 0 && z == 0)
4664
+		/* there isn't any extra space required */
4665 4665
 		return str;
4666 4666
 
4667
-	buf = (char *)cli_realloc(buf, x + 1 - z);
4667
+	*buf = (char *)cli_realloc(*buf, x + 1 - z);
4668 4668
 	a = str;
4669
-	b = buf;
4669
+	b = *buf;
4670 4670
 
4671 4671
 	while(*a != '\0') {
4672 4672
 		switch(*a) {
... ...
@@ -4691,7 +4684,7 @@ rfc2426_escape(const char *str)
4691 4691
 	}
4692 4692
 	*b = '\0';
4693 4693
 
4694
-	return buf;
4694
+	return *buf;
4695 4695
 }
4696 4696
 
4697 4697
 /* my_stristr varies from strstr in that its searches are case-insensitive */
... ...
@@ -4719,21 +4712,21 @@ my_stristr(const char *haystack, const char *needle)
4719 4719
 }
4720 4720
 
4721 4721
 static const char *
4722
-rfc2445_datetime_format(FILETIME *ft)
4722
+rfc2445_datetime_format(FILETIME *ft, char *buffer, size_t len)
4723 4723
 {
4724
-	static char *buffer = NULL;
4725 4724
 	const struct tm *stm = NULL;
4726
-	if (buffer == NULL)
4727
-		buffer = cli_malloc(30); // should be enough
4725
+
4728 4726
 	stm = fileTimeToStructTM(ft);
4729
-	if (strftime(buffer, 30, "%Y%m%dT%H%M%SZ", stm)==0) {
4730
-		cli_dbgmsg("Problem occured formatting date\n");
4727
+	if (strftime(buffer, len, "%Y%m%dT%H%M%SZ", stm)==0) {
4728
+		cli_warnmsg("RFC2445: Problem occured formatting date\n");
4731 4729
 		return NULL;
4732 4730
 	}
4733 4731
 	return buffer;
4734 4732
 }
4735 4733
 
4736
-char *removeCR (char *c) {
4734
+static char *
4735
+removeCR(char *c)
4736
+{
4737 4737
   // converts /r/n to /n
4738 4738
   char *a, *b;
4739 4739
   a = b = c;
... ...
@@ -4792,16 +4785,13 @@ char *skip_header_prologue(char *headers) {
4792 4792
 }
4793 4793
 
4794 4794
 static const char *
4795
-rfc2425_datetime_format(const FILETIME *ft)
4795
+rfc2425_datetime_format(const FILETIME *ft, char *buffer, size_t len)
4796 4796
 {
4797
-	static char *buffer = NULL;
4798 4797
 	const struct tm *stm = NULL;
4799
-	if (buffer == NULL)
4800
-		buffer = cli_malloc(30); // should be enough for the date as defined below
4801 4798
 
4802 4799
 	stm = fileTimeToStructTM(ft);
4803 4800
 	//Year[4]-Month[2]-Day[2] Hour[2]:Min[2]:Sec[2]
4804
-	if(strftime(buffer, 30, "%Y-%m-%dT%H:%M:%SZ", stm) == 0) {
4801
+	if(strftime(buffer, len, "%Y-%m-%dT%H:%M:%SZ", stm) == 0) {
4805 4802
 		cli_errmsg("Problem occured formatting date\n");
4806 4803
 		return NULL;
4807 4804
 	}
... ...
@@ -4931,6 +4921,8 @@ pst_decode(const char *dir, int desc)
4931 4931
 	pst_desc_ll *d_ptr;
4932 4932
 	struct file_ll  *f, *head;
4933 4933
 	char *enc = NULL;	/* base64 encoded attachment */
4934
+	char rfc2445buffer[30], rfc2425buffer[30];
4935
+	char *rfc2426ptr;
4934 4936
 
4935 4937
 	x = pst_open(&pstfile, desc);
4936 4938
 	if(x != CL_SUCCESS)
... ...
@@ -5030,6 +5022,8 @@ pst_decode(const char *dir, int desc)
5030 5030
     }*/
5031 5031
   d_ptr = d_ptr->child; // do the children of TOPF
5032 5032
 
5033
+	rfc2426ptr = NULL;
5034
+
5033 5035
   while (d_ptr != NULL) {
5034 5036
     if (d_ptr->desc == NULL) {
5035 5037
       cli_warnmsg("pst_decode: item's desc record is NULL\n");
... ...
@@ -5078,6 +5072,8 @@ pst_decode(const char *dir, int desc)
5078 5078
 	    sprintf(temp, "%s%08d", f->name, x);
5079 5079
 	    if (x == 99999999) {
5080 5080
 	      cli_errmsg("pst_decode: Why can I not create a folder %s? I have tried %i extensions...\n", f->name, x);
5081
+	      if(rfc2426ptr)
5082
+	      	free(rfc2426ptr);
5081 5083
 	      return(5);
5082 5084
 	    }
5083 5085
 	    fclose(f->output);
... ...
@@ -5095,6 +5091,8 @@ pst_decode(const char *dir, int desc)
5095 5095
 	  if ((f->output = fopen(filename, "w")) == NULL) {
5096 5096
 	    cli_errmsg("pst_decode: Could not open file \"%s\" for write\n", f->name);
5097 5097
 	    free(filename);
5098
+	      if(rfc2426ptr)
5099
+	      	free(rfc2426ptr);
5098 5100
 	    return CL_ETMPFILE;
5099 5101
 	  }
5100 5102
 	    free(filename);
... ...
@@ -5122,115 +5120,115 @@ pst_decode(const char *dir, int desc)
5122 5122
 	// Desc Name <email@address>\n
5123 5123
 	f->email_count++;
5124 5124
 
5125
-	if (item->contact == NULL) { // this is an incorrect situation. Inform user
5126
-	  cli_errmsg("pst_decode: ERROR. This contact has not been fully parsed. one of the pre-requisties is NULL\n");
5127
-	} else {
5128 5125
 	  if (contact_mode == CMODE_VCARD) {
5129 5126
 	    // the specification I am following is (hopefully) RFC2426 vCard Mime Directory Profile
5130 5127
 	    fputs("BEGIN:VCARD\n", f->output);
5131
-	    fprintf(f->output, "FN:%s\n", rfc2426_escape(item->contact->fullname));
5128
+	    fprintf(f->output, "FN:%s\n", rfc2426_escape(item->contact->fullname, &rfc2426ptr));
5129
+	    /*
5130
+	     * FIXME: if more than one string here need to be esacaped,
5131
+	     *	the wrong values will get fprinted
5132
+	     */
5132 5133
 	    fprintf(f->output, "N:%s;%s;%s;%s;%s\n",
5133
-		    rfc2426_escape((item->contact->surname==NULL?"":item->contact->surname)),
5134
-		    rfc2426_escape((item->contact->first_name==NULL?"":item->contact->first_name)),
5135
-		    rfc2426_escape((item->contact->middle_name==NULL?"":item->contact->middle_name)),
5136
-		    rfc2426_escape((item->contact->display_name_prefix==NULL?"":item->contact->display_name_prefix)),
5137
-		    rfc2426_escape((item->contact->suffix==NULL?"":item->contact->suffix)));
5134
+		    rfc2426_escape(item->contact->surname, &rfc2426ptr),
5135
+		    rfc2426_escape(item->contact->first_name, &rfc2426ptr),
5136
+		    rfc2426_escape(item->contact->middle_name, &rfc2426ptr),
5137
+		    rfc2426_escape(item->contact->display_name_prefix, &rfc2426ptr),
5138
+		    rfc2426_escape(item->contact->suffix, &rfc2426ptr));
5138 5139
 	    if (item->contact->nickname != NULL)
5139
-	      fprintf(f->output, "NICKNAME:%s\n", rfc2426_escape(item->contact->nickname));
5140
+	      fprintf(f->output, "NICKNAME:%s\n", rfc2426_escape(item->contact->nickname, &rfc2426ptr));
5140 5141
 	    if (item->contact->address1 != NULL)
5141
-	      fprintf(f->output, "EMAIL:%s\n", rfc2426_escape(item->contact->address1));
5142
+	      fprintf(f->output, "EMAIL:%s\n", rfc2426_escape(item->contact->address1, &rfc2426ptr));
5142 5143
 	    if (item->contact->address2 != NULL)
5143
-	      fprintf(f->output, "EMAIL:%s\n", rfc2426_escape(item->contact->address2));
5144
+	      fprintf(f->output, "EMAIL:%s\n", rfc2426_escape(item->contact->address2, &rfc2426ptr));
5144 5145
 	    if (item->contact->address3 != NULL)
5145
-	      fprintf(f->output, "EMAIL:%s\n", rfc2426_escape(item->contact->address3));
5146
+	      fprintf(f->output, "EMAIL:%s\n", rfc2426_escape(item->contact->address3, &rfc2426ptr));
5146 5147
 	    if (item->contact->birthday != NULL)
5147
-	      fprintf(f->output, "BDAY:%s\n", rfc2425_datetime_format(item->contact->birthday));
5148
+	      fprintf(f->output, "BDAY:%s\n", rfc2425_datetime_format(item->contact->birthday, rfc2425buffer, sizeof(rfc2425buffer)));
5148 5149
 	    if (item->contact->home_address != NULL) {
5149 5150
 	      fprintf(f->output, "ADR;TYPE=home:%s;%s;%s;%s;%s;%s;%s\n",
5150
-		      rfc2426_escape((item->contact->home_po_box!=NULL?item->contact->home_po_box:"")),
5151
+		      rfc2426_escape(item->contact->home_po_box, &rfc2426ptr),
5151 5152
 		      "", // extended Address
5152
-		      rfc2426_escape((item->contact->home_street!=NULL?item->contact->home_street:"")),
5153
-		      rfc2426_escape((item->contact->home_city!=NULL?item->contact->home_city:"")),
5154
-		      rfc2426_escape((item->contact->home_state!=NULL?item->contact->home_state:"")),
5155
-		      rfc2426_escape((item->contact->home_postal_code!=NULL?item->contact->home_postal_code:"")),
5156
-		      rfc2426_escape((item->contact->home_country!=NULL?item->contact->home_country:"")));
5157
-	      fprintf(f->output, "LABEL;TYPE=home:%s\n", rfc2426_escape(item->contact->home_address));
5153
+		      rfc2426_escape(item->contact->home_street, &rfc2426ptr),
5154
+		      rfc2426_escape(item->contact->home_city, &rfc2426ptr),
5155
+		      rfc2426_escape(item->contact->home_state, &rfc2426ptr),
5156
+		      rfc2426_escape(item->contact->home_postal_code, &rfc2426ptr),
5157
+		      rfc2426_escape(item->contact->home_country, &rfc2426ptr));
5158
+	      fprintf(f->output, "LABEL;TYPE=home:%s\n", rfc2426_escape(item->contact->home_address, &rfc2426ptr));
5158 5159
 	    }
5159 5160
 	    if (item->contact->business_address != NULL) {
5160 5161
 	      fprintf(f->output, "ADR;TYPE=work:%s;%s;%s;%s;%s;%s;%s\n",
5161
-		      rfc2426_escape((item->contact->business_po_box!=NULL?item->contact->business_po_box:"")),
5162
+		      rfc2426_escape(item->contact->business_po_box, &rfc2426ptr),
5162 5163
 		      "", // extended Address
5163
-		      rfc2426_escape((item->contact->business_street!=NULL?item->contact->business_street:"")),
5164
-		      rfc2426_escape((item->contact->business_city!=NULL?item->contact->business_city:"")),
5165
-		      rfc2426_escape((item->contact->business_state!=NULL?item->contact->business_state:"")),
5166
-		      rfc2426_escape((item->contact->business_postal_code!=NULL?item->contact->business_postal_code:"")),
5167
-		      rfc2426_escape((item->contact->business_country!=NULL?item->contact->business_country:"")));
5168
-	      fprintf(f->output, "LABEL;TYPE=work:%s\n", rfc2426_escape(item->contact->business_address));
5164
+		      rfc2426_escape(item->contact->business_street, &rfc2426ptr),
5165
+		      rfc2426_escape(item->contact->business_city, &rfc2426ptr),
5166
+		      rfc2426_escape(item->contact->business_state, &rfc2426ptr),
5167
+		      rfc2426_escape(item->contact->business_postal_code, &rfc2426ptr),
5168
+		      rfc2426_escape(item->contact->business_country, &rfc2426ptr));
5169
+	      fprintf(f->output, "LABEL;TYPE=work:%s\n", rfc2426_escape(item->contact->business_address, &rfc2426ptr));
5169 5170
 	    }
5170 5171
 	    if (item->contact->other_address != NULL) {
5171 5172
 	      fprintf(f->output, "ADR;TYPE=postal:%s;%s;%s;%s;%s;%s;%s\n",
5172
-		      rfc2426_escape((item->contact->other_po_box!=NULL?item->contact->business_po_box:"")),
5173
-		      "", // extended Address
5174
-		      rfc2426_escape((item->contact->other_street!=NULL?item->contact->other_street:"")),
5175
-		      rfc2426_escape((item->contact->other_city!=NULL?item->contact->other_city:"")),
5176
-		      rfc2426_escape((item->contact->other_state!=NULL?item->contact->other_state:"")),
5177
-		      rfc2426_escape((item->contact->other_postal_code!=NULL?item->contact->other_postal_code:"")),
5178
-		      rfc2426_escape((item->contact->other_country!=NULL?item->contact->other_country:"")));
5179
-	      fprintf(f->output, "ADR;TYPE=postal:%s\n", rfc2426_escape(item->contact->other_address));
5173
+		      rfc2426_escape(item->contact->business_po_box, &rfc2426ptr),
5174
+		      "", // extended Addres
5175
+		      rfc2426_escape(item->contact->other_street, &rfc2426ptr),
5176
+		      rfc2426_escape(item->contact->other_city, &rfc2426ptr),
5177
+		      rfc2426_escape(item->contact->other_state, &rfc2426ptr),
5178
+		      rfc2426_escape(item->contact->other_postal_code, &rfc2426ptr),
5179
+		      rfc2426_escape(item->contact->other_country, &rfc2426ptr));
5180
+	      fprintf(f->output, "ADR;TYPE=postal:%s\n", rfc2426_escape(item->contact->other_address, &rfc2426ptr));
5180 5181
 	    }
5181 5182
 	    if (item->contact->business_fax != NULL)
5182
-	      fprintf(f->output, "TEL;TYPE=work,fax:%s\n", rfc2426_escape(item->contact->business_fax));
5183
+	      fprintf(f->output, "TEL;TYPE=work,fax:%s\n", rfc2426_escape(item->contact->business_fax, &rfc2426ptr));
5183 5184
 	    if (item->contact->business_phone != NULL)
5184
-	      fprintf(f->output, "TEL;TYPE=work,voice:%s\n", rfc2426_escape(item->contact->business_phone));
5185
+	      fprintf(f->output, "TEL;TYPE=work,voice:%s\n", rfc2426_escape(item->contact->business_phone, &rfc2426ptr));
5185 5186
 	    if (item->contact->business_phone2 != NULL)
5186
-	      fprintf(f->output, "TEL;TYPE=work,voice:%s\n", rfc2426_escape(item->contact->business_phone2));
5187
+	      fprintf(f->output, "TEL;TYPE=work,voice:%s\n", rfc2426_escape(item->contact->business_phone2, &rfc2426ptr));
5187 5188
 	    if (item->contact->car_phone != NULL)
5188
-	      fprintf(f->output, "TEL;TYPE=car,voice:%s\n", rfc2426_escape(item->contact->car_phone));
5189
+	      fprintf(f->output, "TEL;TYPE=car,voice:%s\n", rfc2426_escape(item->contact->car_phone, &rfc2426ptr));
5189 5190
 	    if (item->contact->home_fax != NULL)
5190
-	      fprintf(f->output, "TEL;TYPE=home,fax:%s\n", rfc2426_escape(item->contact->home_fax));
5191
+	      fprintf(f->output, "TEL;TYPE=home,fax:%s\n", rfc2426_escape(item->contact->home_fax, &rfc2426ptr));
5191 5192
 	    if (item->contact->home_phone != NULL)
5192
-	      fprintf(f->output, "TEL;TYPE=home,voice:%s\n", rfc2426_escape(item->contact->home_phone));
5193
+	      fprintf(f->output, "TEL;TYPE=home,voice:%s\n", rfc2426_escape(item->contact->home_phone, &rfc2426ptr));
5193 5194
 	    if (item->contact->home_phone2 != NULL)
5194
-	      fprintf(f->output, "TEL;TYPE=home,voice:%s\n", rfc2426_escape(item->contact->home_phone2));
5195
+	      fprintf(f->output, "TEL;TYPE=home,voice:%s\n", rfc2426_escape(item->contact->home_phone2, &rfc2426ptr));
5195 5196
 	    if (item->contact->isdn_phone != NULL)
5196
-	      fprintf(f->output, "TEL;TYPE=isdn:%s\n", rfc2426_escape(item->contact->isdn_phone));
5197
+	      fprintf(f->output, "TEL;TYPE=isdn:%s\n", rfc2426_escape(item->contact->isdn_phone, &rfc2426ptr));
5197 5198
 	    if (item->contact->mobile_phone != NULL)
5198
-	      fprintf(f->output, "TEL;TYPE=cell,voice:%s\n", rfc2426_escape(item->contact->mobile_phone));
5199
+	      fprintf(f->output, "TEL;TYPE=cell,voice:%s\n", rfc2426_escape(item->contact->mobile_phone, &rfc2426ptr));
5199 5200
 	    if (item->contact->other_phone != NULL)
5200
-	      fprintf(f->output, "TEL;TYPE=msg:%s\n", rfc2426_escape(item->contact->other_phone));
5201
+	      fprintf(f->output, "TEL;TYPE=msg:%s\n", rfc2426_escape(item->contact->other_phone, &rfc2426ptr));
5201 5202
 	    if (item->contact->pager_phone != NULL)
5202
-	      fprintf(f->output, "TEL;TYPE=pager:%s\n", rfc2426_escape(item->contact->pager_phone));
5203
+	      fprintf(f->output, "TEL;TYPE=pager:%s\n", rfc2426_escape(item->contact->pager_phone, &rfc2426ptr));
5203 5204
 	    if (item->contact->primary_fax != NULL)
5204
-	      fprintf(f->output, "TEL;TYPE=fax,pref:%s\n", rfc2426_escape(item->contact->primary_fax));
5205
+	      fprintf(f->output, "TEL;TYPE=fax,pref:%s\n", rfc2426_escape(item->contact->primary_fax, &rfc2426ptr));
5205 5206
 	    if (item->contact->primary_phone != NULL)
5206
-	      fprintf(f->output, "TEL;TYPE=phone,pref:%s\n", rfc2426_escape(item->contact->primary_phone));
5207
+	      fprintf(f->output, "TEL;TYPE=phone,pref:%s\n", rfc2426_escape(item->contact->primary_phone, &rfc2426ptr));
5207 5208
 	    if (item->contact->radio_phone != NULL)
5208
-	      fprintf(f->output, "TEL;TYPE=pcs:%s\n", rfc2426_escape(item->contact->radio_phone));
5209
+	      fprintf(f->output, "TEL;TYPE=pcs:%s\n", rfc2426_escape(item->contact->radio_phone, &rfc2426ptr));
5209 5210
 	    if (item->contact->telex != NULL)
5210
-	      fprintf(f->output, "TEL;TYPE=bbs:%s\n", rfc2426_escape(item->contact->telex));
5211
+	      fprintf(f->output, "TEL;TYPE=bbs:%s\n", rfc2426_escape(item->contact->telex, &rfc2426ptr));
5211 5212
 	    if (item->contact->job_title != NULL)
5212
-	      fprintf(f->output, "TITLE:%s\n", rfc2426_escape(item->contact->job_title));
5213
+	      fprintf(f->output, "TITLE:%s\n", rfc2426_escape(item->contact->job_title, &rfc2426ptr));
5213 5214
 	    if (item->contact->profession != NULL)
5214
-	      fprintf(f->output, "ROLE:%s\n", rfc2426_escape(item->contact->profession));
5215
+	      fprintf(f->output, "ROLE:%s\n", rfc2426_escape(item->contact->profession, &rfc2426ptr));
5215 5216
 	    if (item->contact->assistant_name != NULL || item->contact->assistant_phone != NULL) {
5216 5217
 	      fputs("AGENT:BEGIN:VCARD\n", f->output);
5217 5218
 	      if (item->contact->assistant_name != NULL)
5218
-		fprintf(f->output, "FN:%s\n", rfc2426_escape(item->contact->assistant_name));
5219
+		fprintf(f->output, "FN:%s\n", rfc2426_escape(item->contact->assistant_name, &rfc2426ptr));
5219 5220
 	      if (item->contact->assistant_phone != NULL)
5220
-		fprintf(f->output, "TEL:%s\n", rfc2426_escape(item->contact->assistant_phone));
5221
+		fprintf(f->output, "TEL:%s\n", rfc2426_escape(item->contact->assistant_phone, &rfc2426ptr));
5221 5222
 		fputs("END:VCARD\n\n", f->output);
5222 5223
 	    }
5223 5224
 	    if (item->contact->company_name != NULL)
5224
-	      fprintf(f->output, "ORG:%s\n", rfc2426_escape(item->contact->company_name));
5225
+	      fprintf(f->output, "ORG:%s\n", rfc2426_escape(item->contact->company_name, &rfc2426ptr));
5225 5226
 	    if (item->comment != NULL)
5226
-	      fprintf(f->output, "NOTE:%s\n", rfc2426_escape(item->comment));
5227
+	      fprintf(f->output, "NOTE:%s\n", rfc2426_escape(item->comment, &rfc2426ptr));
5227 5228
 
5228 5229
 	    fputs("VERSION: 3.0\n", f->output);
5229 5230
 	    fputs("END:VCARD\n\n", f->output);
5230 5231
 	  } else {
5231 5232
 	    fprintf(f->output, "%s <%s>\n", item->contact->fullname, item->contact->address1);
5232 5233
 	  }
5233
-	}
5234 5234
 	// }}}2
5235 5235
       } else if (item->email != NULL &&
5236 5236
 		 (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT)) {
... ...
@@ -5505,11 +5503,11 @@ pst_decode(const char *dir, int desc)
5505 5505
 	}*/
5506 5506
 	fputs("BEGIN:VJOURNAL\n", f->output);
5507 5507
 	if (item->email->subject != NULL)
5508
-	  fprintf(f->output, "SUMMARY:%s\n", rfc2426_escape(item->email->subject->subj));
5508
+	  fprintf(f->output, "SUMMARY:%s\n", rfc2426_escape(item->email->subject->subj, &rfc2426ptr));
5509 5509
 	if (item->email->body != NULL)
5510
-	  fprintf(f->output, "DESCRIPTION:%s\n", rfc2426_escape(item->email->body));
5510
+	  fprintf(f->output, "DESCRIPTION:%s\n", rfc2426_escape(item->email->body, &rfc2426ptr));
5511 5511
 	if (item->journal->start != NULL)
5512
-	  fprintf(f->output, "DTSTART;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->journal->start));
5512
+	  fprintf(f->output, "DTSTART;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->journal->start, rfc2445buffer, sizeof(rfc2445buffer)));
5513 5513
 	fputs("END:VJOURNAL\n\n", f->output);
5514 5514
 	// }}}2
5515 5515
       } else if (item->type == PST_TYPE_APPOINTMENT) {
... ...
@@ -5519,19 +5517,19 @@ pst_decode(const char *dir, int desc)
5519 5519
 
5520 5520
 	fputs("BEGIN:VEVENT\n", f->output);
5521 5521
 	if (item->create_date != NULL)
5522
-	  fprintf(f->output, "CREATED:%s\n", rfc2445_datetime_format(item->create_date));
5522
+	  fprintf(f->output, "CREATED:%s\n", rfc2445_datetime_format(item->create_date, rfc2445buffer, sizeof(rfc2445buffer)));
5523 5523
 	if (item->modify_date != NULL)
5524
-	  fprintf(f->output, "LAST-MOD:%s\n", rfc2445_datetime_format(item->modify_date));
5524
+	  fprintf(f->output, "LAST-MOD:%s\n", rfc2445_datetime_format(item->modify_date, rfc2445buffer, sizeof(rfc2445buffer)));
5525 5525
 	if (item->email != NULL && item->email->subject != NULL)
5526
-	  fprintf(f->output, "SUMMARY:%s\n", rfc2426_escape(item->email->subject->subj));
5526
+	  fprintf(f->output, "SUMMARY:%s\n", rfc2426_escape(item->email->subject->subj, &rfc2426ptr));
5527 5527
 	if (item->email != NULL && item->email->body != NULL)
5528
-	  fprintf(f->output, "DESCRIPTION:%s\n", rfc2426_escape(item->email->body));
5528
+	  fprintf(f->output, "DESCRIPTION:%s\n", rfc2426_escape(item->email->body, &rfc2426ptr));
5529 5529
 	if (item->appointment != NULL && item->appointment->start != NULL)
5530
-	  fprintf(f->output, "DTSTART;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->appointment->start));
5530
+	  fprintf(f->output, "DTSTART;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->appointment->start, rfc2445buffer, sizeof(rfc2445buffer)));
5531 5531
 	if (item->appointment != NULL && item->appointment->end != NULL)
5532
-	  fprintf(f->output, "DTEND;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->appointment->end));
5532
+	  fprintf(f->output, "DTEND;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->appointment->end, rfc2445buffer, sizeof(rfc2445buffer)));
5533 5533
 	if (item->appointment != NULL && item->appointment->location != NULL)
5534
-	  fprintf(f->output, "LOCATION:%s\n", rfc2426_escape(item->appointment->location));
5534
+	  fprintf(f->output, "LOCATION:%s\n", rfc2426_escape(item->appointment->location, &rfc2426ptr));
5535 5535
 	if (item->appointment != NULL) {
5536 5536
 	  switch (item->appointment->showas) {
5537 5537
 	  case PST_FREEBUSY_TENTATIVE:
... ...
@@ -5616,6 +5614,9 @@ pst_decode(const char *dir, int desc)
5616 5616
 
5617 5617
   }
5618 5618
 
5619
+      if(rfc2426ptr)
5620
+	free(rfc2426ptr);
5621
+
5619 5622
 	//  fclose(pstfile.fp);
5620 5623
 	while (f != NULL) {
5621 5624
 		if (f->output != NULL)