[FFmpeg-devel] [PATCH 3/4] lavu/avstring: add av_append_path_component() funcion

Michael Niedermayer michaelni at gmx.at
Wed Apr 1 00:43:30 CEST 2015


On Tue, Mar 31, 2015 at 10:47:44PM +0200, Mariusz Szczepańczyk wrote:
> On Mon, Mar 30, 2015 at 12:38 AM, Michael Niedermayer <michaelni at gmx.at>
> wrote:
> 
> > On Thu, Mar 26, 2015 at 05:39:49PM +0100, Mariusz Szczepańczyk wrote:
> > > On Thu, Mar 26, 2015 at 3:40 PM, Michael Niedermayer <michaelni at gmx.at>
> > > wrote:
> > >
> > > > On Thu, Mar 26, 2015 at 01:25:19AM +0100, Mariusz Szczepańczyk wrote:
> > > > > From: Lukasz Marek <lukasz.m.luki2 at gmail.com>
> > > > >
> > > > > Convinient function to build paths.
> > > > > ---
> > > > >  libavutil/avstring.c    | 43
> > +++++++++++++++++++++++++++++++++++++++++++
> > > > >  libavutil/avstring.h    | 10 ++++++++++
> > > > >  tests/ref/fate/avstring |  9 +++++++++
> > > > >  3 files changed, 62 insertions(+)
> > > > >
> > > > > diff --git a/libavutil/avstring.c b/libavutil/avstring.c
> > > > > index 25c65b4..f105aa7 100644
> > > > > --- a/libavutil/avstring.c
> > > > > +++ b/libavutil/avstring.c
> > > > > @@ -269,6 +269,35 @@ const char *av_dirname(char *path)
> > > > >      return path;
> > > > >  }
> > > > >
> > > > > +char *av_append_path_component(const char *path, const char
> > *component)
> > > > > +{
> > > > > +    size_t p_len, c_len;
> > > > > +    char *fullpath;
> > > > > +
> > > > > +    if (!path)
> > > > > +        return component ? av_strdup(component) : NULL;
> > > > > +    if (!component)
> > > > > +        return av_strdup(path);
> > > > > +
> > > > > +    p_len = strlen(path);
> > > > > +    c_len = strlen(component);
> > > >
> > > > > +    fullpath = malloc(p_len + c_len + 2);
> > > >
> > > > av_malloc()
> > > >
> > > >
> > > fixed
> > >
> > >
> > > > > +    if (fullpath) {
> > > > > +        if (p_len) {
> > > >
> > > > > +            strcpy(fullpath, path);
> > > >
> > > > av_strlcpy() is more robust/secure
> > > >
> > > >
> > > fixed
> > >
> > >
> > > >
> > > > > +            if (c_len) {
> > > > > +                if (fullpath[p_len - 1] != '/' && component[0] !=
> > '/')
> > > > > +                    fullpath[p_len++] = '/';
> > > > > +                else if (fullpath[p_len - 1] == '/' && component[0]
> > ==
> > > > '/')
> > > > > +                    p_len--;
> > > > > +            }
> > > > > +        }
> > > > > +        strcpy(&fullpath[p_len], component);
> > > >
> > > > av_strlcpy()
> > > >
> > >
> > > fixed
> > >
> > >
> > > Mariusz
> >
> > >  libavutil/avstring.c    |   43
> > +++++++++++++++++++++++++++++++++++++++++++
> > >  libavutil/avstring.h    |   10 ++++++++++
> > >  tests/ref/fate/avstring |    9 +++++++++
> > >  3 files changed, 62 insertions(+)
> > > 63e9d3c9f993fff81fbbb734a1e4d2728ebf85eb
> > 0003-lavu-avstring-add-av_append_path_component-funcion.patch
> > > From a79c0aceef2d3c9f51973958910bed773462fdd8 Mon Sep 17 00:00:00 2001
> > > From: Lukasz Marek <lukasz.m.luki2 at gmail.com>
> > > Date: Sat, 5 Jul 2014 18:12:02 +0200
> > > Subject: [PATCH 3/4] lavu/avstring: add av_append_path_component()
> > funcion
> > >
> > > Convinient function to build paths.
> > > ---
> > >  libavutil/avstring.c    | 43 +++++++++++++++++++++++++++++++++++++++++++
> > >  libavutil/avstring.h    | 10 ++++++++++
> > >  tests/ref/fate/avstring |  9 +++++++++
> > >  3 files changed, 62 insertions(+)
> > >
> > > diff --git a/libavutil/avstring.c b/libavutil/avstring.c
> > > index 25c65b4..24bc23a 100644
> > > --- a/libavutil/avstring.c
> > > +++ b/libavutil/avstring.c
> > > @@ -269,6 +269,35 @@ const char *av_dirname(char *path)
> > >      return path;
> > >  }
> > >
> > > +char *av_append_path_component(const char *path, const char *component)
> > > +{
> > > +    size_t p_len, c_len;
> > > +    char *fullpath;
> > > +
> > > +    if (!path)
> > > +        return component ? av_strdup(component) : NULL;
> >
> > the NULL check before av_strdup should not be needed
> >
> >
> ok
> 
> 
> >
> > > +    if (!component)
> > > +        return av_strdup(path);
> > > +
> > > +    p_len = strlen(path);
> > > +    c_len = strlen(component);
> > > +    fullpath = av_malloc(p_len + c_len + 2);
> >
> > this needs a check for potential integer overflow of the additions
> >
> 
> Added checking.
> 
> New patch also updates version.h and APIchanges.
> 
> Regards,
> Mariusz

>  doc/APIchanges          |    3 +++
>  libavutil/avstring.c    |   45 +++++++++++++++++++++++++++++++++++++++++++++
>  libavutil/avstring.h    |   10 ++++++++++
>  libavutil/version.h     |    2 +-
>  tests/ref/fate/avstring |    9 +++++++++
>  5 files changed, 68 insertions(+), 1 deletion(-)
> c78c3f0222bc75a34aa73b884148b6cf5246a599  0003-lavu-avstring-add-av_append_path_component-funcion.patch
> From 86ecd3c3f56426e7860399724147bee15d26bbcc Mon Sep 17 00:00:00 2001
> From: Lukasz Marek <lukasz.m.luki2 at gmail.com>
> Date: Sat, 5 Jul 2014 18:12:02 +0200
> Subject: [PATCH 1/2] lavu/avstring: add av_append_path_component() funcion
> 
> Convinient function to build paths.

applied

thanks

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The educated differ from the uneducated as much as the living from the
dead. -- Aristotle 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150401/43e5a5e3/attachment.asc>


More information about the ffmpeg-devel mailing list