diff mbox series

[3/3] stack_clash: make use of tst_kcmdline_parse

Message ID 20240308045230.3106549-3-liwang@redhat.com
State Superseded
Headers show
Series [1/3] kconfig: add funtion to parse /proc/cmdline | expand

Commit Message

Li Wang March 8, 2024, 4:52 a.m. UTC
Signed-off-by: Li Wang <liwang@redhat.com>
---
 testcases/cve/stack_clash.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Comments

Petr Vorel March 8, 2024, 8:56 a.m. UTC | #1
Hi Li,

>  void setup(void)
>  {
> -	char buf[4096], *p;
> +	char *p;
stack_clash.c:276:15: warning: unused variable ā€˜pā€™ [-Wunused-variable]
  276 |         char *p;
      |               ^

>  	page_size = sysconf(_SC_PAGESIZE);
>  	page_mask = ~(page_size - 1);

> -	buf[4095] = '\0';
> -	SAFE_FILE_SCANF("/proc/cmdline", "%4095[^\n]", buf);
> +	struct tst_kcmdline_param params = TST_KCMDLINE_INIT("stack_guard_gap");
> +	tst_kcmdline_parse(&params, 1);

> -	if ((p = strstr(buf, "stack_guard_gap=")) != NULL) {
> -		if (sscanf(p, "stack_guard_gap=%ld", &GAP_PAGES) != 1) {
> -			tst_brk(TBROK | TERRNO, "sscanf");
> -			return;
> -		}
> +	if (params.value[0] != '\0') {
> +		GAP_PAGES= atol(params.value);
>  		tst_res(TINFO, "stack_guard_gap = %ld", GAP_PAGES);
>  	}

Otherwise LGTM.
Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr
diff mbox series

Patch

diff --git a/testcases/cve/stack_clash.c b/testcases/cve/stack_clash.c
index 56b970a1b..ae70dd866 100644
--- a/testcases/cve/stack_clash.c
+++ b/testcases/cve/stack_clash.c
@@ -44,6 +44,7 @@ 
 #include <stdlib.h>
 
 #include "tst_test.h"
+#include "tst_kconfig.h"
 #include "tst_safe_stdio.h"
 #include "lapi/mmap.h"
 
@@ -272,19 +273,16 @@  void do_child(void)
 
 void setup(void)
 {
-	char buf[4096], *p;
+	char *p;
 
 	page_size = sysconf(_SC_PAGESIZE);
 	page_mask = ~(page_size - 1);
 
-	buf[4095] = '\0';
-	SAFE_FILE_SCANF("/proc/cmdline", "%4095[^\n]", buf);
+	struct tst_kcmdline_param params = TST_KCMDLINE_INIT("stack_guard_gap");
+	tst_kcmdline_parse(&params, 1);
 
-	if ((p = strstr(buf, "stack_guard_gap=")) != NULL) {
-		if (sscanf(p, "stack_guard_gap=%ld", &GAP_PAGES) != 1) {
-			tst_brk(TBROK | TERRNO, "sscanf");
-			return;
-		}
+	if (params.value[0] != '\0') {
+		GAP_PAGES= atol(params.value);
 		tst_res(TINFO, "stack_guard_gap = %ld", GAP_PAGES);
 	}