Linux-rt-users archive on lore.kernel.org
 help / color / Atom feed
* [PATCH rt-tests v1 v1 0/4] Fix gcc warning
@ 2019-08-19  6:43 Daniel Wagner
  2019-08-19  6:43 ` [PATCH rt-tests v1 v1 1/4] pmqtest: Increase buffer to avoid overflow Daniel Wagner
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Daniel Wagner @ 2019-08-19  6:43 UTC (permalink / raw)
  To: Clark Williams, John Kacur; +Cc: linux-rt-users, Daniel Wagner

On F29 and F30 gcc is warning about too small buffers. Let's fix this.

changes v1:
 - Increase the buffer to needed exact size as pointed out by Sebastian

Daniel Wagner (4):
  pmqtest: Increase buffer to avoid overflow
  sigwaittest: Increase buffer to avoid overflow
  svsematest: Increase buffer to avoid overflow
  deadline_test: Increase buffer to avoid overflow

 src/pmqtest/pmqtest.c              | 4 ++--
 src/sched_deadline/deadline_test.c | 2 +-
 src/sigwaittest/sigwaittest.c      | 2 +-
 src/svsematest/svsematest.c        | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

-- 
2.21.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH rt-tests v1 v1 1/4] pmqtest: Increase buffer to avoid overflow
  2019-08-19  6:43 [PATCH rt-tests v1 v1 0/4] Fix gcc warning Daniel Wagner
@ 2019-08-19  6:43 ` Daniel Wagner
  2019-08-23 15:15   ` John Kacur
  2019-08-19  6:43 ` [PATCH rt-tests v1 v1 2/4] sigwaittest: " Daniel Wagner
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Daniel Wagner @ 2019-08-19  6:43 UTC (permalink / raw)
  To: Clark Williams, John Kacur; +Cc: linux-rt-users, Daniel Wagner

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH rt-tests v1 v1 2/4] sigwaittest: Increase buffer to avoid overflow
  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-19  6:43 ` " 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-19  6:43 ` [PATCH rt-tests v1 v1 4/4] deadline_test: " Daniel Wagner
  3 siblings, 1 reply; 9+ messages in thread
From: Daniel Wagner @ 2019-08-19  6:43 UTC (permalink / raw)
  To: Clark Williams, John Kacur; +Cc: linux-rt-users, Daniel Wagner

Increase the size of the char buffer. gcc 9.1.1 reports:

src/sigwaittest/sigwaittest.c:494:5: note: ‘sprintf’ output between 5 and 14 bytes into a destination of size 8
  494 |     sprintf(f_opt, "-fr%d", i);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~
src/sigwaittest/sigwaittest.c:522:24: warning: ‘%d’ directive writing between 1 and 10 bytes into a region of size 5 [-Wformat-overflow=]
  522 |     sprintf(f_opt, "-fs%d", i);
      |                        ^~

Signed-off-by: Daniel Wagner <wagi@monom.org>
---
 src/sigwaittest/sigwaittest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/sigwaittest/sigwaittest.c b/src/sigwaittest/sigwaittest.c
index 59f28a5babcb..2d0c04132fa7 100644
--- a/src/sigwaittest/sigwaittest.c
+++ b/src/sigwaittest/sigwaittest.c
@@ -352,7 +352,7 @@ int main(int argc, char *argv[])
 	struct params *sender = NULL;
 	sigset_t sigset;
 	void *param = NULL;
-	char f_opt[8];
+	char f_opt[14];
 	struct timespec launchdelay, maindelay;
 
 	process_options(argc, argv);
-- 
2.21.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH rt-tests v1 v1 3/4] svsematest: Increase buffer to avoid overflow
  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-19  6:43 ` [PATCH rt-tests v1 v1 2/4] sigwaittest: " Daniel Wagner
@ 2019-08-19  6:43 ` " 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
  3 siblings, 1 reply; 9+ messages in thread
From: Daniel Wagner @ 2019-08-19  6:43 UTC (permalink / raw)
  To: Clark Williams, John Kacur; +Cc: linux-rt-users, Daniel Wagner

Increase the size of the char buffer. gcc 9.1.1 reports:

rc/svsematest/svsematest.c:578:24: warning: ‘%d’ directive writing between 1 and 10 bytes into a region of size 5 [-Wformat-overflow=]
  578 |     sprintf(f_opt, "-fr%d", i);
      |                        ^~
src/svsematest/svsematest.c:606:5: note: ‘sprintf’ output between 5 and 14 bytes into a destination of size 8
  606 |     sprintf(f_opt, "-fs%d", i);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Daniel Wagner <wagi@monom.org>
---
 src/svsematest/svsematest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/svsematest/svsematest.c b/src/svsematest/svsematest.c
index 8f880786ec0f..15e36af76288 100644
--- a/src/svsematest/svsematest.c
+++ b/src/svsematest/svsematest.c
@@ -401,7 +401,7 @@ int main(int argc, char *argv[])
 	struct params *sender = NULL;
 	sigset_t sigset;
 	void *param = NULL;
-	char f_opt[8];
+	char f_opt[14];
 	struct timespec launchdelay, maindelay;
 
 	myfile = getenv("_");
-- 
2.21.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH rt-tests v1 v1 4/4] deadline_test: Increase buffer to avoid overflow
  2019-08-19  6:43 [PATCH rt-tests v1 v1 0/4] Fix gcc warning Daniel Wagner
                   ` (2 preceding siblings ...)
  2019-08-19  6:43 ` [PATCH rt-tests v1 v1 3/4] svsematest: " Daniel Wagner
@ 2019-08-19  6:43 ` " Daniel Wagner
  2019-08-23 15:20   ` John Kacur
  3 siblings, 1 reply; 9+ messages in thread
From: Daniel Wagner @ 2019-08-19  6:43 UTC (permalink / raw)
  To: Clark Williams, John Kacur; +Cc: linux-rt-users, Daniel Wagner

Increase the size of the char buffer. gcc 9.1.1 reports:

src/sched_deadline/deadline_test.c:1803:24: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 10 [-Wformat-overflow=]
 1803 |   sprintf(setcpu_buf, "%d", cpu_count - 1);
      |                        ^~
src/sched_deadline/deadline_test.c:1803:23: note: directive argument in the range [-2147483648, 2147483646]
 1803 |   sprintf(setcpu_buf, "%d", cpu_count - 1);
      |                       ^~~~
src/sched_deadline/deadline_test.c:1803:3: note: ‘sprintf’ output between 2 and 12 bytes into a destination of size 10
 1803 |   sprintf(setcpu_buf, "%d", cpu_count - 1);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Daniel Wagner <wagi@monom.org>
---
 src/sched_deadline/deadline_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/sched_deadline/deadline_test.c b/src/sched_deadline/deadline_test.c
index e2898de328bb..5b5f40dbb74d 100644
--- a/src/sched_deadline/deadline_test.c
+++ b/src/sched_deadline/deadline_test.c
@@ -1795,7 +1795,7 @@ int main (int argc, char **argv)
 
 	/* -b has us bind to the last CPU. */
 	if (!all_cpus && !setcpu) {
-		setcpu_buf = malloc(10);
+		setcpu_buf = malloc(12);
 		if (!setcpu_buf) {
 			perror("malloc");
 			exit(-1);
-- 
2.21.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH rt-tests v1 v1 1/4] pmqtest: Increase buffer to avoid overflow
  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
  0 siblings, 0 replies; 9+ messages in thread
From: John Kacur @ 2019-08-23 15:15 UTC (permalink / raw)
  To: Daniel Wagner; +Cc: Clark Williams, linux-rt-users

[-- 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>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH rt-tests v1 v1 2/4] sigwaittest: Increase buffer to avoid overflow
  2019-08-19  6:43 ` [PATCH rt-tests v1 v1 2/4] sigwaittest: " Daniel Wagner
@ 2019-08-23 15:17   ` John Kacur
  0 siblings, 0 replies; 9+ messages in thread
From: John Kacur @ 2019-08-23 15:17 UTC (permalink / raw)
  To: Daniel Wagner; +Cc: Clark Williams, linux-rt-users

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



On Mon, 19 Aug 2019, Daniel Wagner wrote:

> Increase the size of the char buffer. gcc 9.1.1 reports:
> 
> src/sigwaittest/sigwaittest.c:494:5: note: ‘sprintf’ output between 5 and 14 bytes into a destination of size 8
>   494 |     sprintf(f_opt, "-fr%d", i);
>       |     ^~~~~~~~~~~~~~~~~~~~~~~~~~
> src/sigwaittest/sigwaittest.c:522:24: warning: ‘%d’ directive writing between 1 and 10 bytes into a region of size 5 [-Wformat-overflow=]
>   522 |     sprintf(f_opt, "-fs%d", i);
>       |                        ^~
> 
> Signed-off-by: Daniel Wagner <wagi@monom.org>
> ---
>  src/sigwaittest/sigwaittest.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/sigwaittest/sigwaittest.c b/src/sigwaittest/sigwaittest.c
> index 59f28a5babcb..2d0c04132fa7 100644
> --- a/src/sigwaittest/sigwaittest.c
> +++ b/src/sigwaittest/sigwaittest.c
> @@ -352,7 +352,7 @@ int main(int argc, char *argv[])
>  	struct params *sender = NULL;
>  	sigset_t sigset;
>  	void *param = NULL;
> -	char f_opt[8];
> +	char f_opt[14];
>  	struct timespec launchdelay, maindelay;
>  
>  	process_options(argc, argv);
> -- 
> 2.21.0
> 
Signed-off-by: John Kacur <jkacur@redhat.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH rt-tests v1 v1 3/4] svsematest: Increase buffer to avoid overflow
  2019-08-19  6:43 ` [PATCH rt-tests v1 v1 3/4] svsematest: " Daniel Wagner
@ 2019-08-23 15:19   ` John Kacur
  0 siblings, 0 replies; 9+ messages in thread
From: John Kacur @ 2019-08-23 15:19 UTC (permalink / raw)
  To: Daniel Wagner; +Cc: Clark Williams, linux-rt-users

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



On Mon, 19 Aug 2019, Daniel Wagner wrote:

> Increase the size of the char buffer. gcc 9.1.1 reports:
> 
> rc/svsematest/svsematest.c:578:24: warning: ‘%d’ directive writing between 1 and 10 bytes into a region of size 5 [-Wformat-overflow=]
>   578 |     sprintf(f_opt, "-fr%d", i);
>       |                        ^~
> src/svsematest/svsematest.c:606:5: note: ‘sprintf’ output between 5 and 14 bytes into a destination of size 8
>   606 |     sprintf(f_opt, "-fs%d", i);
>       |     ^~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Signed-off-by: Daniel Wagner <wagi@monom.org>
> ---
>  src/svsematest/svsematest.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/svsematest/svsematest.c b/src/svsematest/svsematest.c
> index 8f880786ec0f..15e36af76288 100644
> --- a/src/svsematest/svsematest.c
> +++ b/src/svsematest/svsematest.c
> @@ -401,7 +401,7 @@ int main(int argc, char *argv[])
>  	struct params *sender = NULL;
>  	sigset_t sigset;
>  	void *param = NULL;
> -	char f_opt[8];
> +	char f_opt[14];
>  	struct timespec launchdelay, maindelay;
>  
>  	myfile = getenv("_");
> -- 
> 2.21.0
> 
Signed-off-by: John Kacur <jkacur@redhat.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH rt-tests v1 v1 4/4] deadline_test: Increase buffer to avoid overflow
  2019-08-19  6:43 ` [PATCH rt-tests v1 v1 4/4] deadline_test: " Daniel Wagner
@ 2019-08-23 15:20   ` John Kacur
  0 siblings, 0 replies; 9+ messages in thread
From: John Kacur @ 2019-08-23 15:20 UTC (permalink / raw)
  To: Daniel Wagner; +Cc: Clark Williams, linux-rt-users

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



On Mon, 19 Aug 2019, Daniel Wagner wrote:

> Increase the size of the char buffer. gcc 9.1.1 reports:
> 
> src/sched_deadline/deadline_test.c:1803:24: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 10 [-Wformat-overflow=]
>  1803 |   sprintf(setcpu_buf, "%d", cpu_count - 1);
>       |                        ^~
> src/sched_deadline/deadline_test.c:1803:23: note: directive argument in the range [-2147483648, 2147483646]
>  1803 |   sprintf(setcpu_buf, "%d", cpu_count - 1);
>       |                       ^~~~
> src/sched_deadline/deadline_test.c:1803:3: note: ‘sprintf’ output between 2 and 12 bytes into a destination of size 10
>  1803 |   sprintf(setcpu_buf, "%d", cpu_count - 1);
>       |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Signed-off-by: Daniel Wagner <wagi@monom.org>
> ---
>  src/sched_deadline/deadline_test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/sched_deadline/deadline_test.c b/src/sched_deadline/deadline_test.c
> index e2898de328bb..5b5f40dbb74d 100644
> --- a/src/sched_deadline/deadline_test.c
> +++ b/src/sched_deadline/deadline_test.c
> @@ -1795,7 +1795,7 @@ int main (int argc, char **argv)
>  
>  	/* -b has us bind to the last CPU. */
>  	if (!all_cpus && !setcpu) {
> -		setcpu_buf = malloc(10);
> +		setcpu_buf = malloc(12);
>  		if (!setcpu_buf) {
>  			perror("malloc");
>  			exit(-1);
> -- 
> 2.21.0
> 
Signed-off-by: John Kacur <jkacur@redhat.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, back to index

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

Linux-rt-users archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-rt-users/0 linux-rt-users/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-rt-users linux-rt-users/ https://lore.kernel.org/linux-rt-users \
		linux-rt-users@vger.kernel.org linux-rt-users@archiver.kernel.org
	public-inbox-index linux-rt-users


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-rt-users


AGPL code for this site: git clone https://public-inbox.org/ public-inbox