aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2018-02-10 04:06:29 (GMT)
committerandroid-build-merger <android-build-merger@google.com>2018-02-10 04:06:29 (GMT)
commit671339863b3a49f0f3e45d0da7c9a3c2a76bfeac (patch)
tree1d7334adfaeb60c3a5f447fe2fdedc41cd906066
parent8aa1c6e7f55dadd0388a3b4d6d0e94678058a12c (diff)
parent0ab691088754405f041ee6e32f13f12aa5074cea (diff)
downloadandroid_external_toybox-671339863b3a49f0f3e45d0da7c9a3c2a76bfeac.zip
android_external_toybox-671339863b3a49f0f3e45d0da7c9a3c2a76bfeac.tar.gz
android_external_toybox-671339863b3a49f0f3e45d0da7c9a3c2a76bfeac.tar.bz2
Merge remote-tracking branch 'toybox/master' into HEAD am: b5517d09b2
am: 0ab6910887 Change-Id: If2999e2badb59cc5fbb67b6ef57a7ee851516b0b
-rw-r--r--lib/lib.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 7f5fbbd..e5c9479 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -1036,13 +1036,13 @@ void names_to_pid(char **names, int (*callback)(pid_t pid, char *name))
for (cur = names; *cur; cur++) {
struct stat st1, st2;
- char *bb = basename(*cur);
- off_t len;
+ char *bb = getbasename(*cur);
+ off_t len = strlen(bb);
- // fast path: only matching a filename (no path) that fits in comm
- if (strncmp(comm, bb, 15)) continue;
- len = strlen(bb);
- if (bb==*cur && len<16) goto match;
+ // Fast path: only matching a filename (no path) that fits in comm.
+ // `len` must be 14 or less because with a full 15 bytes we don't
+ // know whether the name fit or was truncated.
+ if (len<=14 && bb==*cur && !strcmp(comm, bb)) goto match;
// If we have a path to existing file only match if same inode
if (bb!=*cur && !stat(*cur, &st1)) {
@@ -1059,12 +1059,12 @@ void names_to_pid(char **names, int (*callback)(pid_t pid, char *name))
sprintf(cmd = libbuf+16, "/proc/%u/cmdline", u);
len = sizeof(libbuf)-17;
if (!(cmd = readfileat(AT_FDCWD, cmd, cmd, &len))) continue;
- // readfile only guarnatees one null terminator and we need two
+ // readfile only guarantees one null terminator and we need two
// (yes the kernel should do this for us, don't care)
cmd[len] = 0;
}
- if (!strcmp(bb, basename(cmd))) goto match;
- if (bb!=*cur && !strcmp(bb, basename(cmd+strlen(cmd)+1))) goto match;
+ if (!strcmp(bb, getbasename(cmd))) goto match;
+ if (bb!=*cur && !strcmp(bb, getbasename(cmd+strlen(cmd)+1))) goto match;
continue;
match:
if (callback(u, *cur)) break;