krb5 commit: Improve printf handling of size_t args
Benjamin Kaduk
kaduk at MIT.EDU
Tue Jul 3 00:43:52 EDT 2012
https://github.com/krb5/krb5/commit/e4a3c43c403a24fcf21a2a67eddf831032ab7ec4
commit e4a3c43c403a24fcf21a2a67eddf831032ab7ec4
Author: Ben Kaduk <kaduk at mit.edu>
Date: Wed Jun 27 15:14:00 2012 -0400
Improve printf handling of size_t args
The %*s format takes two arguments, a precision length/width and
an actual string; the length is specified as a signed integer.
The size_t length field of the gss_buffer_desc type is an unsigned
type, which must be cast or otherwise converted to a signed type
to match the format string expectations.
I do not think that the length will approach SIZE_T_MAX in practice,
due to buffer constraints, so do not include handling for the
edge case.
There is a '%zu' format string for printing size_ts, but it is not
available everywhere (e.g., AIX). Instead, use the
unsigned long long abomination.
src/appl/gss-sample/gss-server.c | 2 +-
src/lib/rpc/auth_gssapi_misc.c | 7 ++++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/appl/gss-sample/gss-server.c b/src/appl/gss-sample/gss-server.c
index 2e56e06..0f5fea0 100644
--- a/src/appl/gss-sample/gss-server.c
+++ b/src/appl/gss-sample/gss-server.c
@@ -893,7 +893,7 @@ showLocalIdentity(OM_uint32 *minor, gss_name_t name)
major = gss_localname(minor, name, GSS_C_NO_OID, &localname);
if (major == GSS_S_COMPLETE)
- printf("localname: %-*s\n", localname.length, localname.value);
+ printf("localname: %-*s\n", (int)localname.length, localname.value);
else if (major != GSS_S_UNAVAILABLE)
display_status("gss_localname", major, *minor);
gss_release_buffer(minor, &localname);
diff --git a/src/lib/rpc/auth_gssapi_misc.c b/src/lib/rpc/auth_gssapi_misc.c
index e1f9205..53bdb98 100644
--- a/src/lib/rpc/auth_gssapi_misc.c
+++ b/src/lib/rpc/auth_gssapi_misc.c
@@ -183,7 +183,7 @@ static void auth_gssapi_display_status_1(
putc ('\n', stderr);
if (misc_debug_gssapi)
gssrpcint_printf("GSS-API authentication error %s: %*s\n",
- m, msg.length, (char *) msg.value);
+ m, (int)msg.length, (char *) msg.value);
(void) gss_release_buffer(&minor_stat, &msg);
if (!msg_ctx)
@@ -296,8 +296,9 @@ bool_t auth_gssapi_unwrap_data(
if (*major != GSS_S_COMPLETE)
return FALSE;
- PRINTF(("gssapi_unwrap_data: %d bytes data, %d bytes sealed\n",
- out_buf.length, in_buf.length));
+ PRINTF(("gssapi_unwrap_data: %llu bytes data, %llu bytes sealed\n",
+ (unsigned long long)out_buf.length,
+ (unsigned long long)in_buf.length));
xdrmem_create(&temp_xdrs, out_buf.value, out_buf.length, XDR_DECODE);
More information about the cvs-krb5
mailing list