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

Commit f1930a12 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Scramble input windows during fuzzing

Add functionality of scrambling windows for the dispatcher fuzzer.
This allows greater coverage of the dispatcher code.

Also, skip events with ACTION_SCROLL because they might contain an
invalid number of pointers, and they won't correctly be rejected because
we aren't verifying them right now.

Bug: 287342122
Test: FUZZER=inputflinger_input_dispatcher_fuzzer; m $FUZZER && ASAN_OPTIONS=detect_odr_violation=0 $ANDROID_HOST_OUT/fuzz/x86_64/$FUZZER/$FUZZER
Change-Id: I6715ee0327cb5cde76996f1c6a80ceba15030aef
parent bee1f544
Loading
Loading
Loading
Loading
+31 −11
Original line number Diff line number Diff line
@@ -65,6 +65,27 @@ private:
    std::map<int32_t /*displayId*/, InputVerifier> mVerifiers;
};

void scrambleWindow(FuzzedDataProvider& fdp, FakeWindowHandle& window) {
    const int32_t left = fdp.ConsumeIntegralInRange<int32_t>(0, 100);
    const int32_t top = fdp.ConsumeIntegralInRange<int32_t>(0, 100);
    const int32_t width = fdp.ConsumeIntegralInRange<int32_t>(0, 100);
    const int32_t height = fdp.ConsumeIntegralInRange<int32_t>(0, 100);

    window.setFrame(Rect(left, top, left + width, top + height));
    window.setSlippery(fdp.ConsumeBool());
    window.setDupTouchToWallpaper(fdp.ConsumeBool());
    window.setIsWallpaper(fdp.ConsumeBool());
    window.setVisible(fdp.ConsumeBool());
    window.setPreventSplitting(fdp.ConsumeBool());
    const bool isTrustedOverlay = fdp.ConsumeBool();
    window.setTrustedOverlay(isTrustedOverlay);
    if (isTrustedOverlay) {
        window.setSpy(fdp.ConsumeBool());
    } else {
        window.setSpy(false);
    }
}

} // namespace

sp<FakeWindowHandle> generateFuzzedWindow(FuzzedDataProvider& fdp, InputDispatcher& dispatcher,
@@ -73,17 +94,9 @@ sp<FakeWindowHandle> generateFuzzedWindow(FuzzedDataProvider& fdp, InputDispatch
    std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
    std::string windowName = android::base::StringPrintf("Win") + std::to_string(windowNumber++);
    sp<FakeWindowHandle> window =
            sp<FakeWindowHandle>::make(application, dispatcher, "Fake", displayId);
            sp<FakeWindowHandle>::make(application, dispatcher, windowName, displayId);

    const int32_t left = fdp.ConsumeIntegralInRange<int32_t>(0, 100);
    const int32_t top = fdp.ConsumeIntegralInRange<int32_t>(0, 100);
    const int32_t width = fdp.ConsumeIntegralInRange<int32_t>(0, 100);
    const int32_t height = fdp.ConsumeIntegralInRange<int32_t>(0, 100);

    window->setFrame(Rect(left, top, left + width, top + height));
    window->setSlippery(fdp.ConsumeBool());
    window->setDupTouchToWallpaper(fdp.ConsumeBool());
    window->setTrustedOverlay(fdp.ConsumeBool());
    scrambleWindow(fdp, *window);
    return window;
}

@@ -113,7 +126,14 @@ void randomizeWindows(
                    windowsPerDisplay.erase(displayId);
                }
            },
            // Could also clone a window, change flags, reposition, etc...
            // Change flags or move some of the existing windows
            [&]() -> void {
                for (auto& window : windows) {
                    if (fdp.ConsumeBool()) {
                        scrambleWindow(fdp, *window);
                    }
                }
            },
    })();
}