linux-sctp.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xin Long <lucien.xin@gmail.com>
To: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Cc: "linux-sctp @ vger . kernel . org" <linux-sctp@vger.kernel.org>
Subject: Re: [PATCH lksctp-tools] func_tests: fix malloc size in test_1_to_1_connectx.c
Date: Wed, 7 Apr 2021 17:13:41 -0400	[thread overview]
Message-ID: <CADvbK_cnKdQftMNmwvgD_RrBA17OTuFNdqKGPaYcZPUrpQx6Dg@mail.gmail.com> (raw)
In-Reply-To: <ce238aa27d414e3a6f857491d789dbfe2f1f912f.1617721194.git.marcelo.leitner@gmail.com>

On Wed, Apr 7, 2021 at 1:35 AM Marcelo Ricardo Leitner
<marcelo.leitner@gmail.com> wrote:
>
> Recent gcc started tracking this and now it's warning:
> test_1_to_1_connectx.c: In function ‘main’:
> test_1_to_1_connectx.c:133:17: warning: array subscript ‘struct sockaddr[0]’ is partly outside array bounds of ‘unsigned char[15]’ [-Warray-bounds]
>   133 |         tmp_addr->sa_family = AF_INET;
>       |                 ^~
> test_1_to_1_connectx.c:132:40: note: referencing an object of size 15 allocated by ‘malloc’
>   132 |         tmp_addr = (struct sockaddr *) malloc(sizeof(struct sockaddr) - 1);
>       |                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> It gets parsed by __connectx_addrsize using each family struct, but they
> aligned to sockaddr size. So lets fix it here by allocating the right
> size.
>
> Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> ---
>  src/func_tests/test_1_to_1_connectx.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/func_tests/test_1_to_1_connectx.c b/src/func_tests/test_1_to_1_connectx.c
> index 3cb18b3aad421720e8598e9a0bbab2de987d4467..9adab2352c09d0fb0087e4c4b43c6d7d7b60de0d 100644
> --- a/src/func_tests/test_1_to_1_connectx.c
> +++ b/src/func_tests/test_1_to_1_connectx.c
> @@ -129,7 +129,7 @@ main(int argc, char *argv[])
>         tst_resm(TPASS, "sctp_connectx() with invalid socket - ENOTSOCK");
>
>         /*sctp_connectx () TEST3: Invalid address, EINVAL Expected error*/
> -       tmp_addr = (struct sockaddr *) malloc(sizeof(struct sockaddr) - 1);
> +       tmp_addr = (struct sockaddr *) malloc(sizeof(struct sockaddr));
>         tmp_addr->sa_family = AF_INET;
>         error = sctp_connectx(sk, tmp_addr, 1, NULL);
>         if (error != -1 || errno != EINVAL)
> --
> 2.30.2
>
Reviewed-by: Xin Long <lucien.xin@gmail.com>

      reply	other threads:[~2021-04-07 21:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06 15:01 [PATCH lksctp-tools] func_tests: fix malloc size in test_1_to_1_connectx.c Marcelo Ricardo Leitner
2021-04-07 21:13 ` Xin Long [this message]

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=CADvbK_cnKdQftMNmwvgD_RrBA17OTuFNdqKGPaYcZPUrpQx6Dg@mail.gmail.com \
    --to=lucien.xin@gmail.com \
    --cc=linux-sctp@vger.kernel.org \
    --cc=marcelo.leitner@gmail.com \
    /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).