Skip to content

Commit

Permalink
Don't read past allocated buffer for string (oshi#1082)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwiddis authored Jan 12, 2020
1 parent 062e772 commit 44815a6
Showing 1 changed file with 1 addition and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,9 @@ public OSProcess getProcess(int pid, boolean slowFields) {
}

private OSProcess getProcess(int pid, LinuxUserGroupInfo userGroupInfo, boolean slowFields) {
String path = "";
Pointer buf = new Memory(1024);
int size = LinuxLibc.INSTANCE.readlink(String.format("/proc/%d/exe", pid), buf, 1023);
if (size > 0) {
String tmp = buf.getString(0);
path = tmp.substring(0, tmp.length() < size ? tmp.length() : size);
}
String path = size > 0 ? new String(buf.getByteArray(0, size)) : "";
Map<String, String> io = FileUtil.getKeyValueMapFromFile(String.format("/proc/%d/io", pid), ":");
// See man proc for how to parse /proc/[pid]/stat
long now = System.currentTimeMillis();
Expand Down

0 comments on commit 44815a6

Please sign in to comment.