mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
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:
parent
2bcc6b96ea
commit
1d5f816874
2 changed files with 42 additions and 9 deletions
|
|
@ -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 */
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue