Skip to content

Commit

Permalink
fix another invalid write and huge allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
EricSesterhennX41 committed Feb 13, 2017
1 parent e2d39bd commit 12326ac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/ytnef.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <limits.h>
#include "ytnef.h"
#include "tnef-errors.h"
#include "mapi.h"
Expand Down Expand Up @@ -212,9 +213,13 @@ DDWORD SwapDDWord(BYTE *p, int size) {
}

/* convert 16-bit unicode to UTF8 unicode */
char *to_utf8(int len, char *buf) {
char *to_utf8(size_t len, char *buf) {
int i, j = 0;
/* worst case length */
if (len > 10000) { // deal with this by adding an arbitrary limit
printf("corrupt file\n");
exit(-1);
}
char *utf8 = malloc(3 * len / 2 + 1);

for (i = 0; i < len - 1; i += 2) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ytnef.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ variableLength *MAPIFindProperty(MAPIProps *p, unsigned int ID);
int MAPISysTimetoDTR(BYTE *data, dtr *thedate);
void MAPIPrint(MAPIProps *p);
void TNEFPrintDate(dtr Date);
char *to_utf8(int len, char *buf);
char *to_utf8(size_t len, char *buf);
WORD SwapWord(BYTE *p, int size);
DWORD SwapDWord(BYTE *p, int size);
DDWORD SwapDDWord(BYTE *p, int size);
Expand Down

0 comments on commit 12326ac

Please sign in to comment.