All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix gcc 8.1 warnings
@ 2018-11-22 16:48 Tomohiro Kusumi
  2018-11-22 16:48 ` [PATCH 1/2] exp: Fix -Wstringop-overflow= warning on gcc 8.1 Tomohiro Kusumi
  2018-11-22 16:48 ` [PATCH 2/2] init: Fix -Wstringop-truncation " Tomohiro Kusumi
  0 siblings, 2 replies; 3+ messages in thread
From: Tomohiro Kusumi @ 2018-11-22 16:48 UTC (permalink / raw)
  To: axboe, fio; +Cc: Tomohiro Kusumi

Fix gcc 8.1 warnings on strncpy()'s length argument.

Tomohiro Kusumi (2):
  exp: Fix -Wstringop-overflow= warning on gcc 8.1
  init: Fix -Wstringop-truncation warning on gcc 8.1

 exp/expression-parser.y |    2 +-
 init.c                  |    3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)



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

* [PATCH 1/2] exp: Fix -Wstringop-overflow= warning on gcc 8.1
  2018-11-22 16:48 [PATCH 0/2] Fix gcc 8.1 warnings Tomohiro Kusumi
@ 2018-11-22 16:48 ` Tomohiro Kusumi
  2018-11-22 16:48 ` [PATCH 2/2] init: Fix -Wstringop-truncation " Tomohiro Kusumi
  1 sibling, 0 replies; 3+ messages in thread
From: Tomohiro Kusumi @ 2018-11-22 16:48 UTC (permalink / raw)
  To: axboe, fio; +Cc: Tomohiro Kusumi

gcc 8.1 on DragonFlyBSD is warning below.

It seems to be saying max copy length shouldn't depend on
the input string itself, so change the length argument to
"sizeof(lexer_input_buffer)-3" without strlen() involved,
followed by explicit \0 termination at the end of source
string length or at "sizeof(lexer_input_buffer)-3".

(-3 comes from what this function has been using.)

--
    CC y.tab.o
In function 'setup_to_parse_string',
    inlined from 'evaluate_arithmetic_expression' at y.tab.c:317:2:
y.tab.c:305:2: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]
  strncpy(lexer_input_buffer, string, len);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
y.tab.c: In function 'evaluate_arithmetic_expression':
y.tab.c:301:8: note: length computed here
  len = strlen(string);
        ^~~~~~~~~~~~~~

Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>
---
 exp/expression-parser.y |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/exp/expression-parser.y b/exp/expression-parser.y
index 04a6e07..29e2bcf 100644
--- a/exp/expression-parser.y
+++ b/exp/expression-parser.y
@@ -208,7 +208,7 @@ static void setup_to_parse_string(const char *string)
 	if (len > sizeof(lexer_input_buffer) - 3)
 		len = sizeof(lexer_input_buffer) - 3;
 
-	strncpy(lexer_input_buffer, string, len);
+	strncpy(lexer_input_buffer, string, sizeof(lexer_input_buffer)-3);
 	lexer_input_buffer[len] = '\0'; 
 	lexer_input_buffer[len + 1] = '\0';  /* lex/yacc want string double null terminated! */
 	lexer_read_offset = 0;
-- 
1.7.1



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

* [PATCH 2/2] init: Fix -Wstringop-truncation warning on gcc 8.1
  2018-11-22 16:48 [PATCH 0/2] Fix gcc 8.1 warnings Tomohiro Kusumi
  2018-11-22 16:48 ` [PATCH 1/2] exp: Fix -Wstringop-overflow= warning on gcc 8.1 Tomohiro Kusumi
@ 2018-11-22 16:48 ` Tomohiro Kusumi
  1 sibling, 0 replies; 3+ messages in thread
From: Tomohiro Kusumi @ 2018-11-22 16:48 UTC (permalink / raw)
  To: axboe, fio; +Cc: Tomohiro Kusumi

gcc 8.1 on DragonFlyBSD is warning below.

The code looks correct, but gcc 8.1 seems to be complaining
on length argument "strlen(filename)".

Replacing the length with "len - ((ts - file) + 1) - 1",
(i.e. buffer_size - leading_directory_size_with_slash - 1)
can silence the warning, but this equals "strlen(filename)".
Neither allows copying beyond limit of "full_fn" whose size
is "len".

--
init.c:2042:6: warning: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
      strncpy(full_fn + (ts - file) + 1,
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       filename, strlen(filename));
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>
---
 init.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/init.c b/init.c
index a2b70c4..682a0c2 100644
--- a/init.c
+++ b/init.c
@@ -2040,7 +2040,8 @@ static int __parse_jobs_ini(struct thread_data *td,
 					strncpy(full_fn,
 						file, (ts - file) + 1);
 					strncpy(full_fn + (ts - file) + 1,
-						filename, strlen(filename));
+						filename,
+						len - ((ts - file) + 1) - 1);
 					full_fn[len - 1] = 0;
 					filename = full_fn;
 				}
-- 
1.7.1



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

end of thread, other threads:[~2018-11-23  3:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-22 16:48 [PATCH 0/2] Fix gcc 8.1 warnings Tomohiro Kusumi
2018-11-22 16:48 ` [PATCH 1/2] exp: Fix -Wstringop-overflow= warning on gcc 8.1 Tomohiro Kusumi
2018-11-22 16:48 ` [PATCH 2/2] init: Fix -Wstringop-truncation " Tomohiro Kusumi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.