Merge pull request #582 from night1rider/fenrir-issue-2894

Give each PSK thread its own heap copy of connfd
pull/318/merge
Paul Adelsbach 2026-07-10 15:50:04 -06:00 committed by GitHub
commit 1ea8602197
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 1 deletions

View File

@ -78,6 +78,10 @@ void* wolfssl_thread(void* fd)
char buf[MAXLINE];
char response[] = "I hear ya for shizzle";
/* fd was heap-allocated per connection by main(); free it now that the
* descriptor has been copied into connfd. */
free(fd);
memset(buf, 0, MAXLINE);
/* create WOLFSSL object */
@ -230,12 +234,26 @@ int main()
return 1;
}
else {
int* connfd_ptr;
printf("Connection from %s, port %d\n",
inet_ntop(AF_INET, &cliAddr.sin_addr, buff, sizeof(buff)),
ntohs(cliAddr.sin_port));
if (pthread_create(&thread, NULL, &wolfssl_thread, (void*) &connfd)
/* Give each thread its own heap-allocated copy of the descriptor;
* passing &connfd would let the next accept() overwrite it. */
connfd_ptr = malloc(sizeof(int));
if (connfd_ptr == NULL) {
printf("Fatal error : malloc error\n");
close(connfd);
return 1;
}
*connfd_ptr = connfd;
if (pthread_create(&thread, NULL, &wolfssl_thread, connfd_ptr)
!= 0) {
close(connfd);
free(connfd_ptr);
return 1;
}
if (pthread_detach(thread) != 0) {