Skip to content

Commit

Permalink
解决 parse_params 缓冲区溢出问题,解决 ffrdp & avkcp android 平台 app 退出时报错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
rockcarry committed Nov 25, 2020
1 parent d9db96b commit c5015e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion avkcpdemuxer/avkcpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static char* parse_params(const char *str, const char *key, char *val, int len)
}
val[i] = *p++;
}
val[i] = val[len-1] = '\0';
val[i < len ? i : len - 1] = '\0';
return val;
}

Expand Down Expand Up @@ -157,6 +157,8 @@ static int avkcpc_callback(void *ctxt, int type, char *rbuf, int rbsize, int rbh
if (avcodec_open2(hwctxt, hwdec, NULL) == 0) {
*avkcpd->vcodec_context = hwctxt;
} else {
hwctxt->extradata_size = 0;
hwctxt->extradata = NULL;
avkcpd->cmnvars->init_params->video_hwaccel = 0;
avcodec_close(hwctxt);
avcodec_free_context(&hwctxt);
Expand Down Expand Up @@ -260,6 +262,8 @@ void avkcpdemuxer_exit(void *ctxt)
{
AVKCPDEMUXER *avkcpd = (AVKCPDEMUXER*)ctxt;
if (avkcpd) {
(*avkcpd->vcodec_context)->extradata_size = 0;
(*avkcpd->vcodec_context)->extradata = NULL;
avcodec_close(*avkcpd->acodec_context);
avcodec_close(*avkcpd->vcodec_context);
avcodec_free_context(avkcpd->acodec_context);
Expand Down
6 changes: 5 additions & 1 deletion ffrdpdemuxer/ffrdpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static char* parse_params(const char *str, const char *key, char *val, int len)
}
val[i] = *p++;
}
val[i] = val[len-1] = '\0';
val[i < len ? i : len - 1] = '\0';
return val;
}

Expand Down Expand Up @@ -158,6 +158,8 @@ static int ffrdpc_callback(void *ctxt, int type, char *rbuf, int rbsize, int rbh
if (avcodec_open2(hwctxt, hwdec, NULL) == 0) {
*ffrdpd->vcodec_context = hwctxt;
} else {
hwctxt->extradata_size = 0;
hwctxt->extradata = NULL;
ffrdpd->cmnvars->init_params->video_hwaccel = 0;
avcodec_close(hwctxt);
avcodec_free_context(&hwctxt);
Expand Down Expand Up @@ -261,6 +263,8 @@ void ffrdpdemuxer_exit(void *ctxt)
{
FFRDPDEMUXER *ffrdpd = (FFRDPDEMUXER*)ctxt;
if (ffrdpd) {
(*ffrdpd->vcodec_context)->extradata_size = 0;
(*ffrdpd->vcodec_context)->extradata = NULL;
avcodec_close(*ffrdpd->acodec_context);
avcodec_close(*ffrdpd->vcodec_context);
avcodec_free_context(ffrdpd->acodec_context);
Expand Down
2 changes: 1 addition & 1 deletion src/ffplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ static char* parse_params(const char *str, const char *key, char *val, int len)
}
val[i] = *p++;
}
val[i] = val[len-1] = '\0';
val[i < len ? i : len - 1] = '\0';
return val;
}

Expand Down

0 comments on commit c5015e9

Please sign in to comment.