summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/gluegen
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-06-20 08:59:55 +0200
committerSven Gothel <[email protected]>2013-06-20 08:59:55 +0200
commit2d8e25398e929f553c4524e9c57f083d90ba4e08 (patch)
treefcdcb1402293824970f736615022e0054305b63c /src/java/com/jogamp/gluegen
parent23341a2df2d2ea36784a16fa1db8bc7385351a12 (diff)
Security: Gluegen generated native methods w/ 'pass through function pointer' _must_ be private!
Diffstat (limited to 'src/java/com/jogamp/gluegen')
-rw-r--r--src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java52
1 files changed, 37 insertions, 15 deletions
diff --git a/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java b/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java
index 82434cf..e6b3b6f 100644
--- a/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java
+++ b/src/java/com/jogamp/gluegen/procaddress/ProcAddressEmitter.java
@@ -178,18 +178,23 @@ public class ProcAddressEmitter extends JavaEmitter {
// Internals only below this point
//
+ /** If 'native', enforce 'private native' modifiers. */
+ protected void fixSecurityModifiers(JavaMethodBindingEmitter javaEmitter) {
+ if( javaEmitter.hasModifier(JavaMethodBindingEmitter.NATIVE) &&
+ !javaEmitter.hasModifier(JavaMethodBindingEmitter.PRIVATE) )
+ {
+ javaEmitter.removeModifier(JavaMethodBindingEmitter.PUBLIC);
+ javaEmitter.removeModifier(JavaMethodBindingEmitter.PROTECTED);
+ javaEmitter.removeModifier(JavaMethodBindingEmitter.NATIVE);
+ javaEmitter.addModifier(JavaMethodBindingEmitter.PRIVATE);
+ javaEmitter.addModifier(JavaMethodBindingEmitter.NATIVE);
+ }
+ }
+
protected void generateModifiedEmitters(JavaMethodBindingEmitter baseJavaEmitter, List<FunctionEmitter> emitters) {
// See whether we need a proc address entry for this one
boolean callThroughProcAddress = needsProcAddressWrapper(baseJavaEmitter.getBinding().getCSymbol());
- ProcAddressJavaMethodBindingEmitter emitter =
- new ProcAddressJavaMethodBindingEmitter(baseJavaEmitter,
- callThroughProcAddress,
- getProcAddressConfig().getProcAddressTableExpr(),
- baseJavaEmitter.isForImplementingMethodCall(),
- this);
- emitters.add(emitter);
-
// If this emitter doesn't have a body (i.e., is a direct native
// call with no intervening argument processing), we need to force
// it to emit a body, and produce another one to act as the entry
@@ -199,18 +204,35 @@ public class ProcAddressEmitter extends JavaEmitter {
// from incorrectly introducing method bodies to the private
// native implementing methods; want this to work at least for
// public and package-private methods
- if (baseJavaEmitter.signatureOnly()
- && !baseJavaEmitter.hasModifier(JavaMethodBindingEmitter.PRIVATE)
- && baseJavaEmitter.hasModifier(JavaMethodBindingEmitter.NATIVE)
- && callThroughProcAddress) {
- emitter.setEmitBody(true);
- emitter.removeModifier(JavaMethodBindingEmitter.NATIVE);
- emitter = new ProcAddressJavaMethodBindingEmitter(baseJavaEmitter,
+ final boolean needsJavaWrapper = baseJavaEmitter.signatureOnly() &&
+ !baseJavaEmitter.hasModifier(JavaMethodBindingEmitter.PRIVATE) &&
+ baseJavaEmitter.hasModifier(JavaMethodBindingEmitter.NATIVE) &&
+ callThroughProcAddress;
+
+
+ {
+ final ProcAddressJavaMethodBindingEmitter emitter = new ProcAddressJavaMethodBindingEmitter(baseJavaEmitter,
+ callThroughProcAddress,
+ getProcAddressConfig().getProcAddressTableExpr(),
+ baseJavaEmitter.isForImplementingMethodCall(),
+ this);
+ if( needsJavaWrapper ) {
+ emitter.setEmitBody(true);
+ emitter.removeModifier(JavaMethodBindingEmitter.NATIVE);
+ } else if ( callThroughProcAddress ) {
+ fixSecurityModifiers(emitter);
+ }
+ emitters.add(emitter);
+ }
+
+ if( needsJavaWrapper ) {
+ final ProcAddressJavaMethodBindingEmitter emitter = new ProcAddressJavaMethodBindingEmitter(baseJavaEmitter,
callThroughProcAddress,
getProcAddressConfig().getProcAddressTableExpr(),
true,
this);
emitter.setForImplementingMethodCall(true);
+ fixSecurityModifiers(emitter);
emitters.add(emitter);
}
}