Skip to content

Commit

Permalink
GH-71 Use Throw instead of FatalError to avoid core dump.
Browse files Browse the repository at this point in the history
  • Loading branch information
SirWumpus committed Nov 12, 2024
1 parent 714d5e5 commit b37a3d1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion jni/Post4.c
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,9 @@ Java_post4_jni_Post4_p4Create(JNIEnv *env, jobject self, jobject opts)
(*env)->DeleteLocalRef(env, clazz);

if (ctx == NULL) {
(*env)->FatalError(env, "cannot create Post4 context");
/* GH-71 Use Throw instead of FatalError to avoid core dump. */
(*env)->Throw(env, post4Exception(env, P4_THROW_GENERIC));
return 0L;
}

p4HookInit(ctx, jHooks);
Expand Down
4 changes: 3 additions & 1 deletion jni/Post4Exception.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public class Post4Exception extends Exception

/* -4095..-256 reserved for the system (that's us). */

public final static int THROW_SIGTERM = (-256);
public final static int THROW_WORDLIST = (-257); /* Out of word list space; invalid wid. */
public final static int THROW_GENERIC = (-4095); /* Unknown, generic, WTF. */

private final static String[] messages = {
Expand Down Expand Up @@ -192,7 +194,7 @@ public Post4Exception()

public Post4Exception(int code)
{
super(code+" thrown: "+(code <= 0 ? messages[-code] : "(unknown)"));
super(code+" thrown: "+(THROW_future < code && code <= 0 ? messages[-code] : "(unknown)"));
this.code = code;
}

Expand Down
7 changes: 7 additions & 0 deletions jni/makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,10 @@ testbye: build
cygtest: build
cp ${LIBNAME} post4jni.dll
POST4_PATH="${POST4_PATH}"; java -Djava.library.path=".;..\\src" -cp ../.. ${MAIN} ../test/units.p4

# GH-71 Should cleanly terminate with an error.
test_badpath: ${PROG}
@printf "== %s == Bad POST4_PATH\n" $@
! POST4_PATH="/invalid" java -Djava.library.path="$${POST4_PATH}" -cp ../.. ${MAIN}

This comment has been minimized.

Copy link
@ruv

ruv Nov 12, 2024

Contributor
POST4_PATH="/invalid" java -Djava.library.path="${POST4_PATH}"

If POST4_PATH was not set before that, this command is equivalent to:

POST4_PATH="/invalid" java -Djava.library.path=""

But the code makes impression that java.library.path is set to the value from POST4_PATH. Either java.library.path should be set to "" (empty string), or export should be used for POST4_PATH (as I mentioned earlier, see my past comment).

This comment has been minimized.

Copy link
@SirWumpus

SirWumpus Nov 12, 2024

Author Owner

Well I'm only concerned with triggering the case the original seg.fault occurred. Actual deployments will be a different setup hopefully without need of POST4_PATH nor java.libary.path.

POST4_PATH is used to file post4.p4 and any INCLUDE-PATH files. java.libary.path is used to find .so files, like libpost4jni.so.

Some reading I've conducted, it appears that java.libary.path cannot be set are runtime (ugh), which people have cited as reasons for temporary extraction of .so files from a jar file into a known location. Ugly.

This comment has been minimized.

Copy link
@SirWumpus

SirWumpus Nov 12, 2024

Author Owner

Currently support .p4 files and .so library will live in the same location, eg /usr/local/lib/post4 when installed (I'm not getting into package management choices between Linux, NetBSD (/usr/pkg/lib), FreeBSD).

@echo "-OK-"

0 comments on commit b37a3d1

Please sign in to comment.