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:

committed by
Nico Williams

parent
da9cad2047
commit
1d2233f907
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user