Q001
NO.99 Your organization provides a cloud server to your customer to run their Java code. You are reviewing the changes for the next release and you see this change in one of the config files: Which is correct? old: JAVA_OPTS="$JAVA_OPTS -Xms8g -Xmx8g" new: JAVA_OPTS="$JAVA_OPTS -Xms8g -Xmx8g -noverify"
A. You accept the change because -noverify is necessary for your code to run with the latest version of Java. B. You reject the change because -Xms8g -Xmx8g uses too much system memory. C. You accept the change because -noverify is a standard option that has been supported since Java 1.0. D. You reject the change because -noverify is a critical security risk. Answer: D
-noverify 是 JVM 啟動參數之一,用來 跳過 Java 類別驗證階段(bytecode verifier)。正常情況下,JVM 在載入類別時會做安全性檢查,例如類別結構是否合法、是否違反記憶體安全規則等。使用 -noverify 可以略過這些檢查,提升啟動速度,但也可能讓惡意或損壞的 bytecode 被執行。
Q002
NO.141 Your organization makes mlib.jar available to your cloud customers.
While working on a code cleanup project for mlib.jar, you see this method by
customers:
public void enableService(String hostName, String portNumber) throws IOException
{
this.transportSocket = new Socket(hostName, portNumber);
}
What security measures should be added to this method so that it meets the
requirements for a customer accessible method?
A. Insert this code before the call to "new Socket":
hostName = new String(hostName);
portNumber = new String(portNumber);
B. Create a method that validates the hostName and portNumber parameters before
opening the socket.
C. Make enableService private.
D. Enclose the call to new Socket In an AccessController.doPrivileged block.
Answer : D
在 Java 安全模型(尤其是帶 SecurityManager 的環境)中,如果程式碼必須執行一個需要特權的操作(例如開 socket、讀檔、寫檔),而且調用者可能是未授權的外部程式碼,官方文件會建議把這段代碼放到 AccessController.doPrivileged 區塊中,以確保 :
權限檢查時只檢查特權代碼本身的權限不會因為外部不受信任的呼叫鏈而被拒絕。也就是說,考題可能假設: enableService 是授權過的庫方法(mlib.jar 屬於受信任的程式碼) 外部客戶端程式可能在沒有足夠權限的情況下調用它。需要確保 socket 連線的建立權限 檢查不被外部呼叫鏈限制 在這種考試脈絡裡,doPrivileged 被當作「安全封裝敏感操作」的答案。
但在 java 17 的考試中,正確答案是 B。
