Message ID | 20200418041931.7534-1-lance.lmwang@gmail.com |
---|---|
State | Accepted |
Commit | 53c88355a5ae638b3a3cf93508c4741238dc6c7f |
Headers | show |
Series | [FFmpeg-devel,v1,1/2] avformat/ftp: Fix for invalid use of av_strtok | expand |
Context | Check | Description |
---|---|---|
andriy/default | pending | |
andriy/make | success | Make finished |
andriy/make_fate | success | Make fate finished |
On Sat, Apr 18, 2020 at 12:19:30PM +0800, lance.lmwang@gmail.com wrote: > From: Limin Wang <lance.lmwang@gmail.com> > > By the av_strtok() description: > * On the first call to av_strtok(), s should point to the string to > * parse, and the value of saveptr is ignored. In subsequent calls, s > * should be NULL, and saveptr should be unchanged since the previous > * call. > > Signed-off-by: Limin Wang <lance.lmwang@gmail.com> > --- > libavformat/ftp.c | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/libavformat/ftp.c b/libavformat/ftp.c > index e3d194d..caeea42 100644 > --- a/libavformat/ftp.c > +++ b/libavformat/ftp.c > @@ -333,15 +333,15 @@ static int ftp_passive_mode(FTPContext *s) > *end = '\0'; > /* skip ip */ > if (!av_strtok(start, ",", &end)) goto fail; > - if (!av_strtok(end, ",", &end)) goto fail; > - if (!av_strtok(end, ",", &end)) goto fail; > - if (!av_strtok(end, ",", &end)) goto fail; > + if (!av_strtok(NULL, ",", &end)) goto fail; > + if (!av_strtok(NULL, ",", &end)) goto fail; > + if (!av_strtok(NULL, ",", &end)) goto fail; > > /* parse port number */ > - start = av_strtok(end, ",", &end); > + start = av_strtok(NULL, ",", &end); > if (!start) goto fail; > s->server_data_port = atoi(start) * 256; > - start = av_strtok(end, ",", &end); > + start = av_strtok(NULL, ",", &end); > if (!start) goto fail; > s->server_data_port += atoi(start); > ff_dlog(s, "Server data port: %d\n", s->server_data_port); > @@ -963,8 +963,10 @@ static int ftp_parse_entry_nlst(char *line, AVIODirEntry *next) > static int ftp_parse_entry_mlsd(char *mlsd, AVIODirEntry *next) > { > char *fact, *value; > + char *saveptr = NULL, *p = mlsd; > ff_dlog(NULL, "%s\n", mlsd); > - while(fact = av_strtok(mlsd, ";", &mlsd)) { > + while(fact = av_strtok(p, ";", &saveptr)) { > + p = NULL; > if (fact[0] == ' ') { > next->name = av_strdup(&fact[1]); > continue; > -- > 2.9.5 > ping the patchset. Please see the discussion of av_strtok from here: https://patchwork.ffmpeg.org/project/ffmpeg/patch/20200417141315.17560-1-lance.lmwang@gmail.com/
On Sat, Apr 18, 2020 at 12:19:30PM +0800, lance.lmwang@gmail.com wrote: > From: Limin Wang <lance.lmwang@gmail.com> > > By the av_strtok() description: > * On the first call to av_strtok(), s should point to the string to > * parse, and the value of saveptr is ignored. In subsequent calls, s > * should be NULL, and saveptr should be unchanged since the previous > * call. > > Signed-off-by: Limin Wang <lance.lmwang@gmail.com> > --- > libavformat/ftp.c | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/libavformat/ftp.c b/libavformat/ftp.c > index e3d194d..caeea42 100644 > --- a/libavformat/ftp.c > +++ b/libavformat/ftp.c > @@ -333,15 +333,15 @@ static int ftp_passive_mode(FTPContext *s) > *end = '\0'; > /* skip ip */ > if (!av_strtok(start, ",", &end)) goto fail; > - if (!av_strtok(end, ",", &end)) goto fail; > - if (!av_strtok(end, ",", &end)) goto fail; > - if (!av_strtok(end, ",", &end)) goto fail; > + if (!av_strtok(NULL, ",", &end)) goto fail; > + if (!av_strtok(NULL, ",", &end)) goto fail; > + if (!av_strtok(NULL, ",", &end)) goto fail; > > /* parse port number */ > - start = av_strtok(end, ",", &end); > + start = av_strtok(NULL, ",", &end); > if (!start) goto fail; > s->server_data_port = atoi(start) * 256; > - start = av_strtok(end, ",", &end); > + start = av_strtok(NULL, ",", &end); > if (!start) goto fail; > s->server_data_port += atoi(start); > ff_dlog(s, "Server data port: %d\n", s->server_data_port); > @@ -963,8 +963,10 @@ static int ftp_parse_entry_nlst(char *line, AVIODirEntry *next) > static int ftp_parse_entry_mlsd(char *mlsd, AVIODirEntry *next) > { > char *fact, *value; > + char *saveptr = NULL, *p = mlsd; > ff_dlog(NULL, "%s\n", mlsd); > - while(fact = av_strtok(mlsd, ";", &mlsd)) { > + while(fact = av_strtok(p, ";", &saveptr)) { > + p = NULL; > if (fact[0] == ' ') { > next->name = av_strdup(&fact[1]); > continue; > -- > 2.9.5 > will apply the patchset tomorrow if no more comments.
diff --git a/libavformat/ftp.c b/libavformat/ftp.c index e3d194d..caeea42 100644 --- a/libavformat/ftp.c +++ b/libavformat/ftp.c @@ -333,15 +333,15 @@ static int ftp_passive_mode(FTPContext *s) *end = '\0'; /* skip ip */ if (!av_strtok(start, ",", &end)) goto fail; - if (!av_strtok(end, ",", &end)) goto fail; - if (!av_strtok(end, ",", &end)) goto fail; - if (!av_strtok(end, ",", &end)) goto fail; + if (!av_strtok(NULL, ",", &end)) goto fail; + if (!av_strtok(NULL, ",", &end)) goto fail; + if (!av_strtok(NULL, ",", &end)) goto fail; /* parse port number */ - start = av_strtok(end, ",", &end); + start = av_strtok(NULL, ",", &end); if (!start) goto fail; s->server_data_port = atoi(start) * 256; - start = av_strtok(end, ",", &end); + start = av_strtok(NULL, ",", &end); if (!start) goto fail; s->server_data_port += atoi(start); ff_dlog(s, "Server data port: %d\n", s->server_data_port); @@ -963,8 +963,10 @@ static int ftp_parse_entry_nlst(char *line, AVIODirEntry *next) static int ftp_parse_entry_mlsd(char *mlsd, AVIODirEntry *next) { char *fact, *value; + char *saveptr = NULL, *p = mlsd; ff_dlog(NULL, "%s\n", mlsd); - while(fact = av_strtok(mlsd, ";", &mlsd)) { + while(fact = av_strtok(p, ";", &saveptr)) { + p = NULL; if (fact[0] == ' ') { next->name = av_strdup(&fact[1]); continue;