On 9 May 2012 10:23, Jim Meyering <j...@meyering.net> wrote: > From: Jim Meyering <meyer...@redhat.com> > > Remove unnecessary and unchecked uses of strdup, > and add a comment that this strncpy use is ok. > > Signed-off-by: Jim Meyering <meyer...@redhat.com> > --- > linux-user/elfload.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/linux-user/elfload.c b/linux-user/elfload.c > index f3b1552..25175cc 100644 > --- a/linux-user/elfload.c > +++ b/linux-user/elfload.c > @@ -2338,12 +2338,14 @@ static int fill_psinfo(struct target_elf_prpsinfo > *psinfo, const TaskState *ts) > psinfo->pr_uid = getuid(); > psinfo->pr_gid = getgid(); > > - filename = strdup(ts->bprm->filename); > - base_filename = strdup(basename(filename)); > + filename = ts->bprm->filename; > + base_filename = basename(filename); > + /* > + * Using strncpy here is fine: at max-length, > + * this field is not NUL-terminated. > + */ > (void) strncpy(psinfo->pr_fname, base_filename, > sizeof(psinfo->pr_fname)); > - free(base_filename); > - free(filename);
This doesn't look right -- basename can modify the string it's passed, which is why we create a copy for it. -- PMM