Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion sapi/litespeed/lsapi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ static int lsapi_chdir_primary_script( zend_file_handle * file_handle )
getcwd( s_cur_chdir, sizeof( s_cur_chdir ) );

p = strrchr( file_handle->filename, '/' );
if ( *p )
if ( p )
{
*p = 0;
if ( strcmp( file_handle->filename, s_cur_chdir ) != 0 ) {
Expand Down Expand Up @@ -716,6 +716,7 @@ static int parse_opt( int argc, char * argv[], int *climode,
case '?':
if ( *((*(p-1))+2) == 's' )
exit( 99 );
break;
case 'h':
case 'i':
case 'l':
Expand Down
14 changes: 10 additions & 4 deletions sapi/litespeed/lsapilib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1872,10 +1872,12 @@ static char * GetHeaderVar( LSAPI_Request * pReq, const char * name )

char * LSAPI_GetEnv_r( LSAPI_Request * pReq, const char * name )
{
struct LSAPI_key_value_pair * pBegin = pReq->m_pEnvList;
struct LSAPI_key_value_pair * pEnd = pBegin + pReq->m_pHeader->m_cntEnv;
if ( !pReq || !name )
return NULL;

struct LSAPI_key_value_pair * pBegin = pReq->m_pEnvList;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't work for standard C compiler - definitions should come before the code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then should the if(!pReq) code be removed? Because a null pointer dereference will occur before it reachs that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest splitting the definitions and the assignment if you need check before the assignment.

struct LSAPI_key_value_pair * pEnd = pBegin + pReq->m_pHeader->m_cntEnv;

if ( strncmp( name, "HTTP_", 5 ) == 0 )
{
return GetHeaderVar( pReq, name );
Expand Down Expand Up @@ -2282,7 +2284,7 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr )
while( isspace( *pBind ) )
++pBind;

strncpy( achAddr, pBind, 256 );
strncpy( achAddr, pBind, sizeof(pBind) );

switch( *p )
{
Expand Down Expand Up @@ -3112,6 +3114,10 @@ static int lsapi_initSuEXEC()
if ( !s_defaultUid || !s_defaultGid )
{
pw = getpwnam( "nobody" );
if(!pw) {
perror( "Can't get uid for user 'nobody'" );
return -1;
}
if ( !s_defaultUid )
s_defaultUid = pw->pw_uid;
if ( !s_defaultGid )
Expand Down Expand Up @@ -3376,7 +3382,7 @@ void lsapi_MD5Final(unsigned char digest[16], struct lsapi_MD5Context *ctx)
lsapi_MD5Transform(ctx->buf, (uint32 *) ctx->in);
byteReverse((unsigned char *) ctx->buf, 4);
memmove(digest, ctx->buf, 16);
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
}

/* The four core functions - F1 is optimized somewhat */
Expand Down