Skip to content

Instantly share code, notes, and snippets.

@julik
Created May 12, 2016 21:46
Show Gist options
  • Save julik/58c0b9713ac2d2372d799ca562281c9a to your computer and use it in GitHub Desktop.
Save julik/58c0b9713ac2d2372d799ca562281c9a to your computer and use it in GitHub Desktop.
clang -o bug bug.c -lcurl
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <curl/curl.h>
#include <stdlib.h>
// Compiled and ran via
// $ clang -o bug bug.c -lcurl && ./bug
void perform_https_req() {
CURL* curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
curl_easy_setopt(curl, CURLOPT_URL, "https://google.com");
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
fprintf(stdout, "Performing the request\n");
fflush(stdout);
curl_easy_perform(curl);
fprintf(stdout, "Request performed.\n");
fflush(stdout);
curl_easy_cleanup(curl);
}
int main(int argc, char*argv[]){
// Perform a curl request to google in the master first. This is necessary to cause the crash,
// at least in my attempts.
perform_https_req();
pid_t child_pid;
child_pid = fork();
if(child_pid == 0) {
perform_https_req(); // Perform the request in child
exit(0);
} else {
int stat_loc;
wait(&stat_loc);
printf("Exited with %d\n", stat_loc);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment