linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Kacur <jkacur@redhat.com>
To: Daniel Wagner <wagi@monom.org>
Cc: Clark Williams <williams@redhat.com>, linux-rt-users@vger.kernel.org
Subject: Re: [PATCH rt-tests v1 v1 1/4] pmqtest: Increase buffer to avoid overflow
Date: Fri, 23 Aug 2019 17:15:58 +0200 (CEST)	[thread overview]
Message-ID: <alpine.LFD.2.21.1908231709170.7154@planxty> (raw)
In-Reply-To: <20190819064304.4676-2-wagi@monom.org>

[-- Attachment #1: Type: text/plain, Size: 1943 bytes --]



On Mon, 19 Aug 2019, Daniel Wagner wrote:

> Increase the size of the char buffer. gcc 9.1.1 reports:
> 
> src/pmqtest/pmqtest.c: In function ‘main’:
> src/pmqtest/pmqtest.c:46:21: warning: ‘%d’ directive writing between 1 and 10 bytes into a region of size 8 [-Wformat-overflow=]
>    46 | #define SYNCMQ_NAME "/syncmsg%d"
>       |                     ^~~~~~~~~~~~
> 
> src/pmqtest/pmqtest.c:445:3: note: ‘sprintf’ output between 10 and 19 bytes into a destination of size 16
>   445 |   sprintf(mqname, SYNCMQ_NAME, i);
>       |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Signed-off-by: Daniel Wagner <wagi@monom.org>
> ---
>  src/pmqtest/pmqtest.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/pmqtest/pmqtest.c b/src/pmqtest/pmqtest.c
> index a04fc49872bf..3ce799bd6319 100644
> --- a/src/pmqtest/pmqtest.c
> +++ b/src/pmqtest/pmqtest.c
> @@ -440,7 +440,7 @@ int main(int argc, char *argv[])
>  		goto nomem;
>  
>  	for (i = 0; i < num_threads; i++) {
> -		char mqname[16];
> +		char mqname[19];
>  
>  		sprintf(mqname, SYNCMQ_NAME, i);
>  		receiver[i].syncmq = mq_open(mqname, oflag, 0777, &mqstat);
> @@ -567,7 +567,7 @@ int main(int argc, char *argv[])
>  	}
>  	nanosleep(&maindelay, NULL);
>  	for (i = 0; i < num_threads; i++) {
> -		char mqname[16];
> +		char mqname[19];
>  
>  		mq_close(receiver[i].syncmq);
>  		sprintf(mqname, SYNCMQ_NAME, i);
> -- 
> 2.21.0
> 

I don't love the use of "magic numbers". Also the compiler considers the 
signed integers to be −2147483648 to 2147483647 so including the sign that 
is potentially up to 11 chars, plus our string is "/syncmsg" is 8 chars
so that's where the 19 comes from. However we are using the int to 
represent threads, so we know we can't have a negative number. However 
sprintf also adds '\n' which brings us back to 19 again anyway.

This is better than what we have, so 

Signed-off-by: John Kacur <jkacur@redhat.com>

  reply	other threads:[~2019-08-23 15:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-19  6:43 [PATCH rt-tests v1 v1 0/4] Fix gcc warning Daniel Wagner
2019-08-19  6:43 ` [PATCH rt-tests v1 v1 1/4] pmqtest: Increase buffer to avoid overflow Daniel Wagner
2019-08-23 15:15   ` John Kacur [this message]
2019-08-19  6:43 ` [PATCH rt-tests v1 v1 2/4] sigwaittest: " Daniel Wagner
2019-08-23 15:17   ` John Kacur
2019-08-19  6:43 ` [PATCH rt-tests v1 v1 3/4] svsematest: " Daniel Wagner
2019-08-23 15:19   ` John Kacur
2019-08-19  6:43 ` [PATCH rt-tests v1 v1 4/4] deadline_test: " Daniel Wagner
2019-08-23 15:20   ` John Kacur

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=alpine.LFD.2.21.1908231709170.7154@planxty \
    --to=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=wagi@monom.org \
    --cc=williams@redhat.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).