title: Valgrind Error: "Invalid read of size 1" due to strstr() with C
body: <p>Valgrind output:</p>
  
  <pre><code>GET /cs3157/tng/index.html
  ==760== Invalid read of size 1
  ==760==    at 0x4C2E7D4: strstr (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==760==    by 0x400E67: HandleTCPClient (http-server.c:101)
  ==760==    by 0x400D42: main (http-server.c:75)
  ==760==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
  </code></pre>
  
  <p>Relevant code:</p>
  
  <pre><code>FILE *input = fdopen(clntSocket, "r");      //socket wrapped with FILE * 
  if (input == NULL)
  {
      perror("fdopen failed");
      fclose(input);
      return;
  }
  char request_buffer[100];
  char out_buf[BUF_SIZE];
  int len, res;
  
  while( fgets(request_buffer, sizeof(request_buffer),input) != NULL)
  {
      request_buffer[sizeof(request_buffer)-1] = '\0';   //null terminates buffer
      char *request = request_buffer;
      char *token_separators = "\t \r\n"; // tab, space, new line
      char *method = strtok(request, token_separators);
      char *requestURI = strtok(NULL, token_separators);
      char *httpVersion = strtok(NULL, token_separators);
  
      if( strstr(method,"GET") != NULL )
      {
              if( requestURI[strlen(requestURI)] == '/' ) 
                      requestURI = strcat(requestURI,"index.html");
              printf("%s %s\n", method, requestURI);
  
      } 
      memset(request_buffer,'\0',sizeof(request_buffer) );
  }
  
  fclose(input);      //close the socket by closing the FILE * wrapper
  </code></pre>
  
  <p>I read that this error is typically caused by failure to null terminate the String. I thought that my first line after fgets() would prevent that from being a problem. I'm guessing I'm overlooking something. I appreciate any help.</p>
  
  <p>edit: Program ends crashes with a segmentation fault. </p>