mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8229872: (fs) Increase buffer size used with getmntent
Dynamically allocate memory for getmntent Reviewed-by: alanb
This commit is contained in:
parent
628283fe53
commit
67ad501e5b
5 changed files with 89 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -79,10 +79,26 @@ class LinuxFileSystem extends UnixFileSystem {
|
|||
ArrayList<UnixMountEntry> entries = new ArrayList<>();
|
||||
try {
|
||||
long fp = setmntent(Util.toBytes(fstab), Util.toBytes("r"));
|
||||
int maxLineSize = 1024;
|
||||
try {
|
||||
for (;;) {
|
||||
int lineSize = getlinelen(fp);
|
||||
if (lineSize == -1)
|
||||
break;
|
||||
if (lineSize > maxLineSize)
|
||||
maxLineSize = lineSize;
|
||||
}
|
||||
} catch (UnixException x) {
|
||||
// nothing we need to do
|
||||
} finally {
|
||||
rewind(fp);
|
||||
}
|
||||
|
||||
try {
|
||||
for (;;) {
|
||||
UnixMountEntry entry = new UnixMountEntry();
|
||||
int res = getmntent(fp, entry);
|
||||
// count in NUL character at the end
|
||||
int res = getmntent(fp, entry, maxLineSize + 1);
|
||||
if (res < 0)
|
||||
break;
|
||||
entries.add(entry);
|
||||
|
|
|
@ -51,7 +51,17 @@ class LinuxNativeDispatcher extends UnixNativeDispatcher {
|
|||
/**
|
||||
* int getmntent(FILE *fp, struct mnttab *mp, int len);
|
||||
*/
|
||||
static native int getmntent(long fp, UnixMountEntry entry)
|
||||
|
||||
static int getmntent(long fp, UnixMountEntry entry, int buflen) throws UnixException {
|
||||
NativeBuffer buffer = NativeBuffers.getNativeBuffer(buflen);
|
||||
try {
|
||||
return getmntent0(fp, entry, buffer.address(), buflen);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
|
||||
static native int getmntent0(long fp, UnixMountEntry entry, long buffer, int bufLen)
|
||||
throws UnixException;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue