Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation with last NDK + some hardening #13

Closed
af-anssi opened this issue Jun 20, 2018 · 6 comments
Closed

Fix compilation with last NDK + some hardening #13

af-anssi opened this issue Jun 20, 2018 · 6 comments

Comments

@af-anssi
Copy link

I have a trivial patch to submit to compile with the last NDK and include some hardening measures in the produced library. Where can I send/submit it ?
I paste it below but tell me if I have to submit it somewhere else.

diff --git a/android/olm-sdk/src/main/jni/Android.mk b/android/olm-sdk/src/main/jni/Android.mk
index aceaef0..44a2787 100644
--- a/android/olm-sdk/src/main/jni/Android.mk
+++ b/android/olm-sdk/src/main/jni/Android.mk
@@ -21,6 +21,9 @@ LOCAL_CFLAGS+= -DOLMLIB_VERSION_MAJOR=$(MAJOR) \
 
 #LOCAL_CFLAGS+= -DNDK_DEBUG
 
+LOCAL_CFLAGS+=-fstack-protector-all -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Wall
+LOCAL_LDFLAGS=-z relro -z now
+
 LOCAL_C_INCLUDES+= $(LOCAL_PATH)/$(SRC_ROOT_DIR)/include/ \
 $(LOCAL_PATH)/$(SRC_ROOT_DIR)/lib
 
diff --git a/android/olm-sdk/src/main/jni/Application.mk b/android/olm-sdk/src/main/jni/Application.mk
index 6516f5e..63c175e 100644
--- a/android/olm-sdk/src/main/jni/Application.mk
+++ b/android/olm-sdk/src/main/jni/Application.mk
@@ -1,3 +1,3 @@
 APP_PLATFORM := android-16
-APP_ABI := arm64-v8a armeabi-v7a armeabi x86_64  x86
-APP_STL := gnustl_static
\ No newline at end of file
+APP_ABI := arm64-v8a armeabi-v7a x86_64  x86
+APP_STL := gnustl_static
diff --git a/android/olm-sdk/src/main/jni/olm_account.cpp b/android/olm-sdk/src/main/jni/olm_account.cpp
index 40081ac..bdd6db3 100644
--- a/android/olm-sdk/src/main/jni/olm_account.cpp
+++ b/android/olm-sdk/src/main/jni/olm_account.cpp
@@ -16,6 +16,7 @@
  */
 
 #include "olm_account.h"
+#include <string.h>
 
 using namespace AndroidOlmSdk;
 
@@ -684,4 +685,4 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz,
     }
 
     return (jlong)(intptr_t)accountPtr;
-}
\ No newline at end of file
+}
diff --git a/android/olm-sdk/src/main/jni/olm_inbound_group_session.cpp b/android/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
index 114b7cd..3fb2036 100644
--- a/android/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
+++ b/android/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
@@ -16,6 +16,7 @@
  */
 
 #include "olm_inbound_group_session.h"
+#include <string.h>
 
 using namespace AndroidOlmSdk;
 
diff --git a/android/olm-sdk/src/main/jni/olm_jni_helper.cpp b/android/olm-sdk/src/main/jni/olm_jni_helper.cpp
index a1f5c59..93c275e 100644
--- a/android/olm-sdk/src/main/jni/olm_jni_helper.cpp
+++ b/android/olm-sdk/src/main/jni/olm_jni_helper.cpp
@@ -18,6 +18,7 @@
 #include "olm_jni_helper.h"
 #include "olm/olm.h"
 #include <sys/time.h>
+#include <string.h>
 
 using namespace AndroidOlmSdk;
 
diff --git a/android/olm-sdk/src/main/jni/olm_outbound_group_session.cpp b/android/olm-sdk/src/main/jni/olm_outbound_group_session.cpp
index a821709..5715372 100644
--- a/android/olm-sdk/src/main/jni/olm_outbound_group_session.cpp
+++ b/android/olm-sdk/src/main/jni/olm_outbound_group_session.cpp
@@ -16,6 +16,7 @@
  */
 
 #include "olm_outbound_group_session.h"
+#include <string.h>
 
 using namespace AndroidOlmSdk;
 
diff --git a/android/olm-sdk/src/main/jni/olm_session.cpp b/android/olm-sdk/src/main/jni/olm_session.cpp
index 5ca49db..49c4e8f 100644
--- a/android/olm-sdk/src/main/jni/olm_session.cpp
+++ b/android/olm-sdk/src/main/jni/olm_session.cpp
@@ -16,6 +16,7 @@
  */
 
 #include "olm_session.h"
+#include <string.h>
 
 using namespace AndroidOlmSdk;
 
@@ -958,4 +959,4 @@ JNIEXPORT jlong OLM_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz,
     }
 
     return (jlong)(intptr_t)sessionPtr;
-}
\ No newline at end of file
+}
-- 
2.17.1

@manuroe
Copy link

manuroe commented Jun 22, 2018

Hi @af-anssi,

Thanks for this contribution. As per https://git.matrix.org/git/olm/tree/CONTRIBUTING.rst, could you please sign off this patch?

@bmarty
Copy link
Contributor

bmarty commented Jun 25, 2018

Hi @af-anssi ,

Is it necessary to add all the #include <string.h> lines?

Benoît

@af-anssi
Copy link
Author

The memset function prototype is declared in string.h in the NDK. The compilation fails if the function is used but the prototype is not known.

@bmarty
Copy link
Contributor

bmarty commented Jun 26, 2018

Hi @af-anssi,

ok for "string.h", but moved to olm_jni.h to factorize

Your description says "compile with the last NDK", but I do not see this in the provided patch. Is it missing

@af-anssi af-anssi changed the title Compiling with last NDK + some hardening Fix compilation with last NDK + some hardening Jun 26, 2018
@af-anssi
Copy link
Author

diff --git a/android/olm-sdk/src/main/jni/Android.mk b/android/olm-sdk/src/main/jni/Android.mk
index aceaef0..44a2787 100644
--- a/android/olm-sdk/src/main/jni/Android.mk
+++ b/android/olm-sdk/src/main/jni/Android.mk
@@ -21,6 +21,9 @@ LOCAL_CFLAGS+= -DOLMLIB_VERSION_MAJOR=$(MAJOR) \

#LOCAL_CFLAGS+= -DNDK_DEBUG

+LOCAL_CFLAGS+=-fstack-protector-all -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Wall
+LOCAL_LDFLAGS=-z relro -z now
+
LOCAL_C_INCLUDES+= $(LOCAL_PATH)/$(SRC_ROOT_DIR)/include/
$(LOCAL_PATH)/$(SRC_ROOT_DIR)/lib

diff --git a/android/olm-sdk/src/main/jni/Application.mk b/android/olm-sdk/src/main/jni/Application.mk
index 6516f5e..63c175e 100644
--- a/android/olm-sdk/src/main/jni/Application.mk
+++ b/android/olm-sdk/src/main/jni/Application.mk
@@ -1,3 +1,3 @@
APP_PLATFORM := android-16
-APP_ABI := arm64-v8a armeabi-v7a armeabi x86_64 x86
-APP_STL := gnustl_static
\ No newline at end of file
+APP_ABI := arm64-v8a armeabi-v7a x86_64 x86
+APP_STL := gnustl_static
diff --git a/android/olm-sdk/src/main/jni/olm_jni.h b/android/olm-sdk/src/main/jni/olm_jni.h
index e6a49e2..8d8d67c 100644
--- a/android/olm-sdk/src/main/jni/olm_jni.h
+++ b/android/olm-sdk/src/main/jni/olm_jni.h
@@ -20,7 +20,7 @@

#include
#include
-#include
+#include <string.h>
#include
#include <jni.h>
#include <android/log.h>

@bmarty
Copy link
Contributor

bmarty commented Jun 27, 2018

Hi @af-anssi ,
This new patch is just a change to including "string.h" in olm_jni.h, right?
Benoît

@af-anssi af-anssi closed this as completed Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants