All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/3] [COMMITTED] lib/tst_mkfs.c: Fix fall through warning
@ 2020-05-12 15:17 Cyril Hrubis
  2020-05-12 15:17 ` [LTP] [PATCH 2/3] [COMMITTED] lib: Fix two sprintf() warnings Cyril Hrubis
  2020-05-12 15:17 ` [LTP] [PATCH 3/3] [COMMITTED] lib: Fix two strncpy() destination equal bounds warnings Cyril Hrubis
  0 siblings, 2 replies; 3+ messages in thread
From: Cyril Hrubis @ 2020-05-12 15:17 UTC (permalink / raw)
  To: ltp

tst_mkfs.c: In function 'tst_mkfs_':
../include/old/test.h:139:5: warning: this statement may fall through [-Wimplicit-fallthrough=]
  139 |  if (tst_test) \
      |     ^
tst_mkfs.c:98:3: note: in expansion of macro 'tst_brkm'
   98 |   tst_brkm(TCONF, cleanup_fn,
      |   ^~~~~~~~
tst_mkfs.c:100:2: note: here
  100 |  default:
      |  ^~~~~~~

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 lib/tst_mkfs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/tst_mkfs.c b/lib/tst_mkfs.c
index 3860545eb..38b2e7151 100644
--- a/lib/tst_mkfs.c
+++ b/lib/tst_mkfs.c
@@ -97,6 +97,7 @@ void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void),
 	case 255:
 		tst_brkm(TCONF, cleanup_fn,
 			 "%s:%d: %s not found in $PATH", file, lineno, mkfs);
+	break;
 	default:
 		tst_brkm(TBROK, cleanup_fn,
 			 "%s:%d: %s failed with %i", file, lineno, mkfs, ret);
-- 
2.26.2


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

* [LTP] [PATCH 2/3] [COMMITTED] lib: Fix two sprintf() warnings.
  2020-05-12 15:17 [LTP] [PATCH 1/3] [COMMITTED] lib/tst_mkfs.c: Fix fall through warning Cyril Hrubis
@ 2020-05-12 15:17 ` Cyril Hrubis
  2020-05-12 15:17 ` [LTP] [PATCH 3/3] [COMMITTED] lib: Fix two strncpy() destination equal bounds warnings Cyril Hrubis
  1 sibling, 0 replies; 3+ messages in thread
From: Cyril Hrubis @ 2020-05-12 15:17 UTC (permalink / raw)
  To: ltp

tst_test.c: In function 'do_setup':
tst_test.c:69:21: warning: '%s' directive writing up to 1023 bytes into a region of size 1011 [-Wformat-overflow=]

tst_kconfig.c: In function 'tst_kconfig_read':
tst_kconfig.c:67:37: warning: '%s' directive output may be truncated writing up to 1023 bytes into a region of size 1018 [-Wformat-truncation=]

The buffer that we print the path along with variable name has to be
bigger than the path obviously.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 lib/tst_kconfig.c | 2 +-
 lib/tst_test.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
index 4b51413e5..d49187b6f 100644
--- a/lib/tst_kconfig.c
+++ b/lib/tst_kconfig.c
@@ -52,7 +52,7 @@ static char is_gzip;
 static FILE *open_kconfig(void)
 {
 	FILE *fp;
-	char buf[1024];
+	char buf[1064];
 	char path_buf[1024];
 	const char *path = kconfig_path(path_buf, sizeof(path_buf));
 
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 64cd3ac33..0e58060e0 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -68,7 +68,7 @@ extern unsigned int tst_max_futexes;
 
 #define IPC_ENV_VAR "LTP_IPC_PATH"
 
-static char ipc_path[1024];
+static char ipc_path[1064];
 const char *tst_ipc_path = ipc_path;
 
 static char shm_path[1024];
-- 
2.26.2


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

* [LTP] [PATCH 3/3] [COMMITTED] lib: Fix two strncpy() destination equal bounds warnings
  2020-05-12 15:17 [LTP] [PATCH 1/3] [COMMITTED] lib/tst_mkfs.c: Fix fall through warning Cyril Hrubis
  2020-05-12 15:17 ` [LTP] [PATCH 2/3] [COMMITTED] lib: Fix two sprintf() warnings Cyril Hrubis
@ 2020-05-12 15:17 ` Cyril Hrubis
  1 sibling, 0 replies; 3+ messages in thread
From: Cyril Hrubis @ 2020-05-12 15:17 UTC (permalink / raw)
  To: ltp

In function 'strncpy',
    inlined from 'tst_sys_conf_save_str' at tst_sys_conf.c:29:2:
/usr/include/bits/string_fortified.h:106:10: warning: '__builtin_strncpy' specified bound 4096 equals destination size [-Wstringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'strncpy',
    inlined from 'tst_sys_conf_save_str' at tst_sys_conf.c:30:2:
/usr/include/bits/string_fortified.h:106:10: warning: '__builtin_strncpy' specified bound 4096 equals destination size [-Wstringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In short we have to always copy dest-1 bytes and zero the last one, that
may still make us loose part of the path, but at least we will not
crash.

Maybe we should rewrite the code to just use strdup() instead.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 lib/tst_sys_conf.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/tst_sys_conf.c b/lib/tst_sys_conf.c
index 1ae875387..4ad9f8b9b 100644
--- a/lib/tst_sys_conf.c
+++ b/lib/tst_sys_conf.c
@@ -26,8 +26,11 @@ int tst_sys_conf_save_str(const char *path, const char *value)
 {
 	struct tst_sys_conf *n = SAFE_MALLOC(sizeof(*n));
 
-	strncpy(n->path, path, sizeof(n->path));
-	strncpy(n->value, value, sizeof(n->value));
+	strncpy(n->path, path, sizeof(n->path)-1);
+	strncpy(n->value, value, sizeof(n->value)-1);
+
+	n->path[sizeof(n->path) - 1] = 0;
+	n->value[sizeof(n->value) - 1] = 0;
 
 	n->next = save_restore_data;
 	save_restore_data = n;
-- 
2.26.2


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

end of thread, other threads:[~2020-05-12 15:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-12 15:17 [LTP] [PATCH 1/3] [COMMITTED] lib/tst_mkfs.c: Fix fall through warning Cyril Hrubis
2020-05-12 15:17 ` [LTP] [PATCH 2/3] [COMMITTED] lib: Fix two sprintf() warnings Cyril Hrubis
2020-05-12 15:17 ` [LTP] [PATCH 3/3] [COMMITTED] lib: Fix two strncpy() destination equal bounds warnings Cyril Hrubis

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.