Skip to content

Commit

Permalink
ug_input: refuse non-numeric opt
Browse files Browse the repository at this point in the history
Currently only port number is accepted - refuse any option that doesn't
match this.

\+ created a separate function for parsing
  • Loading branch information
MartinPulec committed Oct 30, 2023
1 parent f4aeae0 commit 6d548ac
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/video_capture/ug_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ void ug_input_state::frame_arrived(struct video_frame *f, struct audio_frame *a)
}
}

static bool
parse_fmt(const char *fmt, uint16_t *port)
{
if (fmt[0] == '\0') {
return true;
}
if (!isdigit(fmt[0])) {
MSG(ERROR, "Invalid option: %s\n", fmt);
return false;
}
*port = stoi(fmt);
return true;
}

static int vidcap_ug_input_init(struct vidcap_params *cap_params, void **state)
{
uint16_t port = 5004;
Expand All @@ -109,12 +123,12 @@ static int vidcap_ug_input_init(struct vidcap_params *cap_params, void **state)
printf("\t-t ug_input[:<port>] [-s embedded]\n");
return VIDCAP_INIT_NOERR;
}
ug_input_state *s = new ug_input_state();

if (isdigit(vidcap_params_get_fmt(cap_params)[0])) {
port = atoi(vidcap_params_get_fmt(cap_params));
if (!parse_fmt(vidcap_params_get_fmt(cap_params), &port)) {
return VIDCAP_INIT_FAIL;
}

auto *s = new ug_input_state();

char cfg[128] = "";
snprintf(cfg, sizeof cfg, "%p", s);
int ret = initialize_video_display(vidcap_params_get_parent(cap_params), "pipe", cfg, 0, NULL, &s->display);
Expand Down

0 comments on commit 6d548ac

Please sign in to comment.