linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Donnellan <ajd@linux.ibm.com>
To: Benjamin Gray <bgray@linux.ibm.com>, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v3 2/7] selftests/powerpc: Add ptrace setup_core_pattern() null-terminator
Date: Fri, 02 Dec 2022 14:52:58 +1100	[thread overview]
Message-ID: <42ea8c518ce1db9bd09c7fc48e21aa16a468d138.camel@linux.ibm.com> (raw)
In-Reply-To: <20221128041948.58339-3-bgray@linux.ibm.com>

On Mon, 2022-11-28 at 15:19 +1100, Benjamin Gray wrote:
> - malloc() does not zero the buffer,
> - fread() does not null-terminate it's output,
> - `cat /proc/sys/kernel/core_pattern | hexdump -C` shows the file is
>   not inherently null-terminated
> 
> So using string operations on the buffer is risky. Explicitly add a
> null
> character to the end to make it safer.
> 
> Signed-off-by: Benjamin Gray <bgray@linux.ibm.com>

Reviewed-by: Andrew Donnellan <ajd@linux.ibm.com>

> ---
>  tools/testing/selftests/powerpc/ptrace/core-pkey.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/powerpc/ptrace/core-pkey.c
> b/tools/testing/selftests/powerpc/ptrace/core-pkey.c
> index bbc05ffc5860..5c82ed9e7c65 100644
> --- a/tools/testing/selftests/powerpc/ptrace/core-pkey.c
> +++ b/tools/testing/selftests/powerpc/ptrace/core-pkey.c
> @@ -383,7 +383,7 @@ static int setup_core_pattern(char
> **core_pattern_, bool *changed_)
>                 goto out;
>         }
>  
> -       ret = fread(core_pattern, 1, PATH_MAX, f);
> +       ret = fread(core_pattern, 1, PATH_MAX - 1, f);
>         fclose(f);
>         if (!ret) {
>                 perror("Error reading core_pattern file");
> @@ -391,6 +391,8 @@ static int setup_core_pattern(char
> **core_pattern_, bool *changed_)
>                 goto out;
>         }
>  
> +       core_pattern[ret] = '\0';
> +
>         /* Check whether we can predict the name of the core file. */
>         if (!strcmp(core_pattern, "core") || !strcmp(core_pattern,
> "core.%p"))
>                 *changed_ = false;

-- 
Andrew Donnellan    OzLabs, ADL Canberra
ajd@linux.ibm.com   IBM Australia Limited

  reply	other threads:[~2022-12-02  3:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-28  4:19 [PATCH v3 0/7] Expand selftest utils Benjamin Gray
2022-11-28  4:19 ` [PATCH v3 1/7] selftests/powerpc: Use mfspr/mtspr macros Benjamin Gray
2022-11-28  4:19 ` [PATCH v3 2/7] selftests/powerpc: Add ptrace setup_core_pattern() null-terminator Benjamin Gray
2022-12-02  3:52   ` Andrew Donnellan [this message]
2022-11-28  4:19 ` [PATCH v3 3/7] selftests/powerpc: Add generic read/write file util Benjamin Gray
2022-12-02 11:04   ` Michael Ellerman
2023-01-25  4:50   ` Andrew Donnellan
2022-11-28  4:19 ` [PATCH v3 4/7] selftests/powerpc: Add read/write debugfs file, int Benjamin Gray
2023-01-25  4:59   ` Andrew Donnellan
2022-11-28  4:19 ` [PATCH v3 5/7] selftests/powerpc: Parse long/unsigned long value safely Benjamin Gray
2022-11-28  4:19 ` [PATCH v3 6/7] selftests/powerpc: Add {read,write}_{long,ulong} Benjamin Gray
2022-11-28  4:19 ` [PATCH v3 7/7] selftests/powerpc: Add automatically allocating read_file Benjamin Gray
2022-12-08 12:40 ` (subset) [PATCH v3 0/7] Expand selftest utils Michael Ellerman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42ea8c518ce1db9bd09c7fc48e21aa16a468d138.camel@linux.ibm.com \
    --to=ajd@linux.ibm.com \
    --cc=bgray@linux.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).