0

I am attempting to create an SSL server with Polarssl. The program compiles and runs, however I encounter a segfault upon connecting to the server from a browser. It occurs in the loop in the following function. Thanks!

int db_read(SSL_STRUCT* ssl, size_t len, unsigned char* buffer){
  int r;
  memset(buffer, 0, len);
  printf("memset successful\n");
  do {
      r = ssl_read(&((ssl)->ssl), buffer, len-1);
  }while(r == POLARSSL_ERR_NET_WANT_READ);
  if(r < 0){
      printf("server forgot his reading glasses at home-- %d\n", r);
   }
 return r;
}
  • If the segfault occurs in the loop in that function, then more specifically it occurs in function `ssl_read()`. My best guess would be that there's something wrong with `ssl`, or perhaps with `*ssl`. Running your program under Valgrind would likely shed some light on the problem. Alternatively, run it in a debugger, such as gdb, that will stop execution and allow you to examine the program state when it receives the `SIGSEGV`. – John Bollinger Jan 23 '15 at 21:30
  • 1
    i'd be genuinely curious if that `ssl` pointer is (a) valid, and (b) contains a valid `ssl_context`. I'd also be curious if the caller correctly supplied a valid buffer of length `len`. – WhozCraig Jan 23 '15 at 21:30
  • is buffer allocated? I mean does it point to a valid buffer and is len the correct length of it? – pm100 Jan 23 '15 at 21:31
  • '&((ssl)->ssl)' seems a bit long-winded! – Martin James Jan 23 '15 at 21:31
  • If the problem were with `buffer` or `len`, then you would expect the segfault to occur during the `memset()`, prior to entering the loop. – John Bollinger Jan 23 '15 at 21:32
  • Well, yes. If it was me, I would break on the read and inspect the SSL_STRUCT for sanity/correctness. – Martin James Jan 23 '15 at 21:43

0 Answers0