annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
57
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
1 Index: readpst.c
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
2 ===================================================================
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
3 --- readpst.c (revision 45)
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
4 +++ readpst.c (working copy)
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
5 @@ -1396,6 +1396,7 @@
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
6 // char *rfc2426_escape(char *str) {{{1
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
7 char *rfc2426_escape(char *str) {
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
8 static char *buf = NULL;
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
9 + static int buflen = 0;
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
10 char *a, *b;
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
11 int x, y, z;
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
12 DEBUG_ENT("rfc2426_escape");
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
13 @@ -1411,9 +1412,10 @@
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
14 z = chr_count(str, '\r');
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
15 x = strlen(str) + y - z;
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
16
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
17 - if ( (y - z) == 0 ) // resize buffer if needed
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
18 + if ( x + 1 > buflen ) // resize buffer if needed
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
19 {
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
20 buf = (char*) realloc(buf, x + 1); // don't forget room for the NUL
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
21 + buflen = x + 1;
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
22 if ( buf == NULL )
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
23 {
de3753c3160a add archive directory with history of alioth versions that have been merged here
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
24 fprintf(stderr, "Error: rfc2426_escape(): realloc(%d) returned NULL!\n", x + 1);