view archive/readpst.c.diff @ 359:a3e674fade6c

From Jeffrey Morlan: pst_parse_block misreads Table Contexts (aka "type 2") with a multi-block Row Matrix ("ind2"). Rows are never split between blocks - every block except the last has padding at the end which should be ignored. I've only seen this affect the recipients table, but presumably it could affect attachments too. This was causing out-of-bounds memory ranges to be returned from pst_getBlockOffset and later access; patch fixes both the table reading issue and adds a missing bounds check to pst_getBlockOffset (so as not to risk a segfault if the PST is corrupted).
author Carl Byington <carl@five-ten-sg.com>
date Wed, 06 Jul 2016 10:20:12 -0700
parents de3753c3160a
children
line wrap: on
line source

Index: readpst.c
===================================================================
--- readpst.c	(revision 45)
+++ readpst.c	(working copy)
@@ -1396,6 +1396,7 @@
 // char *rfc2426_escape(char *str) {{{1
 char *rfc2426_escape(char *str) {
   static char *buf = NULL;
+  static int buflen = 0;
   char *a, *b;
   int x, y, z;
   DEBUG_ENT("rfc2426_escape");
@@ -1411,9 +1412,10 @@
   z = chr_count(str, '\r');
   x = strlen(str) + y - z;
 
-  if ( (y - z) == 0 )	// resize buffer if needed
+  if ( x + 1 > buflen )	// resize buffer if needed
   {
     buf = (char*) realloc(buf, x + 1); // don't forget room for the NUL
+    buflen = x + 1;
 	if ( buf == NULL )
 	{
       fprintf(stderr, "Error: rfc2426_escape(): realloc(%d) returned NULL!\n", x + 1);