gssmask: Use asprintf to avoid having to think about max uname.

This way there is no truncation and no build failure due to
-Werror=format-truncation as is the default in some compilers, such
as gcc7.4 with -Wall -Werror.

This is presumably not space-constrained or performance-critical; the
very next thing it does is another asprintf and frees it immediately.
And uname is not usually under any adversary's control.

fix https://github.com/heimdal/heimdal/issues/1105
This commit is contained in:
Taylor R Campbell
2023-05-26 02:02:53 +00:00
committed by Nico Williams
parent da9cad2047
commit 1d2233f907

View File

@@ -646,7 +646,7 @@ static int
HandleOP(GetVersionAndCapabilities)
{
int32_t cap = HAS_MONIKER;
char name[256] = "unknown", *str;
char *name = NULL, *str = NULL;
int ret;
if (targetname)
@@ -656,13 +656,16 @@ HandleOP(GetVersionAndCapabilities)
{
struct utsname ut;
if (uname(&ut) == 0) {
snprintf(name, sizeof(name), "%s-%s-%s",
ut.sysname, ut.version, ut.machine);
if (asprintf(&name, "%s-%s-%s",
ut.sysname, ut.version, ut.machine) == -1) {
errx(1, "out of memory");
}
}
}
#endif
ret = asprintf(&str, "gssmask %s %s", PACKAGE_STRING, name);
ret = asprintf(&str, "gssmask %s %s", PACKAGE_STRING,
name ? name : "unknown");
if (ret == -1)
errx(1, "out of memory");
@@ -670,6 +673,7 @@ HandleOP(GetVersionAndCapabilities)
put32(c, cap);
putstring(c, str);
free(str);
free(name);
return 0;
}