[pacman-dev] [PATCH] Change strdup function using for strndup
Laszlo Papp
djszapi at archlinux.us
Sat Oct 24 11:13:29 EDT 2009
On Sat, Oct 24, 2009 at 4:46 PM, Xavier <shiningxc at gmail.com> wrote:
> On Sun, Oct 18, 2009 at 5:38 PM, Dan McGee <dpmcgee at gmail.com> wrote:
> > On Sat, Oct 17, 2009 at 11:40 PM, Laszlo Papp <djszapi2 at gmail.com>
> wrote:
> >> * Size examined str* function usage is a common coding practice,
> >> * because it's more safer to avoid breakage while using
> str* functions.
> >>
> >> Signed-off-by: Laszlo Papp <djszapi at archlinux.us>
> >> ---
> >> @@ -189,7 +189,7 @@ char *mdirname(const char *path)
> >> }
> >> /* no slash found */
> >> free(ret);
> >> - return(strdup("."));
> >> + return(strndup(".", PATH_MAX));
> >> }
> >>
> >
> > Um...what? Really?
> >
>
> Yes yes, this is more safer, I swear !
>
> So what happens if we do reach the limit given to strndup ? We just
> truncate the string and we expect everything will be fine^Wmore safer
> ?
>
>
It can be avoided with 'if' condition examination.
Best Regards,
Laszlo Papp
More information about the pacman-dev
mailing list