Skip to content

Commit

Permalink
MT#55283 always use full-struct initialisation
Browse files Browse the repository at this point in the history
Avoids uninitialised values.

Closes #1873

Identified by Alexandru Pirvulescu <[email protected]>

Change-Id: Ie7019c2f762b6f163d6d27c519513f6898e1571c
Ref: #1873
Thanks: Alexandru Pirvulescu <[email protected]>
(cherry picked from commit 38985b9)
(cherry picked from commit 397b11e)
  • Loading branch information
rfuchs committed Oct 22, 2024
1 parent 17cac8b commit 5ed335d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 42 deletions.
89 changes: 48 additions & 41 deletions daemon/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,31 +83,31 @@ bool kernel_init_table(void) {
if (!kernel.is_open)
return true;

struct rtpengine_command_init cmd;
ssize_t ret;

cmd.cmd = REMG_INIT;

cmd.init = (struct rtpengine_init_info) {
.last_cmd = __REMG_LAST,
.msg_size = {
[REMG_INIT] = sizeof(struct rtpengine_command_init),
[REMG_ADD_TARGET] = sizeof(struct rtpengine_command_add_target),
[REMG_DEL_TARGET] = sizeof(struct rtpengine_command_del_target),
[REMG_ADD_DESTINATION] = sizeof(struct rtpengine_command_destination),
[REMG_ADD_CALL] = sizeof(struct rtpengine_command_add_call),
[REMG_DEL_CALL] = sizeof(struct rtpengine_command_del_call),
[REMG_ADD_STREAM] = sizeof(struct rtpengine_command_add_stream),
[REMG_DEL_STREAM] = sizeof(struct rtpengine_command_del_stream),
[REMG_PACKET] = sizeof(struct rtpengine_command_packet),
[REMG_INIT_PLAY_STREAMS] = sizeof(struct rtpengine_command_init_play_streams),
[REMG_GET_PACKET_STREAM] = sizeof(struct rtpengine_command_get_packet_stream),
[REMG_PLAY_STREAM_PACKET] = sizeof(struct rtpengine_command_play_stream_packet),
[REMG_PLAY_STREAM] = sizeof(struct rtpengine_command_play_stream),
[REMG_STOP_STREAM] = sizeof(struct rtpengine_command_stop_stream),
[REMG_FREE_PACKET_STREAM] = sizeof(struct rtpengine_command_free_packet_stream),
struct rtpengine_command_init cmd = {
.cmd = REMG_INIT,
.init = {
.last_cmd = __REMG_LAST,
.msg_size = {
[REMG_INIT] = sizeof(struct rtpengine_command_init),
[REMG_ADD_TARGET] = sizeof(struct rtpengine_command_add_target),
[REMG_DEL_TARGET] = sizeof(struct rtpengine_command_del_target),
[REMG_ADD_DESTINATION] = sizeof(struct rtpengine_command_destination),
[REMG_ADD_CALL] = sizeof(struct rtpengine_command_add_call),
[REMG_DEL_CALL] = sizeof(struct rtpengine_command_del_call),
[REMG_ADD_STREAM] = sizeof(struct rtpengine_command_add_stream),
[REMG_DEL_STREAM] = sizeof(struct rtpengine_command_del_stream),
[REMG_PACKET] = sizeof(struct rtpengine_command_packet),
[REMG_INIT_PLAY_STREAMS] = sizeof(struct rtpengine_command_init_play_streams),
[REMG_GET_PACKET_STREAM] = sizeof(struct rtpengine_command_get_packet_stream),
[REMG_PLAY_STREAM_PACKET] = sizeof(struct rtpengine_command_play_stream_packet),
[REMG_PLAY_STREAM] = sizeof(struct rtpengine_command_play_stream),
[REMG_STOP_STREAM] = sizeof(struct rtpengine_command_stop_stream),
[REMG_FREE_PACKET_STREAM] = sizeof(struct rtpengine_command_free_packet_stream),
},
.rtpe_stats = rtpe_stats,
},
.rtpe_stats = rtpe_stats,
};

ret = write(kernel.fd, &cmd, sizeof(cmd));
Expand Down Expand Up @@ -159,14 +159,15 @@ void kernel_shutdown_table(void) {


void kernel_add_stream(struct rtpengine_target_info *mti) {
struct rtpengine_command_add_target cmd;
ssize_t ret;

if (!kernel.is_open)
return;

cmd.cmd = REMG_ADD_TARGET;
cmd.target = *mti;
struct rtpengine_command_add_target cmd = {
.cmd = REMG_ADD_TARGET,
.target = *mti,
};

ret = write(kernel.fd, &cmd, sizeof(cmd));
if (ret == sizeof(cmd))
Expand All @@ -176,14 +177,15 @@ void kernel_add_stream(struct rtpengine_target_info *mti) {
}

void kernel_add_destination(struct rtpengine_destination_info *mdi) {
struct rtpengine_command_destination cmd;
ssize_t ret;

if (!kernel.is_open)
return;

cmd.cmd = REMG_ADD_DESTINATION;
cmd.destination = *mdi;
struct rtpengine_command_destination cmd = {
.cmd = REMG_ADD_DESTINATION,
.destination = *mdi,
};

ret = write(kernel.fd, &cmd, sizeof(cmd));
if (ret == sizeof(cmd))
Expand All @@ -210,13 +212,14 @@ bool kernel_del_stream(struct rtpengine_command_del_target *cmd) {
}

unsigned int kernel_add_call(const char *id) {
struct rtpengine_command_add_call cmd;
ssize_t ret;

if (!kernel.is_open)
return UNINIT_IDX;

cmd.cmd = REMG_ADD_CALL;
struct rtpengine_command_add_call cmd = {
.cmd = REMG_ADD_CALL,
};
snprintf(cmd.call.call_id, sizeof(cmd.call.call_id), "%s", id);

ret = read(kernel.fd, &cmd, sizeof(cmd));
Expand All @@ -226,14 +229,15 @@ unsigned int kernel_add_call(const char *id) {
}

void kernel_del_call(unsigned int idx) {
struct rtpengine_command_del_call cmd;
ssize_t ret;

if (!kernel.is_open)
return;

cmd.cmd = REMG_DEL_CALL;
cmd.call_idx = idx;
struct rtpengine_command_del_call cmd = {
.cmd = REMG_DEL_CALL,
.call_idx = idx,
};

ret = write(kernel.fd, &cmd, sizeof(cmd));
if (ret == sizeof(cmd))
Expand All @@ -243,14 +247,15 @@ void kernel_del_call(unsigned int idx) {
}

unsigned int kernel_add_intercept_stream(unsigned int call_idx, const char *id) {
struct rtpengine_command_add_stream cmd;
ssize_t ret;

if (!kernel.is_open)
return UNINIT_IDX;

cmd.cmd = REMG_ADD_STREAM;
cmd.stream.idx.call_idx = call_idx;
struct rtpengine_command_add_stream cmd = {
.cmd = REMG_ADD_STREAM,
.stream.idx.call_idx = call_idx,
};
snprintf(cmd.stream.stream_name, sizeof(cmd.stream.stream_name), "%s", id);

ret = read(kernel.fd, &cmd, sizeof(cmd));
Expand Down Expand Up @@ -299,11 +304,13 @@ bool kernel_add_stream_packet(unsigned int idx, const char *buf, size_t len, uns
size_t total_len = len + sizeof(struct rtpengine_command_play_stream_packet);
struct rtpengine_command_play_stream_packet *cmd = alloca(total_len);

cmd->cmd = REMG_PLAY_STREAM_PACKET;
cmd->play_stream_packet.packet_stream_idx = idx;
cmd->play_stream_packet.delay_ms = delay_ms;
cmd->play_stream_packet.delay_ts = ts;
cmd->play_stream_packet.duration_ts = dur;
*cmd = (__typeof__(*cmd)) {
.cmd = REMG_PLAY_STREAM_PACKET,
.play_stream_packet.packet_stream_idx = idx,
.play_stream_packet.delay_ms = delay_ms,
.play_stream_packet.delay_ts = ts,
.play_stream_packet.duration_ts = dur,
};

memcpy(&cmd->play_stream_packet.data, buf, len);

Expand Down
2 changes: 1 addition & 1 deletion daemon/media_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@ void __unkernelize(struct packet_stream *p, const char *reason) {
ilog(LOG_INFO, "Removing media stream from kernel: local %s (%s)",
endpoint_print_buf(&p->selected_sfd->socket.local),
reason);
struct rtpengine_command_del_target cmd;
struct rtpengine_command_del_target cmd = {0};
__re_address_translate_ep(&cmd.local, &p->selected_sfd->socket.local);
kernel_del_stream(&cmd);
}
Expand Down

0 comments on commit 5ed335d

Please sign in to comment.