acp: improve debug of channel map

Increase the size of the channel_map debug printf buffer.
Use a safer version of the snprintf that avoids buffer overruns.

See #1781
This commit is contained in:
Wim Taymans 2021-11-04 16:41:32 +01:00
parent efd8ac25e3
commit 86ca0f8466
3 changed files with 41 additions and 4 deletions

View file

@ -29,7 +29,7 @@ extern "C" {
#define PA_CHANNELS_MAX 64
#define PA_CHANNEL_MAP_SNPRINT_MAX 336
#define PA_CHANNEL_MAP_SNPRINT_MAX (PA_CHANNELS_MAX * 32)
typedef enum pa_channel_map_def {
PA_CHANNEL_MAP_AIFF,

View file

@ -280,7 +280,44 @@ static inline PA_PRINTF_FUNC(5, 6) void pa_log_level_meta(enum pa_log_level leve
#define pa_strnull(s) ((s) ? (s) : "null")
#define pa_startswith(s,pfx) (strstr(s, pfx) == s)
#define pa_snprintf snprintf
PA_PRINTF_FUNC(3, 0)
static inline size_t pa_vsnprintf(char *str, size_t size, const char *format, va_list ap)
{
int ret;
pa_assert(str);
pa_assert(size > 0);
pa_assert(format);
ret = vsnprintf(str, size, format, ap);
str[size-1] = 0;
if (ret < 0)
return strlen(str);
if ((size_t) ret > size-1)
return size-1;
return (size_t) ret;
}
PA_PRINTF_FUNC(3, 4)
static inline size_t pa_snprintf(char *str, size_t size, const char *format, ...)
{
size_t ret;
va_list ap;
pa_assert(str);
pa_assert(size > 0);
pa_assert(format);
va_start(ap, format);
ret = pa_vsnprintf(str, size, format, ap);
va_end(ap);
return ret;
}
#define pa_xstrdup(s) ((s) != NULL ? strdup(s) : NULL)
#define pa_xstrndup(s,n) ((s) != NULL ? strndup(s,n) : NULL)

View file

@ -224,7 +224,7 @@ static char* channel_map_snprint(char *s, size_t l, const struct channel_map *ma
*(e = s) = 0;
for (channel = 0; channel < map->channels && l > 1; channel++) {
l -= snprintf(e, l, "%s%s",
l -= spa_scnprintf(e, l, "%s%s",
first ? "" : ",",
channel_id2paname(map->map[channel], &aux));
@ -381,7 +381,7 @@ static void service_entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupStat
}
}
#define PA_CHANNEL_MAP_SNPRINT_MAX 336
#define PA_CHANNEL_MAP_SNPRINT_MAX (CHANNELS_MAX * 32)
static void publish_service(struct service *s)
{