Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions libfcgi/fcgiapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <memory.h> /* for memchr() */
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
Expand Down Expand Up @@ -1160,6 +1161,7 @@ char *FCGX_GetParam(const char *name, FCGX_ParamArray envp)
static int ReadParams(Params *paramsPtr, FCGX_Stream *stream)
{
int nameLen, valueLen;
size_t totalLen;
unsigned char lenBuff[3];
char *nameValue;

Expand All @@ -1175,7 +1177,7 @@ static int ReadParams(Params *paramsPtr, FCGX_Stream *stream)
}
nameLen = ((nameLen & 0x7f) << 24) + (lenBuff[0] << 16)
+ (lenBuff[1] << 8) + lenBuff[2];
if (nameLen >= INT_MAX) {
if (nameLen >= INT_MAX || nameLen >= SIZE_MAX) {
SetError(stream, FCGX_PARAMS_ERROR);
return -1;
}
Expand All @@ -1191,16 +1193,21 @@ static int ReadParams(Params *paramsPtr, FCGX_Stream *stream)
}
valueLen = ((valueLen & 0x7f) << 24) + (lenBuff[0] << 16)
+ (lenBuff[1] << 8) + lenBuff[2];
if (valueLen >= INT_MAX) {
if (valueLen >= INT_MAX || valueLen >= SIZE_MAX) {
SetError(stream, FCGX_PARAMS_ERROR);
return -1;
}
}
totalLen = (size_t)nameLen + (size_t)valueLen + 2u;
if (totalLen < (size_t)nameLen || totalLen < (size_t)valueLen) {
SetError(stream, FCGX_PARAMS_ERROR);
return -1;
}
/*
* nameLen and valueLen are now valid; read the name and value
* from stream and construct a standard environment entry.
*/
nameValue = (char *)Malloc(nameLen + valueLen + 2);
nameValue = (char *)Malloc(totalLen);
if(FCGX_GetStr(nameValue, nameLen, stream) != nameLen) {
SetError(stream, FCGX_PARAMS_ERROR);
free(nameValue);
Expand Down