summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoland Rossgotterer <roland.rossgotterer@gmail.com>2019-01-08 16:03:02 +0100
committerRoland Rossgotterer <roland.rossgotterer@gmail.com>2019-01-09 08:42:25 +0000
commit0330db86fdd42ef1be1354cdbbd6e0ffc21d9a80 (patch)
treefcf13678e6a0194b0336d214d45f5452ca4c8646 /src
parent166162d8305404e8fc820de91ef9f6d733b4657a (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/qglobal.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 0109bb3568..d15a8ba6ae 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -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();
};