1
Fork 0

use port name buffer of actual max size; print warning on truncation

https://gna.org/support/index.php?2526
This commit is contained in:
Nedko Arnaudov 2010-04-04 23:16:15 +03:00
parent 5cc10a0954
commit 5cdb8646cf
3 changed files with 19 additions and 6 deletions

View File

@ -57,6 +57,7 @@ bool g_keep_alsa_walking = false;
bool g_stop_request = false;
static bool g_started = false;
struct a2j * g_a2j = NULL;
size_t g_max_jack_port_name_size;
bool g_a2j_export_hw_ports = false;
char * g_a2j_jack_server_name = "default";
@ -435,6 +436,8 @@ main(
ctime_r(&st.st_mtime, timestamp_str);
timestamp_str[24] = 0;
g_max_jack_port_name_size = jack_port_name_size();
if (!a2j_paths_init())
{
goto fail;

18
port.c
View File

@ -107,12 +107,13 @@ a2j_port_fill_name(
bool make_unique)
{
char *c;
int ret;
if (make_unique)
{
snprintf(
ret = snprintf(
port_ptr->name,
sizeof(port_ptr->name),
g_max_jack_port_name_size,
"%s [%d] (%s): %s",
snd_seq_client_info_get_name(client_info_ptr),
snd_seq_client_info_get_client(client_info_ptr),
@ -121,9 +122,9 @@ a2j_port_fill_name(
}
else
{
snprintf(
ret = snprintf(
port_ptr->name,
sizeof(port_ptr->name),
g_max_jack_port_name_size,
"%s (%s): %s",
snd_seq_client_info_get_name(client_info_ptr),
type == A2J_PORT_CAPTURE ? "capture": "playback",
@ -134,6 +135,13 @@ a2j_port_fill_name(
for (c = port_ptr->name; *c; ++c)
if (!JACK_IS_VALID_PORT_NAME_CHAR(*c))
*c = ' ';
if (ret < 0 || ret >= g_max_jack_port_name_size)
{
/* force terminating nul char because the man page does not specify whether the resulting buffer is nul terminated in this case */
port_ptr->name[g_max_jack_port_name_size] = 0;
a2j_warning("port name \"%s\" was truncated because of the max size support by JACK (%zu)", port_ptr->name, g_max_jack_port_name_size);
}
}
struct a2j_port *
@ -171,7 +179,7 @@ a2j_port_create(
a2j_debug("client name: '%s'", snd_seq_client_info_get_name(client_info_ptr));
a2j_debug("port name: '%s'", snd_seq_port_info_get_name(info));
port = calloc(1, sizeof(struct a2j_port));
port = calloc(1, sizeof(struct a2j_port) + g_max_jack_port_name_size);
if (!port)
{
goto fail_free_client_info;

View File

@ -43,7 +43,6 @@ struct a2j_port
struct list_head siblings; /* list - main loop */
struct a2j * a2j_ptr;
bool is_dead;
char name[64];
snd_seq_addr_t remote;
jack_port_t * jack_port;
@ -51,6 +50,7 @@ struct a2j_port
int64_t last_out_time;
void * jack_buf;
char name[0];
};
struct a2j_stream
@ -124,4 +124,6 @@ struct a2j_delivery_event
extern struct a2j * g_a2j;
extern size_t g_max_jack_port_name_size;
#endif /* #ifndef STRUCTS_H__FD2CC895_411F_4ADE_9200_50FE395EDB72__INCLUDED */