Skip to content

Commit

Permalink
Raspistill: Ensure filename doesn't contain invalid % expansions
Browse files Browse the repository at this point in the history
#142
Check that the output filename does not include %<char>
other than %% or %d as it is fed into sprintf for adding
the timelapse frame number.
  • Loading branch information
6by9 committed Jan 6, 2016
1 parent 5696391 commit 1d2a203
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions host_applications/linux/apps/raspicam/RaspiStill.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,25 @@ static int parse_cmdline(int argc, const char **argv, RASPISTILL_STATE *state)
int len = strlen(argv[i + 1]);
if (len)
{
//We use sprintf to append the frame number for timelapse mode
//Ensure that any %<char> is either %% or %d.
char *percent = argv[i+1];
while(valid && *percent && (percent=strchr(percent, '%')) != NULL)
{
int digits=0;
percent++;
while(isdigit(*percent))
{
percent++;
digits++;
}
if(!((*percent == '%' && !digits) || *percent == 'd'))
{
valid = 0;
fprintf(stderr, "Filename contains %% characters, but not %%d or %%%% - sorry, will fail\n");
}
percent++;
}
state->filename = malloc(len + 10); // leave enough space for any timelapse generated changes to filename
vcos_assert(state->filename);
if (state->filename)
Expand Down

0 comments on commit 1d2a203

Please sign in to comment.