[Git][NTPsec/ntpsec][master] 2 commits: Repair ugly crash from NTS client if broken ca filename

Hal Murray gitlab at mg.gitlab.com
Thu Oct 31 04:14:53 UTC 2019



Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
7383ad7d by Hal Murray at 2019-10-31T02:52:09Z
Repair ugly crash from NTS client if broken ca filename

It used to exit so the operator would know there was a problem
rather than having to debug things after noticing it wasn't working.
But exit-ing from a non-main thread crashes lib_getbuf()
which adds a layer of confusion.

Also repair/tweak a couple of log messages.

- - - - -
6225fc91 by Hal Murray at 2019-10-31T03:05:07Z
Tweak devel/hacking to not call exit() in non main thread.

- - - - -


2 changed files:

- devel/hacking.adoc
- ntpd/nts_client.c


Changes:

=====================================
devel/hacking.adoc
=====================================
@@ -79,7 +79,10 @@ thread.  One interesting area is msyslog.  The DNS thread doesn't call msyslog.
 That was impractical for NTS, so msyslog is thread safe as of 2019-Apr.
 Beware of calling strerror() from non-main threads.  Use ntp_strerror_r() into
 a buffer on the stack.  Similarly, use socktoa_r() and sockporttoa_r() and
-don't call lib_getbuf() or refclock_name().
+don't call lib_getbuf(), refclock_name(), or exit().  [exit() calls
+the registered cleanup routines and some of them call lib_getbuf()
+which will crash (again) when called from a non-main thread.  So
+avoid exit() if you can, but use it if you can't find a better way.]
 
 You *may* assume the clock_gettime(2) and clock_settime(2) calls, and
 the related getitimer(2)/setitimer(2), from POSIX-1.2008.


=====================================
ntpd/nts_client.c
=====================================
@@ -117,6 +117,8 @@ bool nts_probe(struct peer * peer) {
 	else {
 		SSL_CTX *ctx; 
 		ctx = make_ssl_client_ctx(peer->cfg.nts_cfg.ca);
+		if (NULL == ctx)
+			return false;
 		ssl = SSL_new(ctx);
 		SSL_CTX_free(ctx);
 	}
@@ -213,7 +215,7 @@ SSL_CTX* make_ssl_client_ctx(const char * filename) {
 		/* Happens if no ciphers */
 		msyslog(LOG_ERR, "NTSc: NULL ctx");
 		nts_log_ssl_error();
-		exit(1);
+		return NULL;
 	}
 
 #if (OPENSSL_VERSION_NUMBER > 0x1000200fL)
@@ -233,7 +235,8 @@ SSL_CTX* make_ssl_client_ctx(const char * filename) {
 
 	if (!ok) {
 		msyslog(LOG_ERR, "NTSc: Troubles setting up client SSL CTX");
-		exit(1);
+		SSL_CTX_free(ctx);
+		return NULL;
 	};
 
 	return ctx;
@@ -687,7 +690,7 @@ bool nts_set_cert_search(SSL_CTX *ctx, const char *filename) {
 	}
 	ntp_strerror_r(errno, errbuf, sizeof(errbuf));
 	msyslog(LOG_ERR, "NTSc: can't stat cert dir/file: %s, %s",
-		ntsconfig.ca, errbuf);
+		filename, errbuf);
 	return false;
 }
 /* The -4/-6 option is used for both the NTS-KE server and the NTP server.
@@ -707,7 +710,7 @@ bool nts_server_lookup(char *server, sockaddr_u *addr, int af) {
 
 	gai_rc = getaddrinfo(server, "123", &hints, &answer);
 	if (0 != gai_rc) {
-		msyslog(LOG_INFO, "NTSc: nts_probe: DNS error trying to lookup %s: %d, %s",
+		msyslog(LOG_INFO, "NTSc: DNS error trying to lookup %s: %d, %s",
 			server, gai_rc, gai_strerror(gai_rc));
 		return false;
 	}



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/22c04cdf37b95b5e71555589b952e803ee90631c...6225fc91d48fdc4801a31c054a9ce5d410b0b0cf

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/22c04cdf37b95b5e71555589b952e803ee90631c...6225fc91d48fdc4801a31c054a9ce5d410b0b0cf
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20191031/43d10126/attachment-0001.htm>


More information about the vc mailing list