From 254fd37274f34029835823b1b8bf7c6cf13ad16b Mon Sep 17 00:00:00 2001 From: claudio Date: Mon, 21 Mar 2022 10:39:51 +0000 Subject: [PATCH] Make sure that the string generated by pretty_key_id() is always properly NUL terminated. Diff by Martin Vahlensieck OK tb@ --- usr.sbin/rpki-client/print.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/usr.sbin/rpki-client/print.c b/usr.sbin/rpki-client/print.c index c9ca62be178..54139b397d9 100644 --- a/usr.sbin/rpki-client/print.c +++ b/usr.sbin/rpki-client/print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print.c,v 1.5 2022/02/10 17:33:28 claudio Exp $ */ +/* $OpenBSD: print.c,v 1.6 2022/03/21 10:39:51 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -28,19 +28,21 @@ #include "extern.h" static const char * -pretty_key_id(char *hex) +pretty_key_id(const char *hex) { static char buf[128]; /* bigger than SHA_DIGEST_LENGTH * 3 */ size_t i; for (i = 0; i < sizeof(buf) && *hex != '\0'; i++) { - if (i % 3 == 2 && *hex != '\0') + if (i % 3 == 2) buf[i] = ':'; else buf[i] = *hex++; } if (i == sizeof(buf)) memcpy(buf + sizeof(buf) - 4, "...", 4); + else + buf[i] = '\0'; return buf; } -- 2.20.1