Opened 3 years ago

Closed 3 years ago

#1800 closed defect (fixed)

Reported GMP version wrong for shared library

Reported by: zzz Owned by: zzz
Priority: minor Milestone: 0.9.27
Component: api/utils Version: 0.9.25
Keywords: Cc:
Parent Tickets:

Description

In the new jbigi.c (version 3) in 0.9.26, the new functions nativeGMPMajorVersion(), nativeGMPMinorVersion(), and nativeGMPPatchVersion(), return values that are defined in gmp.h. When a dynamic libjbigi.so is built for Debian/Ubuntu?, these will return the values for the libgmp lib it was built against. We need the runtime version from version.c, which is the global symbol:

const char * const gmp_version = VERSION;

which we would access as gmp_version and then parse into the values needed. (or convert to a java string and return in a new function, but that sounds ever worse)

In NBI, we currently only check for major >= 5 which is needed for the constant time functions. This _should_ be enforced in the debian/rules file anyway.

Since this only affects Deb/Ubuntu? builds, just fix the jbigi.c source and it will get picked up in the Deb builds. We don't need to rebuild the static .so files for all architectures, since they report the correct version.

Subtickets

Change History (2)

comment:1 Changed 3 years ago by zzz

  • Owner set to zzz
  • Status changed from new to accepted
--- core/c/jbigi/jbigi/src/jbigi.c	c72a40e42dca92bf710ce3090cf111638b2e69e3
+++ core/c/jbigi/jbigi/src/jbigi.c	725df6d8d6c8f4a48ee15994c3251d9fffc711a0
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <string.h>
 #include <gmp.h>
 #include "jbigi.h"
 
@@ -15,7 +16,7 @@ void convert_mp2j(JNIEnv* env, mpz_t mva
  * 2: (I2P 0.8.7)
  *    Removed nativeDoubleValue()
  *
- * 3: (I2P 0.9.18)
+ * 3: (I2P 0.9.26)
  *    Added:
  *      nativeJbigiVersion()
  *      nativeGMPMajorVersion()
@@ -26,8 +27,12 @@ void convert_mp2j(JNIEnv* env, mpz_t mva
  *    Support negative base value in modPow()
  *    Throw ArithmeticException for bad arguments in modPow()
  *
+ * 4: (I2P 0.9.27)
+ *    Fix nativeGMPMajorVersion(), nativeGMPMinorVersion(), and nativeGMPPatchVersion()
+ *    when built as a shared library
+ *
  */
-#define JBIGI_VERSION 3
+#define JBIGI_VERSION 4
 
 /*****************************************
  *****Native method implementations*******
@@ -39,22 +44,34 @@ JNIEXPORT jint JNICALL Java_net_i2p_util
     return (jint) JBIGI_VERSION;
 }
 
-/* since version 3 */
+/* since version 3, fixed for dynamic builds in version 4 */
 JNIEXPORT jint JNICALL Java_net_i2p_util_NativeBigInteger_nativeGMPMajorVersion
         (JNIEnv* env, jclass cls) {
-    return (jint) __GNU_MP_VERSION;
+    int v = 0;
+    if (strlen(gmp_version) > 0) {
+        v = gmp_version[0] - '0';
+    }
+    return (jint) v;
 }
 
-/* since version 3 */
+/* since version 3, fixed for dynamic builds in version 4 */
 JNIEXPORT jint JNICALL Java_net_i2p_util_NativeBigInteger_nativeGMPMinorVersion
         (JNIEnv* env, jclass cls) {
-    return (jint) __GNU_MP_VERSION_MINOR;
+    int v = 0;
+    if (strlen(gmp_version) > 2) {
+        v = gmp_version[2] - '0';
+    }
+    return (jint) v;
 }
 
-/* since version 3 */
+/* since version 3, fixed for dynamic builds in version 4 */
 JNIEXPORT jint JNICALL Java_net_i2p_util_NativeBigInteger_nativeGMPPatchVersion
         (JNIEnv* env, jclass cls) {
-    return (jint) __GNU_MP_VERSION_PATCHLEVEL;
+    int v = 0;
+    if (strlen(gmp_version) > 4) {
+        v = gmp_version[4] - '0';
+    }
+    return (jint) v;
 }
 
 /******** nativeModPow() */

comment:2 Changed 3 years ago by zzz

  • Resolution set to fixed
  • Status changed from accepted to closed

In 5407812130130ebf4a39ecbc64d3913fe20c22d9 i2p.i2p.zzz.test2 to be propped for 0.9.27

Note: See TracTickets for help on using tickets.