####################################################################### # Fixes index listings with only LF and no CRs. # dave@dawoodfall.net ####################################################################### diff -Naur a/src/protocol/gopher/gopher.c b/src/protocol/gopher/gopher.c --- a/src/protocol/gopher/gopher.c 2017-12-29 17:14:24.247093626 +0000 +++ b/src/protocol/gopher/gopher.c 2017-12-29 17:12:08.496272595 +0000 @@ -638,15 +638,16 @@ static unsigned char * get_gopher_line_end(unsigned char *data, int datalen) { - for (; datalen > 1; data++, datalen--) - if (data[0] == ASCII_CR && data[1] == ASCII_LF) + for (; datalen > 1; data++, datalen--) { + if (data[0] == ASCII_CR && data[1] == ASCII_LF) return data + 2; else if(data[0] == ASCII_CR) - return data + 2; - else - if(data[0] == ASCII_LF) - return data + 2; + return data + 1; + else + if(data[0] == ASCII_LF) + return data + 1; + } return NULL; } @@ -796,9 +797,21 @@ /* Now read the data from the socket */ switch (gopher->entity->type) { + case GOPHER_INDEX: + /* Lines with no carriage returns */ + if (strchr(rb->data, ASCII_CR) == NULL) { + unsigned char *tmp; + tmp = malloc(rb->length + 3); + memcpy(tmp, "i", 1); + memcpy(tmp+1, rb->data, rb->length); + tmp[rb->length]= '\r'; + tmp[rb->length+1]= '\n'; + rb->length+=3; + memcpy(rb->data, tmp, rb->length); + free(tmp); + } + case GOPHER_DIRECTORY: -/* Don't do directory list for cgi output (7) - case GOPHER_INDEX: */ state = read_gopher_directory_data(conn, rb); break; @@ -810,7 +823,6 @@ state = connection_state(S_GOPHER_CSO_ERROR); break; - case GOPHER_INDEX: case GOPHER_SOUND: case GOPHER_PLUS_SOUND: case GOPHER_PLUS_MOVIE: