aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/ftp.c
diff options
context:
space:
mode:
authorMariusz SzczepaƄczyk <mszczepanczyk@gmail.com>2015-08-09 02:38:11 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2015-08-10 18:23:40 +0200
commitee44cb3c81a9e471935ced59bee3d5ff51a1fcbe (patch)
treedbda768826236df77c1e1b06814434f54f6e294a /libavformat/ftp.c
parentbc9305316142a4af22593698c728db2d5db59ab8 (diff)
downloadffmpeg-ee44cb3c81a9e471935ced59bee3d5ff51a1fcbe.tar.gz
lavf/ftp: properly read an empty path
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavformat/ftp.c')
-rw-r--r--libavformat/ftp.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/libavformat/ftp.c b/libavformat/ftp.c
index c92ed11d86..542cf6a862 100644
--- a/libavformat/ftp.c
+++ b/libavformat/ftp.c
@@ -354,10 +354,7 @@ static int ftp_current_dir(FTPContext *s)
if (!end)
goto fail;
- if (end > res && end[-1] == '/') {
- end[-1] = '\0';
- } else
- *end = '\0';
+ *end = '\0';
s->path = av_strdup(start);
av_free(res);
@@ -605,9 +602,8 @@ static int ftp_connect(URLContext *h, const char *url)
{
char proto[10], path[MAX_URL_SIZE], credencials[MAX_URL_SIZE], hostname[MAX_URL_SIZE];
const char *tok_user = NULL, *tok_pass = NULL;
- char *end = NULL;
+ char *end = NULL, *newpath = NULL;
int err;
- size_t pathlen;
FTPContext *s = h->priv_data;
s->state = DISCONNECTED;
@@ -642,10 +638,12 @@ static int ftp_connect(URLContext *h, const char *url)
if ((err = ftp_current_dir(s)) < 0)
return err;
- pathlen = strlen(s->path) + strlen(path) + 1;
- if ((err = av_reallocp(&s->path, pathlen)) < 0)
- return err;
- av_strlcat(s->path + strlen(s->path), path, pathlen);
+
+ newpath = av_append_path_component(s->path, path);
+ if (!newpath)
+ return AVERROR(ENOMEM);
+ av_free(s->path);
+ s->path = newpath;
return 0;
}