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