Make sure that the string generated by pretty_key_id() is always properly
authorclaudio <claudio@openbsd.org>
Mon, 21 Mar 2022 10:39:51 +0000 (10:39 +0000)
committerclaudio <claudio@openbsd.org>
Mon, 21 Mar 2022 10:39:51 +0000 (10:39 +0000)
NUL terminated.
Diff by Martin Vahlensieck <openbsd () academicsolutions ! ch>
OK tb@

usr.sbin/rpki-client/print.c

index c9ca62b..54139b3 100644 (file)
@@ -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 <claudio@openbsd.org>
  * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
 #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;
 }