Skip to content

Commit

Permalink
Add check on frame size
Browse files Browse the repository at this point in the history
  • Loading branch information
sorz committed May 8, 2017
1 parent e65fa6f commit 261f2f0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions sstpd/codecmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static u16 fcstab[256] = {
#define FLAG_SEQUENCE 0x7e
#define CONTROL_ESCAPE 0x7d

#define MAX_FRAME_SIZE 2048

static inline void
escape_to(unsigned char byte, unsigned char* out, int* pos)
Expand Down Expand Up @@ -126,8 +127,10 @@ PppDecoder_unescape(PppDecoder *self, PyObject *args)
return NULL;

frames = PyList_New(0);
if (!frames)
if (!frames) {
PyBuffer_Release(&buf_in);
return NULL;
}

data = (char*) buf_in.buf;
for (i=0; i<buf_in.len; ++i) {
Expand All @@ -153,7 +156,7 @@ PppDecoder_unescape(PppDecoder *self, PyObject *args)
}
self->frame_buf_pos = 0;
}
else {
else if (self->frame_buf_pos < MAX_FRAME_SIZE) {
self->frame_buf[self->frame_buf_pos++] = data[i];
}
}
Expand All @@ -175,7 +178,7 @@ PppDecoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PppDecoder *self;
self = (PppDecoder *)type->tp_alloc(type, 0);
if (self != NULL) {
self->frame_buf = malloc(sizeof(char[1502]));
self->frame_buf = malloc(sizeof(char[MAX_FRAME_SIZE]));
if (!self->frame_buf) {
Py_DECREF(self);
return PyErr_NoMemory();
Expand Down

0 comments on commit 261f2f0

Please sign in to comment.