From: Ben Kaduk Date: Wed, 27 Jun 2012 19:14:00 +0000 (-0400) Subject: Improve printf handling of size_t args X-Git-Tag: krb5-1.11-alpha1~463 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4a3c43c403a24fcf21a2a67eddf831032ab7ec4;p=thirdparty%2Fkrb5.git 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. --- diff --git a/src/appl/gss-sample/gss-server.c b/src/appl/gss-sample/gss-server.c index 2e56e06ab0..0f5fea0f81 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 e1f92053d5..53bdb983c4 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);