Skip to content

Commit

Permalink
WinCon : break large text packets (was more than 512 characters, now …
Browse files Browse the repository at this point in the history
…MAX_PACKET_SIZE = 128 characters) into smaller packets. Avoids an array overflow.
  • Loading branch information
Bill-Gray committed Mar 14, 2021
1 parent c03e650 commit 51327ca
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions wincon/pdcdisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <stdlib.h>
#include <string.h>
#include <assert.h>

#ifdef PDC_WIDE
#define USE_UNICODE_ACS_CHARS 1
Expand Down Expand Up @@ -143,12 +144,23 @@ const chtype MAX_UNICODE = 0x10ffff;
const chtype DUMMY_CHAR_NEXT_TO_FULLWIDTH = 0x110000;
#endif

#define MAX_PACKET_SIZE 128

void _new_packet(attr_t attr, int lineno, int x, int len, const chtype *srcp)
{
int j;
int fore, back;
bool blink, ansi;

assert( len >= 0);
while( len > MAX_PACKET_SIZE)
{
_new_packet( attr, lineno, x, MAX_PACKET_SIZE, srcp);
srcp += MAX_PACKET_SIZE;
x += MAX_PACKET_SIZE;
len -= MAX_PACKET_SIZE;
}

if (pdc_ansi && (lineno == (SP->lines - 1)) && ((x + len) == SP->cols))
{
len--;
Expand Down Expand Up @@ -179,9 +191,9 @@ void _new_packet(attr_t attr, int lineno, int x, int len, const chtype *srcp)
if (ansi)
{
#ifdef PDC_WIDE
WCHAR buffer[512];
WCHAR buffer[MAX_PACKET_SIZE];
#else
char buffer[512];
char buffer[MAX_PACKET_SIZE];
#endif
int n_out;

Expand Down Expand Up @@ -211,7 +223,7 @@ void _new_packet(attr_t attr, int lineno, int x, int len, const chtype *srcp)
}
else
{
CHAR_INFO buffer[512];
CHAR_INFO buffer[MAX_PACKET_SIZE];
COORD bufSize, bufPos;
SMALL_RECT sr;
WORD mapped_attr;
Expand Down

0 comments on commit 51327ca

Please sign in to comment.