Revert "lib: Fix printing a short into portstr"
This reverts commit ccb63bb0aa
, which was
unnecessary and broke tests/kdc/check-kadmin (and other things).
host->port happens to be an unsigned short, so that promotion to an integer in
the snprintf() call is safe in that the promoted value will still be
non-negative, and no larger than an unsigned short's maximum value. We're
still assuming that 7 bytes is sufficient to hold the text representation of
that maximum value, which indeed it is, assuming sizeof(unsigned short) == 2
and CHAR_BIT == 8, which are fair assumptions here. A better patch, if we
needed it, would be to just make portstr[] an array of 11 char, or perhaps make
it a VLA (but we can't yet use VLAs, I don't think, because of older Windows
systems that must be supported still).
This commit is contained in:
@@ -353,13 +353,13 @@ krb5_krbhst_format_string(krb5_context context, const krb5_krbhst_info *host,
|
||||
char *hostname, size_t hostlen)
|
||||
{
|
||||
const char *proto = "";
|
||||
char portstr[7] = {0};
|
||||
char portstr[7] = "";
|
||||
if(host->proto == KRB5_KRBHST_TCP)
|
||||
proto = "tcp/";
|
||||
else if(host->proto == KRB5_KRBHST_HTTP)
|
||||
proto = "http://";
|
||||
if(host->port != host->def_port)
|
||||
snprintf(portstr, sizeof(portstr), ":%hd", host->port);
|
||||
snprintf(portstr, sizeof(portstr), ":%d", host->port);
|
||||
snprintf(hostname, hostlen, "%s%s%s", proto, host->hostname, portstr);
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user