system: audio: parse command filenames with PATH_MAX

Parse command filename tokens into PATH_MAX-sized buffers before
reading optional raw audio parameters. This bounds nxplayer and
nxrecorder input without runtime-built scanf formats.

Signed-off-by: Old-Ding <35417409+Old-Ding@users.noreply.github.com>
This commit is contained in:
Old-Ding 2026-07-11 00:19:13 +08:00 committed by Alan C. Assis
parent 2bcc6b96ea
commit 1d5f816874
2 changed files with 42 additions and 9 deletions

View file

@ -317,10 +317,21 @@ static int nxplayer_cmd_playraw(FAR struct nxplayer_s *pplayer, char *parg)
int bpsamp = 0;
int samprate = 0;
int chmap = 0;
char filename[128];
size_t len;
char filename[PATH_MAX];
sscanf(parg, "%s %d %d %d %d", filename, &channels, &bpsamp,
&samprate, &chmap);
parg += strspn(parg, " \t\r\n");
len = strcspn(parg, " \t\r\n");
if (len >= sizeof(filename))
{
len = sizeof(filename) - 1;
}
memcpy(filename, parg, len);
filename[len] = '\0';
sscanf(parg + len, "%d %d %d %d", &channels, &bpsamp,
&samprate, &chmap);
/* Try to play the file specified */

View file

@ -190,10 +190,21 @@ static int nxrecorder_cmd_recordraw(FAR struct nxrecorder_s *precorder,
int bpsamp = 0;
int samprate = 0;
int chmap = 0;
char filename[128];
size_t len;
char filename[PATH_MAX];
sscanf(parg, "%s %d %d %d %d", filename, &channels, &bpsamp,
&samprate, &chmap);
parg += strspn(parg, " \t\r\n");
len = strcspn(parg, " \t\r\n");
if (len >= sizeof(filename))
{
len = sizeof(filename) - 1;
}
memcpy(filename, parg, len);
filename[len] = '\0';
sscanf(parg + len, "%d %d %d %d", &channels, &bpsamp,
&samprate, &chmap);
/* Try to record the file specified */
@ -259,10 +270,21 @@ static int nxrecorder_cmd_record(FAR struct nxrecorder_s *precorder,
int bpsamp = 0;
int samprate = 0;
int chmap = 0;
char filename[128];
size_t len;
char filename[PATH_MAX];
sscanf(parg, "%s %d %d %d %d", filename, &channels, &bpsamp,
&samprate, &chmap);
parg += strspn(parg, " \t\r\n");
len = strcspn(parg, " \t\r\n");
if (len >= sizeof(filename))
{
len = sizeof(filename) - 1;
}
memcpy(filename, parg, len);
filename[len] = '\0';
sscanf(parg + len, "%d %d %d %d", &channels, &bpsamp,
&samprate, &chmap);
/* Try to record the file specified */