Skip to content

Commit f13a88a

Browse files
author
George Wang
committed
Fixed a bug that header value is not terminated by '\0' when accessed through getenv().
1 parent 34d397e commit f13a88a

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

sapi/litespeed/lsapilib.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,10 +1390,12 @@ char * LSAPI_GetHeader_r( LSAPI_Request * pReq, int headerIndex )
13901390
off = pReq->m_pHeaderIndex->m_headerOff[ headerIndex ];
13911391
if ( !off )
13921392
return NULL;
1393-
if ( *(pReq->m_pHttpHeader + off +
1394-
pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) )
1395-
*( pReq->m_pHttpHeader + off +
1396-
pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) = 0;
1393+
if ( *(pReq->m_pHttpHeader + off
1394+
+ pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) )
1395+
{
1396+
*( pReq->m_pHttpHeader + off
1397+
+ pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) = 0;
1398+
}
13971399
return pReq->m_pHttpHeader + off;
13981400
}
13991401

@@ -1830,12 +1832,21 @@ ssize_t LSAPI_Write_Stderr_r( LSAPI_Request * pReq, const char * pBuf, size_t le
18301832
static char * GetHeaderVar( LSAPI_Request * pReq, const char * name )
18311833
{
18321834
int i;
1835+
char * pValue;
18331836
for( i = 0; i < H_TRANSFER_ENCODING; ++i )
18341837
{
18351838
if ( pReq->m_pHeaderIndex->m_headerOff[i] )
18361839
{
18371840
if ( strcmp( name, CGI_HEADERS[i] ) == 0 )
1838-
return pReq->m_pHttpHeader + pReq->m_pHeaderIndex->m_headerOff[i];
1841+
{
1842+
pValue = pReq->m_pHttpHeader
1843+
+ pReq->m_pHeaderIndex->m_headerOff[i];
1844+
if ( *(pValue + pReq->m_pHeaderIndex->m_headerLen[i]) != '\0')
1845+
{
1846+
*(pValue + pReq->m_pHeaderIndex->m_headerLen[i]) = '\0';
1847+
}
1848+
return pValue;
1849+
}
18391850
}
18401851
}
18411852
if ( pReq->m_pHeader->m_cntUnknownHeaders > 0 )
@@ -1862,7 +1873,15 @@ static char * GetHeaderVar( LSAPI_Request * pReq, const char * name )
18621873
++p; ++pKey;
18631874
}
18641875
if (( pKey == pKeyEnd )&& (!*p ))
1865-
return pReq->m_pHttpHeader + pCur->valueOff;
1876+
{
1877+
pValue = pReq->m_pHttpHeader + pCur->valueOff;
1878+
1879+
if ( *(pValue + pCur->valueLen) != '\0')
1880+
{
1881+
*(pValue + pCur->valueLen) = '\0';
1882+
}
1883+
return pValue;
1884+
}
18661885
++pCur;
18671886
}
18681887
}

0 commit comments

Comments
 (0)