shill: add unit tests for OnRawNlMessageReceived

Add unit tests that verify that NetlinkManager handles malformed
netlink messages in a reasonable way. This led me to revise the
checks in OnRawNlMessageReceived...

We now validate that we have read enough bytes for an entire nlmsghdr,
instead of just the length field of the header. This eliminates the
possibility of a bad memory access when OnNlMessageReceived reads
the sequence number field of the nlmsghdr.

While there:
- Have the NetlinkManagerTest fixture check the nullity of
  netlink_manager_ before dereferencing it.
- Fully reset the NetlinkManager singleton when the NetlinkManagerTest
  fixture is destroyed. This ensures that each test finds the fixture
  in the same initial state.
- Change netlink_socket_ from an inline member to a raw pointer, so
  that we can pass ownership to NetlinkManager (but also retain a reference
  to it).

BUG=chromium:313000
TEST=USE="asan clang" FEATURES="test" P2_TEST_FILTER="shill::*" emerge-peppy platform2

Change-Id: Ibdbe5574badf6963ade22dec546ade040c27686c
Reviewed-on: https://chromium-review.googlesource.com/175855
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Commit-Queue: mukesh agrawal <quiche@chromium.org>
Tested-by: mukesh agrawal <quiche@chromium.org>
diff --git a/netlink_manager.h b/netlink_manager.h
index 1d714e2..c7fe231 100644
--- a/netlink_manager.h
+++ b/netlink_manager.h
@@ -248,6 +248,7 @@
   FRIEND_TEST(NetlinkManagerTest, GetFamilyTimeout);
   FRIEND_TEST(NetlinkManagerTest, MessageHandler);
   FRIEND_TEST(NetlinkManagerTest, MultipartMessageHandler);
+  FRIEND_TEST(NetlinkManagerTest, OnInvalidRawNlMessageReceived);
   FRIEND_TEST(NetlinkManagerTest, TimeoutResponseHandlers);
   FRIEND_TEST(NetlinkMessageTest, Parse_NL80211_CMD_ASSOCIATE);
   FRIEND_TEST(NetlinkMessageTest, Parse_NL80211_CMD_AUTHENTICATE);