From e2ef39fae5ffb576cdc4d924cf0b67393138168d Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 25 Mar 2019 11:33:32 +0100 Subject: [PATCH 1/5] Fix overflow in test The serialized text is not nul-terminated (its size is explicitely provided), but the input text in the event is a nul-terminated string. The test was failing with ASAN enabled. --- app/tests/test_control_event_serialize.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/tests/test_control_event_serialize.c b/app/tests/test_control_event_serialize.c index f6034370..90b75fff 100644 --- a/app/tests/test_control_event_serialize.c +++ b/app/tests/test_control_event_serialize.c @@ -49,13 +49,14 @@ static void test_serialize_text_event(void) { static void test_serialize_long_text_event(void) { struct control_event event; event.type = CONTROL_EVENT_TYPE_TEXT; - char text[TEXT_MAX_LENGTH]; + char text[TEXT_MAX_LENGTH + 1]; memset(text, 'a', sizeof(text)); + text[TEXT_MAX_LENGTH] = '\0'; event.text_event.text = text; unsigned char buf[SERIALIZED_EVENT_MAX_SIZE]; int size = control_event_serialize(&event, buf); - assert(size == 3 + sizeof(text)); + assert(size == 3 + TEXT_MAX_LENGTH); unsigned char expected[3 + TEXT_MAX_LENGTH]; expected[0] = 0x01; // CONTROL_EVENT_TYPE_KEYCODE From f11b0ec2043ba912e91efce8bb30ecc547dc0aef Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 27 Mar 2019 21:47:54 +0100 Subject: [PATCH 2/5] Fix server checkstyle errors Fix errors reported by: gradle -p server check --- .../src/main/java/com/genymobile/scrcpy/EventController.java | 1 - server/src/main/java/com/genymobile/scrcpy/IO.java | 2 +- .../src/main/java/com/genymobile/scrcpy/ScreenEncoder.java | 1 - server/src/main/java/com/genymobile/scrcpy/Server.java | 5 +++-- .../com/genymobile/scrcpy/wrappers/StatusBarManager.java | 2 -- 5 files changed, 4 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/EventController.java b/server/src/main/java/com/genymobile/scrcpy/EventController.java index 5fa2cab2..341869fa 100644 --- a/server/src/main/java/com/genymobile/scrcpy/EventController.java +++ b/server/src/main/java/com/genymobile/scrcpy/EventController.java @@ -1,7 +1,6 @@ package com.genymobile.scrcpy; import com.genymobile.scrcpy.wrappers.InputManager; -import com.genymobile.scrcpy.wrappers.ServiceManager; import android.graphics.Point; import android.os.SystemClock; diff --git a/server/src/main/java/com/genymobile/scrcpy/IO.java b/server/src/main/java/com/genymobile/scrcpy/IO.java index f1f05105..57c017db 100644 --- a/server/src/main/java/com/genymobile/scrcpy/IO.java +++ b/server/src/main/java/com/genymobile/scrcpy/IO.java @@ -8,7 +8,7 @@ import java.io.FileDescriptor; import java.io.IOException; import java.nio.ByteBuffer; -public class IO { +public final class IO { private IO() { // not instantiable } diff --git a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java index 22eb6a54..c946e990 100644 --- a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java +++ b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java @@ -3,7 +3,6 @@ package com.genymobile.scrcpy; import com.genymobile.scrcpy.wrappers.SurfaceControl; import android.graphics.Rect; -import android.media.MediaMuxer; import android.media.MediaCodec; import android.media.MediaCodecInfo; import android.media.MediaFormat; diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index fb2ba461..b782101c 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -4,7 +4,6 @@ import android.graphics.Rect; import java.io.File; import java.io.IOException; -import java.util.Arrays; public final class Server { @@ -49,8 +48,9 @@ public final class Server { @SuppressWarnings("checkstyle:MagicNumber") private static Options createOptions(String... args) { - if (args.length != 5) + if (args.length != 5) { throw new IllegalArgumentException("Expecting 5 parameters"); + } Options options = new Options(); @@ -73,6 +73,7 @@ public final class Server { return options; } + @SuppressWarnings("checkstyle:MagicNumber") private static Rect parseCrop(String crop) { if ("-".equals(crop)) { return null; diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/StatusBarManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/StatusBarManager.java index aacd5f1a..8f79f51f 100644 --- a/server/src/main/java/com/genymobile/scrcpy/wrappers/StatusBarManager.java +++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/StatusBarManager.java @@ -1,8 +1,6 @@ package com.genymobile.scrcpy.wrappers; -import android.annotation.SuppressLint; import android.os.IInterface; -import android.view.InputEvent; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; From 66baf0f95b3c0fc0b4e56e53cf8f69ff23645be8 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 27 Mar 2019 21:50:25 +0100 Subject: [PATCH 3/5] Run tests with ASAN enabled This may capture more errors (like e2ef39fae5ffb576cdc4d924cf0b67393138168d). --- release.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/release.sh b/release.sh index ca632e00..31720f63 100755 --- a/release.sh +++ b/release.sh @@ -1,13 +1,18 @@ #!/bin/bash set -e -# build and test locally +# test locally +TESTDIR=build_test +rm -rf "$TESTDIR" +# run client tests with ASAN enabled +meson "$TESTDIR" -Db_sanitize=address +ninja -C"$TESTDIR" test + BUILDDIR=build_release rm -rf "$BUILDDIR" meson "$BUILDDIR" --buildtype release --strip -Db_lto=true cd "$BUILDDIR" ninja -ninja test cd - # build Windows releases From 5254e585c60c20f2f2ccfc360eba80d607db273e Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 27 Mar 2019 21:51:42 +0100 Subject: [PATCH 4/5] Run server tests on release --- release.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/release.sh b/release.sh index 31720f63..fbd1eb54 100755 --- a/release.sh +++ b/release.sh @@ -8,6 +8,10 @@ rm -rf "$TESTDIR" meson "$TESTDIR" -Db_sanitize=address ninja -C"$TESTDIR" test +# test server +GRADLE=${GRADLE:-./gradlew} +$GRADLE -p server check + BUILDDIR=build_release rm -rf "$BUILDDIR" meson "$BUILDDIR" --buildtype release --strip -Db_lto=true From ffa8c66979d4262a95cad584894b9a5fbeea0e84 Mon Sep 17 00:00:00 2001 From: Gerdal Date: Wed, 27 Mar 2019 19:37:44 +0100 Subject: [PATCH 5/5] Fix link error on Windows Subsystem for Linux Build failed on WSL because of lack of reference to WinMain@16 during linking. Fixes Signed-off-by: Romain Vimont --- app/src/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main.c b/app/src/main.c index b2a6bf5e..c61db725 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -5,6 +5,7 @@ #include #include #include +#define SDL_MAIN_HANDLED // avoid link error on Linux Windows Subsystem #include #include "compat.h"