diff --git a/common/libtest161/test161.c b/common/libtest161/test161.c index a298fb4..e0a49dd 100644 --- a/common/libtest161/test161.c +++ b/common/libtest161/test161.c @@ -65,9 +65,9 @@ success(int status, const char * secret, const char * name) { int partial_credit(const char *secret, const char *name, int scored, int total) { - char buffer[128]; - snprintf(buffer, 128, "PARTIAL CREDIT %d OF %d", scored, total); - return secprintf(secret, buffer, name); + char buffer[128]; + snprintf(buffer, 128, "PARTIAL CREDIT %d OF %d", scored, total); + return secprintf(secret, buffer, name); } #ifndef _KERNEL @@ -87,6 +87,13 @@ say(const char *fmt, ...) #ifndef SECRET_TESTING +int +snsecprintf(size_t len, char *buffer, const char *secret, const char *msg, const char *name) +{ + (void)secret; + return snprintf(buffer, len, "%s: %s", name, msg); +} + int secprintf(const char * secret, const char * msg, const char * name) { @@ -101,8 +108,9 @@ secprintf(const char * secret, const char * msg, const char * name) #else -int -secprintf(const char * secret, const char * msg, const char * name) +static int +secprintf_common(use_buf int, size_t len, char *buffer, + const char *secret, const char *msg, const char *name) { char *hash, *salt, *fullmsg; int res; @@ -132,11 +140,15 @@ secprintf(const char * secret, const char * msg, const char * name) goto out; } + if (!use_buf) { #ifdef _KERNEL - res = kprintf("\n(%s, %s, %s, %s: %s)\n", name, hash, salt, name, msg); + res = kprintf("\n(%s, %s, %s, %s: %s)\n", name, hash, salt, name, msg); #else - res = say("\n(%s, %s, %s, %s: %s)\n", name, hash, salt, name, msg); + res = say("\n(%s, %s, %s, %s: %s)\n", name, hash, salt, name, msg); #endif + } else { + res = snprintf(buffer, b_len, "\n(%s, %s, %s, %s: %s)\n", name, hash, salt, name, msg); + } out: // These may be NULL, but that's OK @@ -151,6 +163,18 @@ out: return res; } +int +snsecprintf(size_t b_len, char *buffer, const char *secret, const char *msg, const char *name) +{ + return secprintf_common(1, b_len, buffer, secret, msg, name); +} + +int +secprintf(const char * secret, const char * msg, const char * name) +{ + return snsecprintf(0, 0, NULL, secret, msg, name); +} + #endif #ifdef _KERNEL diff --git a/kern/include/kern/test161.h b/kern/include/kern/test161.h index 4922635..1458bd8 100644 --- a/kern/include/kern/test161.h +++ b/kern/include/kern/test161.h @@ -66,6 +66,7 @@ int success(int, const char *, const char *); int secprintf(const char *secret, const char *msg, const char *name); +int snsecprintf(size_t len, char *buffer, const char *secret, const char *msg, const char *name); int partial_credit(const char *secret, const char *name, int scored, int total); #ifdef _KERNEL