diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2022-03-21 10:39:52 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2022-03-21 10:39:52 +0000 |
commit | f220fecd1fcf9e7e41613010415c725b40023634 (patch) | |
tree | dd0d78602ae16a671e7f339520e407de86567dd7 /usr.sbin/rpki-client | |
parent | bc19aeed8fa12d9627ea3a7624fc07b1b19cad76 (diff) |
Make sure that the string generated by pretty_key_id() is always properly
NUL terminated.
Diff by Martin Vahlensieck <openbsd () academicsolutions ! ch>
OK tb@
Diffstat (limited to 'usr.sbin/rpki-client')
-rw-r--r-- | usr.sbin/rpki-client/print.c | 8 |
1 files 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 <claudio@openbsd.org> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> @@ -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; } |