Commit ddf1b5a1 authored by Gaël PORTAY's avatar Gaël PORTAY
Browse files

Fix initialization of string members.

Reported by valgrind using the command below:
$ valgrind jackd -p128 -t2000 -dalsa -dhw:0 -r44100 -p2048 -n2 -S
==8930== Memcheck, a memory error detector
==8930== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==8930== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==8930== Command: jackd -p128 -t2000 -dalsa -dhw:0 -r44100 -p2048 -n2 -S
==8930==
jackdmp 1.9.11
Copyright 2001-2005 Paul Davis and others.
Copyright 2004-2016 Grame.
jackdmp comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details
JACK server starting in realtime mode with priority 10
self-connect-mode is "Don't restrict self connect requests"
creating alsa driver ... hw:0|hw:0|2048|2|44100|0|0|nomon|swmeter|-|16bit
configuring for 44100Hz, period = 2048 frames (46.4 ms), buffer = 2 periods
ALSA: final selected sample format for capture: 16bit little-endian
ALSA: use 2 periods for capture
ALSA: final selected sample format for playback: 16bit little-endian
ALSA: use 2 periods for playback
==8930== Thread 4:
==8930== Syscall param write(buf) points to uninitialised byte(s)
==8930==    at 0x571388D: ??? (syscall-template.S:81)
==8930==    by 0x4EA70B3: Jack::JackClientSocket::Write(void*, int) (JackSocket.cpp:233)
==8930==    by 0x4E94C62: Jack::JackClientCheckResult::Write(Jack::detail::JackChannelTransactionInterface*) (JackRequest.h:227)
==8930==    by 0x4ECDF3A: Jack::JackRequestDecoder::HandleRequest(Jack::detail::JackChannelTransactionInterface*, int) (JackRequestDecoder.cpp:58)
==8930==    by 0x4ED4219: Jack::JackSocketServerChannel::Execute() (JackSocketServerChannel.cpp:247)
==8930==    by 0x4EA4B63: Jack::JackPosixThread::ThreadHandler(void*) (JackPosixThread.cpp:59)
==8930==    by 0x59F5181: start_thread (pthread_create.c:312)
==8930==    by 0x572247C: clone (clone.S:111)
==8930==  Address 0x41da85e is on thread 4's stack
==8930==  in frame #3, created by Jack::JackRequestDecoder::HandleRequest(Jack::detail::JackChannelTransactionInterface*, int) (JackRequestDecoder.cpp:46)
==8930==
==8930== Syscall param write(buf) points to uninitialised byte(s)
==8930==    at 0x571388D: ??? (syscall-template.S:81)
==8930==    by 0x4EA70B3: Jack::JackClientSocket::Write(void*, int) (JackSocket.cpp:233)
==8930==    by 0x4ED619B: Jack::JackClientNotification::Write(Jack::detail::JackChannelTransactionInterface*) (JackRequest.h:1606)
==8930==    by 0x4ED5F2E: Jack::JackSocketNotifyChannel::ClientNotify(int, char const*, int, int, char const*, int, int, int*) (JackSocketNotifyChannel.cpp:56)
==8930==    by 0x4EB51DF: Jack::JackExternalClient::ClientNotify(int, char const*, int, int, char const*, int, int) (JackExternalClient.cpp:40)
==8930==    by 0x4EAFA9A: Jack::JackEngine::ClientNotify(Jack::JackClientInterface*, int, char const*, int, int, char const*, int, int) (JackEngine.cpp:274)
==8930==    by 0x4EAFD34: Jack::JackEngine::NotifyAddClient(Jack::JackClientInterface*, char const*, int) (JackEngine.cpp:318)
==8930==    by 0x4EB0C99: Jack::JackEngine::ClientExternalOpen(char const*, int, int, int*, int*, int*, int*) (JackEngine.cpp:636)
==8930==    by 0x4ED4486: Jack::JackLockedEngine::ClientExternalOpen(char const*, int, int, int*, int*, int*, int*) (JackLockedEngine.h:123)
==8930==    by 0x4ED3AD5: Jack::JackSocketServerChannel::ClientAdd(Jack::detail::JackChannelTransactionInterface*, Jack::JackClientOpenRequest*, Jack::JackClientOpenResult*) (JackSocketServerChannel.cpp:132)
==8930==    by 0x4ECE0B8: Jack::JackRequestDecoder::HandleRequest(Jack::detail::JackChannelTransactionInterface*, int) (JackRequestDecoder.cpp:73)
==8930==    by 0x4ECDFBA: Jack::JackRequestDecoder::HandleRequest(Jack::detail::JackChannelTransactionInterface*, int) (JackRequestDecoder.cpp:63)
==8930==  Address 0x41d9ccb is on thread 4's stack
==8930==  in frame #3, created by Jack::JackSocketNotifyChannel::ClientNotify(int, char const*, int, int, char const*, int, int, int*) (JackSocketNotifyChannel.cpp:51)
==8930==
==8930== Syscall param write(buf) points to uninitialised byte(s)
==8930==    at 0x571388D: ??? (syscall-template.S:81)
==8930==    by 0x4EA70B3: Jack::JackClientSocket::Write(void*, int) (JackSocket.cpp:233)
==8930==    by 0x4ED633C: Jack::JackClientNotification::Write(Jack::detail::JackChannelTransactionInterface*) (JackRequest.h:1612)
==8930==    by 0x4ED5F2E: Jack::JackSocketNotifyChannel::ClientNotify(int, char const*, int, int, char const*, int, int, int*) (JackSocketNotifyChannel.cpp:56)
==8930==    by 0x4EB51DF: Jack::JackExternalClient::ClientNotify(int, char const*, int, int, char const*, int, int) (JackExternalClient.cpp:40)
==8930==    by 0x4EAFA9A: Jack::JackEngine::ClientNotify(Jack::JackClientInterface*, int, char const*, int, int, char const*, int, int) (JackEngine.cpp:274)
==8930==    by 0x4EAFD34: Jack::JackEngine::NotifyAddClient(Jack::JackClientInterface*, char const*, int) (JackEngine.cpp:318)
==8930==    by 0x4EB0C99: Jack::JackEngine::ClientExternalOpen(char const*, int, int, int*, int*, int*, int*) (JackEngine.cpp:636)
==8930==    by 0x4ED4486: Jack::JackLockedEngine::ClientExternalOpen(char const*, int, int, int*, int*, int*, int*) (JackLockedEngine.h:123)
==8930==    by 0x4ED3AD5: Jack::JackSocketServerChannel::ClientAdd(Jack::detail::JackChannelTransactionInterface*, Jack::JackClientOpenRequest*, Jack::JackClientOpenResult*) (JackSocketServerChannel.cpp:132)
==8930==    by 0x4ECE0B8: Jack::JackRequestDecoder::HandleRequest(Jack::detail::JackChannelTransactionInterface*, int) (JackRequestDecoder.cpp:73)
==8930==    by 0x4ECDFBA: Jack::JackRequestDecoder::HandleRequest(Jack::detail::JackChannelTransactionInterface*, int) (JackRequestDecoder.cpp:63)
==8930==  Address 0x41d9d1d is on thread 4's stack
==8930==  in frame #3, created by Jack::JackSocketNotifyChannel::ClientNotify(int, char const*, int, int, char const*, int, int, int*) (JackSocketNotifyChannel.cpp:51)
==8930==
parent a91969e1
......@@ -168,6 +168,7 @@ struct JackClientCheckRequest : public JackRequest
JackClientCheckRequest(const char* name, int protocol, int options, int uuid, int open = false)
: JackRequest(JackRequest::kClientCheck), fProtocol(protocol), fOptions(options), fUUID(uuid), fOpen(open)
{
memset(fName, 0, sizeof(fName));
snprintf(fName, sizeof(fName), "%s", name);
}
......@@ -210,6 +211,7 @@ struct JackClientCheckResult : public JackResult
JackClientCheckResult(int32_t result, const char* name, int status)
: JackResult(result), fStatus(status)
{
memset(fName, 0, sizeof(fName));
snprintf(fName, sizeof(fName), "%s", name);
}
......@@ -246,6 +248,7 @@ struct JackClientOpenRequest : public JackRequest
{}
JackClientOpenRequest(const char* name, int pid, int uuid): JackRequest(JackRequest::kClientOpen)
{
memset(fName, 0, sizeof(fName));
snprintf(fName, sizeof(fName), "%s", name);
fPID = pid;
fUUID = uuid;
......@@ -418,8 +421,10 @@ struct JackPortRegisterRequest : public JackRequest
JackPortRegisterRequest(int refnum, const char* name, const char* port_type, unsigned int flags, unsigned int buffer_size)
: JackRequest(JackRequest::kRegisterPort), fRefNum(refnum), fFlags(flags), fBufferSize(buffer_size)
{
strcpy(fName, name);
strcpy(fPortType, port_type);
memset(fName, 0, sizeof(fName));
memset(fPortType, 0, sizeof(fPortType));
strncpy(fName, name, sizeof(fName)-1);
strncpy(fPortType, port_type, sizeof(fPortType)-1);
}
int Read(detail::JackChannelTransactionInterface* trans)
......@@ -525,8 +530,10 @@ struct JackPortConnectNameRequest : public JackRequest
JackPortConnectNameRequest(int refnum, const char* src_name, const char* dst_name)
: JackRequest(JackRequest::kConnectNamePorts), fRefNum(refnum)
{
strcpy(fSrc, src_name);
strcpy(fDst, dst_name);
memset(fSrc, 0, sizeof(fSrc));
memset(fDst, 0, sizeof(fDst));
strncpy(fSrc, src_name, sizeof(fSrc)-1);
strncpy(fDst, dst_name, sizeof(fDst)-1);
}
int Read(detail::JackChannelTransactionInterface* trans)
......@@ -567,8 +574,10 @@ struct JackPortDisconnectNameRequest : public JackRequest
JackPortDisconnectNameRequest(int refnum, const char* src_name, const char* dst_name)
: JackRequest(JackRequest::kDisconnectNamePorts), fRefNum(refnum)
{
strcpy(fSrc, src_name);
strcpy(fDst, dst_name);
memset(fSrc, 0, sizeof(fSrc));
memset(fDst, 0, sizeof(fDst));
strncpy(fSrc, src_name, sizeof(fSrc)-1);
strncpy(fDst, dst_name, sizeof(fDst)-1);
}
int Read(detail::JackChannelTransactionInterface* trans)
......@@ -685,7 +694,8 @@ struct JackPortRenameRequest : public JackRequest
JackPortRenameRequest(int refnum, jack_port_id_t port, const char* name)
: JackRequest(JackRequest::kPortRename), fRefNum(refnum), fPort(port)
{
strcpy(fName, name);
memset(fName, 0, sizeof(fName));
strncpy(fName, name, sizeof(fName)-1);
}
int Read(detail::JackChannelTransactionInterface* trans)
......@@ -908,6 +918,7 @@ struct JackGetInternalClientNameResult : public JackResult
JackGetInternalClientNameResult(int32_t result, const char* name)
: JackResult(result)
{
memset(fName, 0, sizeof(fName));
snprintf(fName, sizeof(fName), "%s", name);
}
......@@ -943,6 +954,7 @@ struct JackInternalClientHandleRequest : public JackRequest
JackInternalClientHandleRequest(int refnum, const char* client_name)
: JackRequest(JackRequest::kInternalClientHandle), fRefNum(refnum)
{
memset(fName, 0, sizeof(fName));
snprintf(fName, sizeof(fName), "%s", client_name);
}
......@@ -1021,6 +1033,9 @@ struct JackInternalClientLoadRequest : public JackRequest
JackInternalClientLoadRequest(int refnum, const char* client_name, const char* so_name, const char* objet_data, int options, int uuid )
: JackRequest(JackRequest::kInternalClientLoad), fRefNum(refnum), fOptions(options), fUUID(uuid)
{
memset(fName, 0, sizeof(fName));
memset(fDllName, 0, sizeof(fDllName));
memset(fLoadInitName, 0, sizeof(fLoadInitName));
snprintf(fName, sizeof(fName), "%s", client_name);
snprintf(fDllName, sizeof(fDllName), "%s", so_name);
snprintf(fLoadInitName, sizeof(fLoadInitName), "%s", objet_data);
......@@ -1203,9 +1218,12 @@ struct JackSessionCommand
JackSessionCommand(const char *uuid, const char *clientname, const char *command, jack_session_flags_t flags)
{
strncpy(fUUID, uuid, sizeof(fUUID));
strncpy(fClientName, clientname, sizeof(fClientName));
strncpy(fCommand, command, sizeof(fCommand));
memset(fUUID, 0, sizeof(fUUID));
memset(fClientName, 0, sizeof(fClientName));
memset(fCommand, 0, sizeof(fCommand));
strncpy(fUUID, uuid, sizeof(fUUID)-1);
strncpy(fClientName, clientname, sizeof(fClientName)-1);
strncpy(fCommand, command, sizeof(fCommand)-1);
fFlags = flags;
}
};
......@@ -1315,11 +1333,13 @@ struct JackSessionNotifyRequest : public JackRequest
JackSessionNotifyRequest(int refnum, const char* path, jack_session_event_type_t type, const char* dst)
: JackRequest(JackRequest::kSessionNotify), fEventType(type), fRefNum(refnum)
{
memset(fPath, 0, sizeof(fPath));
memset(fDst, 0, sizeof(fDst));
snprintf(fPath, sizeof(fPath), "%s", path);
fPath[JACK_MESSAGE_SIZE] = 0;
if (dst) {
snprintf(fDst, sizeof(fDst), "%s", dst);
} else {
fDst[0] = '\0';
fDst[JACK_CLIENT_NAME_SIZE] = 0;
}
}
......@@ -1384,6 +1404,7 @@ struct JackClientNameResult : public JackResult
JackClientNameResult(int32_t result, const char* name)
: JackResult(result)
{
memset(fName, 0, sizeof(fName));
snprintf(fName, sizeof(fName), "%s", name);
}
......@@ -1412,6 +1433,7 @@ struct JackUUIDResult : public JackResult
JackUUIDResult(int32_t result, const char* uuid)
: JackResult(result)
{
memset(fUUID, 0, sizeof(fUUID));
snprintf(fUUID, sizeof(fUUID), "%s", uuid);
}
......@@ -1441,7 +1463,8 @@ struct JackGetUUIDRequest : public JackRequest
JackGetUUIDRequest(const char* client_name)
: JackRequest(JackRequest::kGetUUIDByClient)
{
strncpy(fName, client_name, sizeof(fName));
memset(fName, 0, sizeof(fName));
strncpy(fName, client_name, sizeof(fName)-1);
}
int Read(detail::JackChannelTransactionInterface* trans)
......@@ -1472,7 +1495,8 @@ struct JackGetClientNameRequest : public JackRequest
JackGetClientNameRequest(const char* uuid)
: JackRequest(JackRequest::kGetClientByUUID)
{
strncpy(fUUID, uuid, sizeof(fUUID));
memset(fUUID, 0, sizeof(fUUID));
strncpy(fUUID, uuid, sizeof(fUUID)-1);
}
int Read(detail::JackChannelTransactionInterface* trans)
......@@ -1505,8 +1529,10 @@ struct JackReserveNameRequest : public JackRequest
JackReserveNameRequest(int refnum, const char *name, const char* uuid)
: JackRequest(JackRequest::kReserveClientName), fRefNum(refnum)
{
strncpy(fName, name, sizeof(fName));
strncpy(fUUID, uuid, sizeof(fUUID));
memset(fName, 0, sizeof(fName));
memset(fUUID, 0, sizeof(fUUID));
strncpy(fName, name, sizeof(fName)-1);
strncpy(fUUID, uuid, sizeof(fUUID)-1);
}
int Read(detail::JackChannelTransactionInterface* trans)
......@@ -1541,7 +1567,8 @@ struct JackClientHasSessionCallbackRequest : public JackRequest
JackClientHasSessionCallbackRequest(const char *name)
: JackRequest(JackRequest::kClientHasSessionCallback)
{
strncpy(fName, name, sizeof(fName));
memset(fName, 0, sizeof(fName));
strncpy(fName, name, sizeof(fName)-1);
}
int Read(detail::JackChannelTransactionInterface* trans)
......@@ -1582,6 +1609,8 @@ struct JackClientNotification
JackClientNotification(const char* name, int refnum, int notify, int sync, const char* message, int value1, int value2)
: fRefNum(refnum), fNotify(notify), fValue1(value1), fValue2(value2), fSync(sync)
{
memset(fName, 0, sizeof(fName));
memset(fMessage, 0, sizeof(fMessage));
snprintf(fName, sizeof(fName), "%s", name);
snprintf(fMessage, sizeof(fMessage), "%s", message);
fSize = Size();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment