linux-user: remove two unchecked uses of strdup
Remove two uses of strdup (use g_path_get_basename instead), and add a comment that this strncpy use is ok. Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
ae21506801
commit
900cfbcac6
@ -2442,7 +2442,7 @@ static void fill_prstatus(struct target_elf_prstatus *prstatus,
|
|||||||
|
|
||||||
static int fill_psinfo(struct target_elf_prpsinfo *psinfo, const TaskState *ts)
|
static int fill_psinfo(struct target_elf_prpsinfo *psinfo, const TaskState *ts)
|
||||||
{
|
{
|
||||||
char *filename, *base_filename;
|
char *base_filename;
|
||||||
unsigned int i, len;
|
unsigned int i, len;
|
||||||
|
|
||||||
(void) memset(psinfo, 0, sizeof (*psinfo));
|
(void) memset(psinfo, 0, sizeof (*psinfo));
|
||||||
@ -2464,13 +2464,15 @@ static int fill_psinfo(struct target_elf_prpsinfo *psinfo, const TaskState *ts)
|
|||||||
psinfo->pr_uid = getuid();
|
psinfo->pr_uid = getuid();
|
||||||
psinfo->pr_gid = getgid();
|
psinfo->pr_gid = getgid();
|
||||||
|
|
||||||
filename = strdup(ts->bprm->filename);
|
base_filename = g_path_get_basename(ts->bprm->filename);
|
||||||
base_filename = strdup(basename(filename));
|
/*
|
||||||
|
* Using strncpy here is fine: at max-length,
|
||||||
|
* this field is not NUL-terminated.
|
||||||
|
*/
|
||||||
(void) strncpy(psinfo->pr_fname, base_filename,
|
(void) strncpy(psinfo->pr_fname, base_filename,
|
||||||
sizeof(psinfo->pr_fname));
|
sizeof(psinfo->pr_fname));
|
||||||
free(base_filename);
|
|
||||||
free(filename);
|
|
||||||
|
|
||||||
|
g_free(base_filename);
|
||||||
bswap_psinfo(psinfo);
|
bswap_psinfo(psinfo);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user