Reputation: 21
When I try to build this project, I'm getting several errors:
Build command failed.
Error while executing process E:\sdk\ndk-bundle\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=D:\TASK\workspace_3\android-event-injector-master\AndroidEventInjector\src\main\jni\Android.mk APP_ABI=x86_64 NDK_ALL_ABIS=x86_64 NDK_DEBUG=1 APP_PLATFORM=android-21 NDK_OUT=D:/TASK/workspace_3/android-event-injector-master/AndroidEventInjector/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=D:\TASK\workspace_3\android-event-injector-master\AndroidEventInjector\build\intermediates\ndkBuild\debug\lib D:/TASK/workspace_3/android-event-injector-master/AndroidEventInjector/build/intermediates/ndkBuild/debug/obj/local/x86_64/libEventInjector.so}
[x86_64] Compile : EventInjector <= EventInjector.c
D:/TASK/workspace_3/android-event-injector-master/AndroidEventInjector/src/main/jni/EventInjector.c:83:7:
error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
LOGD(szBuffer);
^~~~~~~~
D:/TASK/workspace_3/android-event-injector-master/AndroidEventInjector/src/main/jni/EventInjector.c:49:65:
note: expanded from macro 'LOGD'
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG , TAG, VA_ARGS)
^~~~~~~~~~~
D:/TASK/workspace_3/android-event-injector-master/AndroidEventInjector/src/main/jni/EventInjector.c:83:7:
note: treat the string as an argument to avoid this
LOGD(szBuffer);
^
"%s",
D:/TASK/workspace_3/android-event-injector-master/AndroidEventInjector/src/main/jni/EventInjector.c:49:65:
note: expanded from macro 'LOGD'
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG , TAG, VA_ARGS)
^
D:/TASK/workspace_3/android-event-injector-master/AndroidEventInjector/src/main/jni/EventInjector.c:242:28:
error: non-void function 'Java_net_pocketmagic_android_eventinjector_Events_intSendEvent' should return a value [-Wreturn-type]
if (fd <= fileno(stderr)) return;
^
2 errors generated.
make: *** [D:/TASK/workspace_3/android-event-injector-master/AndroidEventInjector/build/intermediates/ndkBuild/debug/obj/local/x86_64/objs-debug/EventInjector/EventInjector.o] Error 1
Upvotes: 1
Views: 793
Reputation: 3986
It seems likely that both of these errors were treated as warnings (and suppressed or ignored) when the original Github uploader was building this.
They are showing up as errors when you build (as they should, IMO) due to different compiler settings or defaults.
In the short term, you can change your compiler flags to ignore these, but it would be better if you actually fixed them (and submitted a pull request to Github), or at least notified the maintainer to do so.
EventInjector.c(83:7): error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
LOGD(szBuffer);
^~~~~~~~
Looks like this macro is used like printf, e.g.:
LOGD("The %s is %d years old", "dog", 7);
So the first argument is interpreted specially; a string with special formatting sequences (e.g. '%s').
This warning/error is alerting you of the danger in passing in something that might be user data, e.g. LOGD(user_input)
. If user_input
doesn't contain any special formatting characters ('%'), then you're probably fine.
But if it does, then the logging function will expect additional arguments to follow (which you didn't provide), so it'll grab something off of the stack that it shouldn't. This is a security vulnerability as well as a potential crash.
The solution to this is to add a literal format string:
LOGD("%s", szBuffer);
...this way szBuffer
can contain anything, and it won't mess things up.
EventInjector.c(242:28): error: non-void function 'Java_net_pocketmagic_android_eventinjector_Events_intSendEvent' should return a value [-Wreturn-type]
if (fd <= fileno(stderr)) return;
^
The Java_net_pocketmagic_android_eventinjector_Events_intSendEvent
function is declared as returning a jint
, but the return statement above isn't returning anything. The caller is going to get something, so what should the compiler do?
This is usually due to an oversight made by the developer, so it's being treated as an error, though it can be treated as a warning, with the compiler simply returning the default value for the 'jint' type.
The solution to this is to add a value after the return. If you disable this error/warning, I believe the compiler will generate code to return (jint)0
by default.
Instead, I'd go ahead and fix it:
if (fd <= fileno(stderr)) return (jint)0;
The rest of the lines in your error output were just additional notes about the first error. Those two fixes should get you going.
Upvotes: 2