From: Piotr Maziarz <piotrx.maziarz@linux.intel.com>
To: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
alsa-devel@alsa-project.org
Cc: cezary.rojewski@intel.com, amadeuszx.slawinski@intel.com
Subject: Re: [PATCH alsa-lib 8/8] topology: Make buffer for saving dynamic size
Date: Thu, 2 Jul 2020 17:04:22 +0200 [thread overview]
Message-ID: <6b738835-3d9d-ae99-0ebb-b8c0215fb4bc@linux.intel.com> (raw)
In-Reply-To: <d764d947-ed85-1d66-ed4f-701b30d1e0a7@linux.intel.com>
On 2020-06-25 16:31, Pierre-Louis Bossart wrote:
>
>
> On 6/25/20 6:03 AM, Piotr Maziarz wrote:
>> Some fields can exceed size limit, e.g. private data has no size
>> restriction. Therefore it needs to be dynamically increased.
>>
>> Signed-off-by: Piotr Maziarz <piotrx.maziarz@linux.intel.com>
>> ---
>> src/topology/save.c | 36 ++++++++++++++++++++++++++++++------
>> 1 file changed, 30 insertions(+), 6 deletions(-)
>>
>> diff --git a/src/topology/save.c b/src/topology/save.c
>> index 4ecf86c..d6ee8b6 100644
>> --- a/src/topology/save.c
>> +++ b/src/topology/save.c
>> @@ -19,22 +19,43 @@
>> #include "tplg_local.h"
>> #define SAVE_ALLOC_SHIFT (13) /* 8192 bytes */
>> +#define PRINT_BUF_SIZE (1024)
>> +#define PRINT_BUF_SIZE_MAX (1024 * 1024)
>> int tplg_save_printf(char **dst, const char *pfx, const char *fmt, ...)
>> {
>> va_list va;
>> - char buf[1024], *s;
>> - size_t n, l, t, pl;
>> + char *buf, *s;
>> + size_t n, alloc_size = PRINT_BUF_SIZE, l, t, pl;
>> + int ret = 0;
>> +
>> + buf = malloc(alloc_size);
>> + if (!buf)
>> + return -ENOMEM;
>> if (pfx == NULL)
>> pfx = "";
>> +again:
>> va_start(va, fmt);
>> - n = vsnprintf(buf, sizeof(buf), fmt, va);
>> + n = vsnprintf(buf, alloc_size, fmt, va);
>> va_end(va);
>> - if (n >= sizeof(buf))
>> - return -EOVERFLOW;
>> + if (n >= PRINT_BUF_SIZE_MAX) {
>> + ret = -EOVERFLOW;
>> + goto end;
>> + }
>
> what this patch does is change the allocation limit from 1KB to 1MB, but
> the data still has no size restriction. At what point do we decide to
> throw an error?
>
If needed size is bigger than PRINT_BUF_SIZE_MAX there will be an error
thrown so I don't know what should I change here. Or do you mean that
private data size in binary should be restricted?
next prev parent reply other threads:[~2020-07-02 15:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-25 11:03 [PATCH alsa-lib 1/8] topology: decode: fix channel map memory allocation Piotr Maziarz
2020-06-25 11:03 ` [PATCH alsa-lib 2/8] topology: decode: Fix adding texts field to enum control Piotr Maziarz
2020-06-25 14:24 ` Pierre-Louis Bossart
2020-06-25 11:03 ` [PATCH alsa-lib 3/8] topology: decode: Fix printing texts section Piotr Maziarz
2020-06-25 11:03 ` [PATCH alsa-lib 4/8] topology: decode: Change declaration of enum decoding function Piotr Maziarz
2020-06-25 11:03 ` [PATCH alsa-lib 5/8] topology: decode: Fix decoding PCM formats and rates Piotr Maziarz
2020-06-25 11:03 ` [PATCH alsa-lib 6/8] topology: decode: Print sig_bits field in PCM capabilities section Piotr Maziarz
2020-06-25 11:03 ` [PATCH alsa-lib 7/8] topology: decode: Add DAI name printing Piotr Maziarz
2020-06-25 11:03 ` [PATCH alsa-lib 8/8] topology: Make buffer for saving dynamic size Piotr Maziarz
2020-06-25 14:31 ` Pierre-Louis Bossart
2020-07-02 15:04 ` Piotr Maziarz [this message]
2020-06-25 14:16 ` [PATCH alsa-lib 1/8] topology: decode: fix channel map memory allocation Pierre-Louis Bossart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6b738835-3d9d-ae99-0ebb-b8c0215fb4bc@linux.intel.com \
--to=piotrx.maziarz@linux.intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=amadeuszx.slawinski@intel.com \
--cc=cezary.rojewski@intel.com \
--cc=pierre-louis.bossart@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox