Increase sysctl argument buffer size to include null character
An UUID is 36 characters long, but sysctl and sysctlbyname return a null terminated string with 37 characters. That was too long for the provided buffer. Surprisingly the return code was still 0 instead of -1. The returned buffer was empty though. Change-Id: Ic4d20ecc1b2b3a3e98468d31ac304957d56deee9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
166162d830
commit
0330db86fd
@ -2899,18 +2899,18 @@ enum {
|
||||
QByteArray QSysInfo::machineUniqueId()
|
||||
{
|
||||
#ifdef Q_OS_BSD4
|
||||
char uuid[UuidStringLen];
|
||||
char uuid[UuidStringLen + 1];
|
||||
size_t uuidlen = sizeof(uuid);
|
||||
# ifdef KERN_HOSTUUID
|
||||
int name[] = { CTL_KERN, KERN_HOSTUUID };
|
||||
if (sysctl(name, sizeof name / sizeof name[0], &uuid, &uuidlen, nullptr, 0) == 0
|
||||
&& uuidlen == sizeof(uuid))
|
||||
return QByteArray(uuid, uuidlen);
|
||||
return QByteArray(uuid, uuidlen - 1);
|
||||
|
||||
# else
|
||||
// Darwin: no fixed value, we need to search by name
|
||||
if (sysctlbyname("kern.uuid", uuid, &uuidlen, nullptr, 0) == 0 && uuidlen == sizeof(uuid))
|
||||
return QByteArray(uuid, uuidlen);
|
||||
return QByteArray(uuid, uuidlen - 1);
|
||||
# endif
|
||||
#elif defined(Q_OS_UNIX)
|
||||
// The modern name on Linux is /etc/machine-id, but that path is
|
||||
@ -2974,11 +2974,11 @@ QByteArray QSysInfo::bootUniqueId()
|
||||
}
|
||||
#elif defined(Q_OS_DARWIN)
|
||||
// "kern.bootsessionuuid" is only available by name
|
||||
char uuid[UuidStringLen];
|
||||
char uuid[UuidStringLen + 1];
|
||||
size_t uuidlen = sizeof(uuid);
|
||||
if (sysctlbyname("kern.bootsessionuuid", uuid, &uuidlen, nullptr, 0) == 0
|
||||
&& uuidlen == sizeof(uuid))
|
||||
return QByteArray(uuid, uuidlen);
|
||||
return QByteArray(uuid, uuidlen - 1);
|
||||
#endif
|
||||
return QByteArray();
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user