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

Commit 10ebb3db authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN Committed by Gerrit Code Review
Browse files

Merge "Fix potential exceptions in FdEventReader users"

parents 084a034f ffa12ecf
Loading
Loading
Loading
Loading
+17 −13
Original line number Original line Diff line number Diff line
@@ -106,6 +106,7 @@ public class NetlinkMonitor extends PacketReader {
        byteBuffer.order(ByteOrder.nativeOrder());
        byteBuffer.order(ByteOrder.nativeOrder());


        while (byteBuffer.remaining() > 0) {
        while (byteBuffer.remaining() > 0) {
            try {
                final int position = byteBuffer.position();
                final int position = byteBuffer.position();
                final NetlinkMessage nlMsg = NetlinkMessage.parse(byteBuffer);
                final NetlinkMessage nlMsg = NetlinkMessage.parse(byteBuffer);
                if (nlMsg == null || nlMsg.getHeader() == null) {
                if (nlMsg == null || nlMsg.getHeader() == null) {
@@ -120,6 +121,9 @@ public class NetlinkMonitor extends PacketReader {
                }
                }


                processNetlinkMessage(nlMsg, whenMs);
                processNetlinkMessage(nlMsg, whenMs);
            } catch (Throwable e) {
                mLog.e("Error handling netlink message", e);
            }
        }
        }
    }
    }


+2 −0
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ import android.os.Looper;
import android.os.MessageQueue;
import android.os.MessageQueue;
import android.system.ErrnoException;
import android.system.ErrnoException;
import android.system.OsConstants;
import android.system.OsConstants;
import android.util.Log;


import androidx.annotation.NonNull;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Nullable;
@@ -244,6 +245,7 @@ public abstract class FdEventsReader<BufferType> {
                handlePacket(mBuffer, bytesRead);
                handlePacket(mBuffer, bytesRead);
            } catch (Exception e) {
            } catch (Exception e) {
                logError("handlePacket error: ", e);
                logError("handlePacket error: ", e);
                Log.wtf(FdEventsReader.class.getSimpleName(), "Error handling packet: stopping", e);
                break;
                break;
            }
            }
        }
        }
+3 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ package android.net.dhcp;
import android.net.util.FdEventsReader;
import android.net.util.FdEventsReader;
import android.os.Handler;
import android.os.Handler;
import android.system.Os;
import android.system.Os;
import android.util.Log;


import androidx.annotation.NonNull;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Nullable;
@@ -59,6 +60,8 @@ abstract class DhcpPacketListener extends FdEventsReader<DhcpPacketListener.Payl
            onReceive(packet, recvbuf.mSrcAddr, recvbuf.mSrcPort);
            onReceive(packet, recvbuf.mSrcAddr, recvbuf.mSrcPort);
        } catch (DhcpPacket.ParseException e) {
        } catch (DhcpPacket.ParseException e) {
            logParseError(recvbuf.mBytes, length, e);
            logParseError(recvbuf.mBytes, length, e);
        } catch (Throwable e) {
            Log.wtf(DhcpPacketListener.class.getSimpleName(), "Error handling DHCP packet", e);
        }
        }
    }
    }


+8 −3
Original line number Original line Diff line number Diff line
@@ -133,9 +133,14 @@ public class ConnectivityPacketTracker {
                return;
                return;
            }
            }


            final String summary = ConnectivityPacketSummary.summarize(
            final String summary;
                    mInterface.macAddr, recvbuf, length);
            try {
                summary = ConnectivityPacketSummary.summarize(mInterface.macAddr, recvbuf, length);
                if (summary == null) return;
                if (summary == null) return;
            } catch (Exception e) {
                if (DBG) Log.d(mTag, "Error creating packet summary", e);
                return;
            }


            if (DBG) Log.d(mTag, summary);
            if (DBG) Log.d(mTag, summary);
            addLogEntry(summary + "\n[" + HexDump.toHexString(recvbuf, 0, length) + "]");
            addLogEntry(summary + "\n[" + HexDump.toHexString(recvbuf, 0, length) + "]");
+12 −3
Original line number Original line Diff line number Diff line
@@ -340,7 +340,14 @@ public class IpReachabilityMonitor {
            // TODO: Consider using NeighborEvent#isValid() here; it's more
            // TODO: Consider using NeighborEvent#isValid() here; it's more
            // strict but may interact badly if other entries are somehow in
            // strict but may interact badly if other entries are somehow in
            // NUD_INCOMPLETE (say, during network attach).
            // NUD_INCOMPLETE (say, during network attach).
            if (entry.getValue().nudState != StructNdMsg.NUD_FAILED) continue;
            final NeighborEvent val = entry.getValue();

            // Find all the neighbors that have gone into FAILED state.
            // Ignore entries for which we have never received an event. If there are neighbors
            // that never respond to ARP/ND, the kernel will send several FAILED event, then
            // an INCOMPLETE event, and then more FAILED events. The INCOMPLETE event will
            // populate the map and the subsequent FAILED event will be processed.
            if (val == null || val.nudState != StructNdMsg.NUD_FAILED) continue;


            ip = entry.getKey();
            ip = entry.getKey();
            for (RouteInfo route : mLinkProperties.getRoutes()) {
            for (RouteInfo route : mLinkProperties.getRoutes()) {
@@ -377,10 +384,12 @@ public class IpReachabilityMonitor {
                Log.d(TAG, "neighbour IPv4(v6): " + entry.getKey() + " neighbour state: "
                Log.d(TAG, "neighbour IPv4(v6): " + entry.getKey() + " neighbour state: "
                        + StructNdMsg.stringForNudState(entry.getValue().nudState));
                        + StructNdMsg.stringForNudState(entry.getValue().nudState));
            }
            }
            if (entry.getValue().nudState != StructNdMsg.NUD_REACHABLE) return;
            final NeighborEvent val = entry.getValue();
            // If an entry is null, consider that probing for that neighbour has completed.
            if (val == null || val.nudState != StructNdMsg.NUD_REACHABLE) return;
        }
        }


        // All neighbours in the watchlist are in REACHABLE state and connection is stable,
        // Probing for all neighbours in the watchlist is complete and the connection is stable,
        // restore NUD probe parameters to steadystate value. In the case where neighbours
        // restore NUD probe parameters to steadystate value. In the case where neighbours
        // are responsive, this code will run before the wakelock expires.
        // are responsive, this code will run before the wakelock expires.
        setNeighbourParametersForSteadyState();
        setNeighbourParametersForSteadyState();
Loading