Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2c3332c9 authored by Xiao Ma's avatar Xiao Ma
Browse files

Fix the potential BufferUnderflowException when parsing ByteBuffer.

Miss catching BufferUnderflowException when converting ByteBuffer to
bytes array for InformationElement member of ScanResultInfo, it might
throw BufferUnderflowException when calling ByteBuffer.get() method.
Reset the position of copied ByteBuffer before calling get() method
should prevent BufferUnderflowException to be thrown.

Bug: 137835398
Test: atest NetworkStackIntegrationTests FrameworksNetTests
Change-Id: I96c548ff9df4989769127d11abd9ed1a79631e05
parent 91409817
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -29,7 +29,9 @@ import android.net.ScanResultInfoParcelable;
import android.net.StaticIpConfiguration;
import android.net.apf.ApfCapabilities;
import android.net.ip.IIpClient;
import android.util.Log;

import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
@@ -61,6 +63,8 @@ import java.util.StringJoiner;
 * @hide
 */
public class ProvisioningConfiguration {
    private static final String TAG = "ProvisioningConfiguration";

    // TODO: Delete this default timeout once those callers that care are
    // fixed to pass in their preferred timeout.
    //
@@ -281,7 +285,7 @@ public class ProvisioningConfiguration {
            public InformationElementParcelable toStableParcelable() {
                final InformationElementParcelable p = new InformationElementParcelable();
                p.id = mId;
                p.payload = mPayload.clone();
                p.payload = mPayload != null ? mPayload.clone() : null;
                return p;
            }

@@ -367,12 +371,18 @@ public class ProvisioningConfiguration {

        private static byte[] convertToByteArray(final ByteBuffer buffer) {
            if (buffer == null) return null;
            byte[] bytes = new byte[buffer.limit()];
            final byte[] bytes = new byte[buffer.limit()];
            final ByteBuffer copy = buffer.asReadOnlyBuffer();
            try {
                copy.position(0);
                copy.get(bytes);
            } catch (BufferUnderflowException e) {
                Log.wtf(TAG, "Buffer under flow exception should never happen.");
            } finally {
                return bytes;
            }
        }
    }

    public boolean mEnableIPv4 = true;
    public boolean mEnableIPv6 = true;