autofs-5.1.8 - avoid calling pthread_getspecific() with NULL key_thread_attempt_id

From: Ian Kent <raven@themaw.net>

Don't call pthread_getspecific() if key_thread_attempt_id is NULL in
case the pthread_getspecific() implementation doesn't check for this.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG |    1 +
 lib/log.c |    3 +++
 2 files changed, 4 insertions(+)

diff --git a/CHANGELOG b/CHANGELOG
index 9d57a21b..dacc2fa0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -12,6 +12,7 @@
 - simplify cache_add() a little.
 - fix use after free in tree_mapent_delete_offset_tree().
 - fix memory leak in xdr_exports().
+- avoid calling pthread_getspecific() with NULL key_thread_attempt_id.
 
 19/10/2021 autofs-5.1.8
 - add xdr_exports().
diff --git a/lib/log.c b/lib/log.c
index 0cb47d7e..d1edef28 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -38,6 +38,9 @@ static char *prepare_attempt_prefix(const char *msg)
 	char buffer[ATTEMPT_ID_SIZE + 1];
 	char *prefixed_msg = NULL;
 
+	if (!key_thread_attempt_id)
+		return NULL;
+
 	attempt_id = pthread_getspecific(key_thread_attempt_id);
 	if (attempt_id) {
 		int len = sizeof(buffer) + 1 + strlen(msg) + 1;