Check for null pointers from gethostbyname_r() to prevent seg faults.
This commit is contained in:
parent
53d34911a1
commit
8630c134a8
1 changed files with 8 additions and 5 deletions
13
libhttp/ssl.c
Normal file → Executable file
13
libhttp/ssl.c
Normal file → Executable file
|
@ -672,12 +672,15 @@ void sslSetCertificate(struct SSLSupport *ssl, const char *filename,
|
||||||
char hostname[256], buf[4096];
|
char hostname[256], buf[4096];
|
||||||
check(!gethostname(hostname, sizeof(hostname)));
|
check(!gethostname(hostname, sizeof(hostname)));
|
||||||
struct hostent he_buf, *he;
|
struct hostent he_buf, *he;
|
||||||
int h_err;
|
int h_err = 0;
|
||||||
if (gethostbyname_r(hostname, &he_buf, buf, sizeof(buf),
|
int ret = gethostbyname_r(hostname, &he_buf, buf, sizeof(buf), &he, &h_err);
|
||||||
&he, &h_err)) {
|
if (!ret && he && he->h_name) {
|
||||||
sslGenerateCertificate(defaultCertificate, hostname);
|
|
||||||
} else {
|
|
||||||
sslGenerateCertificate(defaultCertificate, he->h_name);
|
sslGenerateCertificate(defaultCertificate, he->h_name);
|
||||||
|
} else {
|
||||||
|
if (h_err) {
|
||||||
|
warn("Error getting host information: \"%s\".", hstrerror(h_err));
|
||||||
|
}
|
||||||
|
sslGenerateCertificate(defaultCertificate, hostname);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
goto valid_certificate;
|
goto valid_certificate;
|
||||||
|
|
Loading…
Reference in a new issue