summaryrefslogtreecommitdiff
path: root/src/lib/libtls/tls.c
diff options
context:
space:
mode:
authorbcook <>2014-12-07 15:00:32 +0000
committerbcook <>2014-12-07 15:00:32 +0000
commitf8b7419c7a231d8409475ccb008dfdb666e82813 (patch)
tree094ce4813a37514a96f893ee676a60374f36f28b /src/lib/libtls/tls.c
parent54c29dc63f86eb85f4c728ad9b5375acc16f8ea7 (diff)
downloadopenbsd-f8b7419c7a231d8409475ccb008dfdb666e82813.tar.gz
openbsd-f8b7419c7a231d8409475ccb008dfdb666e82813.tar.bz2
openbsd-f8b7419c7a231d8409475ccb008dfdb666e82813.zip
Allow specific libtls hostname validation errors to propagate.
Remove direct calls to printf from the tls_check_hostname() path. This allows NUL byte error messages to bubble up to the caller, to be logged in a program-appropriate way. It also removes non-portable calls to getprogname(). The semantics of tls_error() are changed slightly: the last error message is not necessarily preserved between subsequent calls into the library. When the previous call to libtls succeeds, client programs should treat the return value of tls_error() as undefined. ok tedu@
Diffstat (limited to 'src/lib/libtls/tls.c')
-rw-r--r--src/lib/libtls/tls.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/lib/libtls/tls.c b/src/lib/libtls/tls.c
index a7f612e40b..d3bb79b3fe 100644
--- a/src/lib/libtls/tls.c
+++ b/src/lib/libtls/tls.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls.c,v 1.1 2014/10/31 13:46:17 jsing Exp $ */ 1/* $OpenBSD: tls.c,v 1.2 2014/12/07 15:00:32 bcook Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -56,15 +56,22 @@ tls_error(struct tls *ctx)
56 return ctx->errmsg; 56 return ctx->errmsg;
57} 57}
58 58
59void
60tls_clear_error(struct tls *ctx)
61{
62 ctx->err = 0;
63 free(ctx->errmsg);
64 ctx->errmsg = NULL;
65}
66
59int 67int
60tls_set_error(struct tls *ctx, char *fmt, ...) 68tls_set_error(struct tls *ctx, char *fmt, ...)
61{ 69{
62 va_list ap; 70 va_list ap;
63 int rv; 71 int rv;
64 72
73 tls_clear_error(ctx);
65 ctx->err = errno; 74 ctx->err = errno;
66 free(ctx->errmsg);
67 ctx->errmsg = NULL;
68 75
69 va_start(ap, fmt); 76 va_start(ap, fmt);
70 rv = vasprintf(&ctx->errmsg, fmt, ap); 77 rv = vasprintf(&ctx->errmsg, fmt, ap);