From f5f1d65c02f3e413b2ab26b47e6794cbe1e427bd Mon Sep 17 00:00:00 2001 From: Karol Grydziuszko Date: Fri, 19 Nov 2021 10:17:31 +0100 Subject: [PATCH] Fixed scope of local memory usage to prohibit out of scope usage. Change-Id: I980f1b9296c726685094bd52aa9c5e39702c90c1 Signed-off-by: Karol Grydziuszko --- frameworks/native/dgram_socket_server.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/frameworks/native/dgram_socket_server.cpp b/frameworks/native/dgram_socket_server.cpp index 2c02d1f..04db0d6 100644 --- a/frameworks/native/dgram_socket_server.cpp +++ b/frameworks/native/dgram_socket_server.cpp @@ -16,6 +16,7 @@ #include "dgram_socket_server.h" #include +#include namespace OHOS { namespace HiviewDFX { @@ -40,18 +41,18 @@ int DgramSocketServer::RecvPacket(char **data, int *length, struct ucred *cred) return 0; } - struct msghdr msgh; + std::array control = {0}; + + struct msghdr msgh = {0}; if (cred != nullptr) { struct iovec iov; iov.iov_base = *data; iov.iov_len = packetLen; msgh.msg_iov = &iov; msgh.msg_iovlen = 1; - - unsigned int cmsgSize = CMSG_SPACE(sizeof(struct ucred)); - char control[cmsgSize]; - msgh.msg_control = control; - msgh.msg_controllen = cmsgSize; + + msgh.msg_control = control.data(); + msgh.msg_controllen = control.size(); msgh.msg_name = nullptr; msgh.msg_namelen = 0; -- Gitee