diff --git a/src/node_credentials.cc b/src/node_credentials.cc index 76088144950e49..b9f469f9d340ce 100644 --- a/src/node_credentials.cc +++ b/src/node_credentials.cc @@ -52,7 +52,7 @@ namespace credentials { static bool HasOnly(int capability) { DCHECK(cap_valid(capability)); - struct __user_cap_data_struct cap_data[2]; + struct __user_cap_data_struct cap_data[_LINUX_CAPABILITY_U32S_3]; struct __user_cap_header_struct cap_header_data = { _LINUX_CAPABILITY_VERSION_3, getpid()}; @@ -61,12 +61,11 @@ static bool HasOnly(int capability) { if (syscall(SYS_capget, &cap_header_data, &cap_data) != 0) { return false; } - if (capability < 32) { - return cap_data[0].permitted == - static_cast(CAP_TO_MASK(capability)); - } - return cap_data[1].permitted == - static_cast(CAP_TO_MASK(capability)); + + static_assert(arraysize(cap_data) == 2); + return cap_data[CAP_TO_INDEX(capability)].permitted == + static_cast(CAP_TO_MASK(capability)) && + cap_data[1 - CAP_TO_INDEX(capability)].permitted == 0; } #endif