Skip to contentSkip to conversation

verify_caps_exec: Replace index() with strchr()

PATCH New Alistair Strachan 2 participants 6 messages Jun 24, 2018 – Jul 23, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 verify_caps_exec: Replace index() with strchr()

The index() function was removed in POSIX.2008. It is not implemented by Android's bionic C library for 64-bit platforms.

Use the more portable strchr() function from C89.

---
 testcases/kernel/security/filecaps/verify_caps_exec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/security/filecaps/verify_caps_exec.c +1 -1
index 2c5cc0b2a..7183d8b4a 100644
@@ -186,7 +186,7 @@ static int fork_drop_and_exec(int keepperms, cap_t expected_caps)
 				 "got a bad seqno (c=%d, s=%d, seqno=%d)", c, s,
 				 seqno);
 		}
-		p = index(buf, '.');
+		p = strchr(buf, '.');
 		if (!p)
 			tst_brkm(TFAIL, NULL,
 				 "got a bad message from print_caps\n");
#1 lore raw

PATCH 1/1 verify_caps_exec: Replace index() with strchr()

Hi Alistair,

Quoted 15 lines

The index() function was removed in POSIX.2008. It is not implemented by Android's bionic C library for 64-bit platforms.

Use the more portable strchr() function from C89.

---
 testcases/kernel/security/filecaps/verify_caps_exec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/security/filecaps/verify_caps_exec.c +0 -0
index 2c5cc0b2a..7183d8b4a 100644

testcases/kernel/security/filecaps/verify_caps_exec.c static int fork_drop_and_exec(int keepperms, cap_t expected_caps) · line 192

Quoted 8 lines
testcases/kernel/security/filecaps/verify_caps_exec.c +1 -1
@@ -186,7 +186,7 @@ static int fork_drop_and_exec(int keepperms, cap_t expected_caps)
 				 "got a bad seqno (c=%d, s=%d, seqno=%d)", c, s,
 				 seqno);
 		}
-		p = index(buf, '.');
+		p = strchr(buf, '.');
 		if (!p)
 			tst_brkm(TFAIL, NULL,
 				 "got a bad message from print_caps\n");

Thanks for your patch, merged.

BTW there are more uses of index() / rindex() in the project.

Kind regards,
Petr

#2 lore raw

PATCH 1/1 cpuset_lib: Replace index() with strchr()

The index() function was removed in POSIX.2008. It is not implemented by Android's bionic C library for 64-bit platforms.

Use the more portable strchr() function from C89.

---
 testcases/kernel/controllers/cpuset/cpuset_lib/cpuinfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/controllers/cpuset/cpuset_lib/cpuinfo.c +1 -1
index c2a60b683..575a61bcd 100644
@@ -59,7 +59,7 @@ static int get_cpu_baseinfo(void)
 	/* get cpuinfo */
 	while (fgets(buf, sizeof(buf), fp) != NULL) {
 		istr = strtok_r(buf, "\t", &saveptr);
-		valstr = index(saveptr, ':');
+		valstr = strchr(saveptr, ':');
 		if (valstr == NULL)
 			continue;
 		valstr++;
#3 lore raw

PATCH 1/1 pounder21: Replace {r,}index() with str{r,}chr()

The index() and rindex() functions were removed in POSIX.2008. They are not implemented by Android's bionic C library for 64-bit platforms.

Use the more portable strchr() and strrchr() functions from C89.

Affects fancy_timed_loop, infinite_loop, run-helper, and timed_loop targets.

---
 tools/pounder21/fancy_timed_loop.c | 4 ++--
 tools/pounder21/infinite_loop.c    | 4 ++--
 tools/pounder21/run.c              | 6 +++---
 tools/pounder21/timed_loop.c       | 4 ++--
 4 files changed, 9 insertions(+), 9 deletions(-)
tools/pounder21/fancy_timed_loop.c +2 -2
index ac3e204d1..f88be3df8 100644
@@ -93,14 +93,14 @@ int main(int argc, char *argv[])
 	out = stdout;
 
 	if (use_max_failures) {
-		progname = rindex(argv[7], '/');
+		progname = strrchr(argv[7], '/');
 		if (progname == NULL) {
 			progname = argv[7];
 		} else {
 			progname++;
 		}
 	} else {
-		progname = rindex(argv[5], '/');
+		progname = strrchr(argv[5], '/');
 		if (progname == NULL) {
 			progname = argv[5];
 		} else {
tools/pounder21/infinite_loop.c +2 -2
index fbe4289ac..e1a0d3dfb 100644
@@ -78,14 +78,14 @@ int main(int argc, char *argv[])
 	out = stdout;
 
 	if (use_max_failures) {
-		progname = rindex(argv[3], '/');
+		progname = strrchr(argv[3], '/');
 		if (progname == NULL) {
 			progname = argv[3];
 		} else {
 			progname++;
 		}
 	} else {
-		progname = rindex(argv[1], '/');
+		progname = strrchr(argv[1], '/');
 		if (progname == NULL) {
 			progname = argv[1];
 		} else {
tools/pounder21/run.c +3 -3
index dec2d3fe7..5f5903c45 100644
@@ -167,7 +167,7 @@ int main(int argc, char *argv[])
 		retcode = process_dir(argv[1]);
 	} else {
 		if (is_executable(argv[1])) {
-			c = rindex(argv[1], '/');
+			c = strrchr(argv[1], '/');
 			c++;
 
 			// Start the test
@@ -495,7 +495,7 @@ static pid_t spawn_test(char *fname)
 			 getenv("POUNDER_LOGDIR"), fname);
 
 		fd = strlen(buf2);
-		for (tmp = (index(buf2, '|') - buf2); tmp < fd; tmp++) {
+		for (tmp = (strchr(buf2, '|') - buf2); tmp < fd; tmp++) {
 			if (buf2[tmp] == '/') {
 				buf2[tmp] = '-';
 			} else if (buf2[tmp] == '|') {
@@ -541,7 +541,7 @@ static pid_t spawn_test(char *fname)
 		snprintf(buf2, TEST_PATH_LEN, "%s/%s", buf, fname);
 
 		// find the location of the last slash
-		last_slash = rindex(buf2, '/');
+		last_slash = strrchr(buf2, '/');
 
 		if (last_slash != NULL) {
 			// copy the filename part into a new buffer
tools/pounder21/timed_loop.c +2 -2
index 51ceac5f2..3dffba0dc 100644
@@ -95,14 +95,14 @@ int main(int argc, char *argv[])
 	out = stdout;
 
 	if (use_max_failures) {
-		progname = rindex(argv[4], '/');
+		progname = strrchr(argv[4], '/');
 		if (progname == NULL) {
 			progname = argv[4];
 		} else {
 			progname++;
 		}
 	} else {
-		progname = rindex(argv[2], '/');
+		progname = strrchr(argv[2], '/');
 		if (progname == NULL) {
 			progname = argv[2];
 		} else {
#4 lore raw

PATCH 1/1 pounder21: Replace {r,}index() with str{r,}chr()

Hi Alistair,

Quoted 9 lines

The index() and rindex() functions were removed in POSIX.2008. They are not implemented by Android's bionic C library for 64-bit platforms.

Use the more portable strchr() and strrchr() functions from C89.

Affects fancy_timed_loop, infinite_loop, run-helper, and timed_loop targets.

Patch merged, thanks!

Kind regards,
Petr