Avoid null pointer exception due to NULL return value from strchr.

This fixes #793.
This commit is contained in:
Kevin Backhouse 2019-04-30 11:15:06 +01:00 committed by Luis Díaz Más
parent c79af9f5ad
commit ae20c30805

View File

@ -329,10 +329,14 @@ int Exiv2::http(Exiv2::Dictionary& request,Exiv2::Dictionary& response,std::stri
// search for the body
for ( size_t b = 0 ; bSearching && b < lengthof(blankLines) ; b++ ) {
if ( strstr(buffer,blankLines[b]) ) {
const char* blankLinePos = strstr(buffer,blankLines[b]);
if ( blankLinePos ) {
bSearching = false ;
body = (int) ( strstr(buffer,blankLines[b]) - buffer ) + strlen(blankLines[b]) ;
status = atoi(strchr(buffer,' ')) ;
body = blankLinePos - buffer + strlen(blankLines[b]);
const char* firstSpace = strchr(buffer,' ');
if (firstSpace) {
status = atoi(firstSpace);
}
}
}
@ -342,9 +346,19 @@ int Exiv2::http(Exiv2::Dictionary& request,Exiv2::Dictionary& response,std::stri
char N = '\n';
int i = 0 ; // initial byte in buffer
while(buffer[i] == N ) i++;
h = strchr(h+i,N)+1;
h = strchr(h+i,N);
if (!h) {
status = 0;
break;
}
h++;
response[""]=std::string(buffer+i).substr(0,h-buffer-2);
result = atoi(strchr(buffer,' '));
const char* firstSpace = strchr(buffer,' ');
if ( !firstSpace ) {
status = 0;
break;
}
result = atoi(firstSpace);
char* c = strchr(h,C);
char* first_newline = strchr(h,N);
while ( c && first_newline && c < first_newline && h < buffer+body ) {