From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v3 09/12] Add TST_EXP_EQ_STRN macro
Date: Mon, 13 Jan 2025 12:53:53 +0100 [thread overview]
Message-ID: <Z4T-0Xk9-sKfPfR-@rei> (raw)
In-Reply-To: <20250109-fix_setsid_tests-v3-9-2ce60c904019@suse.com>
Hi!
> +#define TST_EXP_EQ_STRN(STR_A, STR_B, LEN) do { \
> + TST_PASS = strncmp(STR_A, STR_B, LEN) == 0; \
> + \
> + if (TST_PASS) { \
> + tst_res_(__FILE__, __LINE__, TPASS, \
> + "%s == %s (%s)", \
> + #STR_A, #STR_B, STR_B); \
> + } else { \
> + tst_res_(__FILE__, __LINE__, TFAIL, \
> + "%s (%s) != %s (%s)", \
> + #STR_A, STR_A, #STR_B, STR_B); \
Passing these strings to printf-like function is not safe at all, since
they are possibly not nul terminated. If we realy wanted to print them
we would have to copy them and nul terminated them.
e.g.
char str_a_cpy[LEN+1], str_b_cpy[LEN+1];
strncpy(str_a_cpy, STR_A, LEN);
str_a_cpy[LEN] = 0;
strncpy(str_b_cpy, STR_B, LEN);
str_b_cpy[LEN] = 0;
...
tst_res_(...., str_b_cpy, ...);
> + } \
> +} while (0)
> +
> #endif /* TST_TEST_MACROS_H__ */
>
> --
> 2.43.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2025-01-13 11:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-09 14:11 [LTP] [PATCH v3 00/12] Fix tests failing with setsid Andrea Cervesato
2025-01-09 14:11 ` [LTP] [PATCH v3 01/12] Refactor setpgid01 test Andrea Cervesato
2025-01-09 14:11 ` [LTP] [PATCH v3 02/12] Add SAFE_PTSNAME macro Andrea Cervesato
2025-01-09 14:11 ` [LTP] [PATCH v3 03/12] Refactor ptem01 test Andrea Cervesato
2025-01-09 14:11 ` [LTP] [PATCH v3 04/12] Add ptem02 test Andrea Cervesato
2025-01-09 14:11 ` [LTP] [PATCH v3 05/12] Add ptem03 test Andrea Cervesato
2025-01-09 14:11 ` [LTP] [PATCH v3 06/12] Add ptem04 test Andrea Cervesato
2025-01-09 14:11 ` [LTP] [PATCH v3 07/12] Add ptem05 test Andrea Cervesato
2025-01-09 14:11 ` [LTP] [PATCH v3 08/12] Add ptem06 test Andrea Cervesato
2025-01-09 14:11 ` [LTP] [PATCH v3 09/12] Add TST_EXP_EQ_STRN macro Andrea Cervesato
2025-01-13 11:53 ` Cyril Hrubis [this message]
2025-01-13 14:05 ` Andrea Cervesato via ltp
2025-01-13 15:26 ` Cyril Hrubis
2025-01-09 14:11 ` [LTP] [PATCH v3 10/12] Refactor pty01 test Andrea Cervesato
2025-01-09 14:11 ` [LTP] [PATCH v3 11/12] Add pty08 test Andrea Cervesato
2025-01-09 14:11 ` [LTP] [PATCH v3 12/12] Add pty09 test Andrea Cervesato
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=Z4T-0Xk9-sKfPfR-@rei \
--to=chrubis@suse.cz \
--cc=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/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