Skip to contentSkip to conversation

android: madvise08: fix for android devices.

PATCH New Sandeep Patil 2 participants 3 messages Aug 28, 2017 – Sep 5, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 android: madvise08: fix for android devices.

The test uses '%m' conversion specifier for vfscanf() that is not supported in bionic. Use '%s' instead with a buffer that is substatially larger than the current maximum coredump file name length of 128 bytes.

---
 testcases/kernel/syscalls/madvise/madvise08.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/madvise/madvise08.c +4 -6
index 296c2bff3..813cd687a 100644
@@ -49,10 +49,11 @@
 #define CORE_FILTER "/proc/self/coredump_filter"
 #define YCOUNT 0x500L
 #define FMEMSIZE (YCOUNT + 0x2L)
+#define CORENAME_MAX_SIZE 512
 
 static int dfd;
 static void *fmem;
-static char *cpattern;
+static char cpattern[CORENAME_MAX_SIZE];
 
 static void setup(void)
 {
@@ -80,7 +81,7 @@ static void setup(void)
 	if (!(0x1 & filter))
 		tst_brk(TCONF, "Anonymous private memory is not dumpable.");
 
-	SAFE_FILE_SCANF(CORE_PATTERN, "%m[^\n]", &cpattern);
+	SAFE_FILE_SCANF(CORE_PATTERN, "%s[^\n]", cpattern);
 	tst_res(TINFO, "System core pattern is '%s'", cpattern);
 
 	SAFE_GETCWD(cwd, sizeof(cwd));
@@ -108,10 +109,7 @@ static void setup(void)
 
 static void cleanup(void)
 {
-	if (cpattern)
-		SAFE_FILE_PRINTF(CORE_PATTERN, "%s", cpattern);
-
-	free(cpattern);
+	SAFE_FILE_PRINTF(CORE_PATTERN, "%s", cpattern);
 
 	if (fmem)
 		SAFE_MUNMAP(fmem, FMEMSIZE);
Signature · 1 line
2.14.1.342.g6490525c54-goog
#1 lore raw

PATCH 1/1 android: madvise08: fix for android devices.

Hi!

Quoted 12 lines

static void setup(void)
{

testcases/kernel/syscalls/madvise/madvise08.c +1 -1
@@ -80,7 +81,7 @@ static void setup(void)
 	if (!(0x1 & filter))
 		tst_brk(TCONF, "Anonymous private memory is not dumpable.");
 
-	SAFE_FILE_SCANF(CORE_PATTERN, "%m[^\n]", &cpattern);
+	SAFE_FILE_SCANF(CORE_PATTERN, "%s[^\n]", cpattern);
 	tst_res(TINFO, "System core pattern is '%s'", cpattern);
 
 	SAFE_GETCWD(cwd, sizeof(cwd));

testcases/kernel/syscalls/madvise/madvise08.c static void setup(void) · line 112

Quoted 8 lines
testcases/kernel/syscalls/madvise/madvise08.c +1 -4
@@ -108,10 +109,7 @@ static void setup(void)
 
 static void cleanup(void)
 {
-	if (cpattern)
-		SAFE_FILE_PRINTF(CORE_PATTERN, "%s", cpattern);
-
-	free(cpattern);
+	SAFE_FILE_PRINTF(CORE_PATTERN, "%s", cpattern);

This change breaks the test in a case that tst_brk() is called before we read the cpattern successfully, as we will write and empty string to the cpattern file here in the test cleanup. We have to restore it only and only if it was read correctly. We may as well add a flag called restore_pattern and set it to 1 once we write with SAFE_FILE_PRINTF() in the test setup and use it here.

Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH 1/1 android: madvise08: fix for android devices.

Quoted 14 lines · Cyril Hrubis

Hi!

Quoted 13 lines

static void setup(void)
{

testcases/kernel/syscalls/madvise/madvise08.c +1 -1
@@ -80,7 +81,7 @@ static void setup(void)
 	if (!(0x1 & filter))
 		tst_brk(TCONF, "Anonymous private memory is not dumpable.");
 
-	SAFE_FILE_SCANF(CORE_PATTERN, "%m[^\n]", &cpattern);
+	SAFE_FILE_SCANF(CORE_PATTERN, "%s[^\n]", cpattern);
 	tst_res(TINFO, "System core pattern is '%s'", cpattern);
 
 	SAFE_GETCWD(cwd, sizeof(cwd));
@@ -108,10 +109,7 @@ static void setup(void)
 
Quoted 14 lines

testcases/kernel/syscalls/madvise/madvise08.c static void setup(void) · line 112

Quoted 7 lines
testcases/kernel/syscalls/madvise/madvise08.c +1 -4
 static void cleanup(void)
 {
-	if (cpattern)
-		SAFE_FILE_PRINTF(CORE_PATTERN, "%s", cpattern);
-
-	free(cpattern);
+	SAFE_FILE_PRINTF(CORE_PATTERN, "%s", cpattern);

This change breaks the test in a case that tst_brk() is called before we read the cpattern successfully, as we will write and empty string to the cpattern file here in the test cleanup. We have to restore it only and only if it was read correctly. We may as well add a flag called restore_pattern and set it to 1 once we write with SAFE_FILE_PRINTF() in the test setup and use it here.

Ack and I did miss that path. Fixing in v2 with a 'restore_cpattern' flag.

- ssp

Quoted 4 lines
Signature · 3 lines
-- 
Cyril Hrubis
[email protected]