AndreasFagschlunger / O2Xfs

Java API for accessing CEN/XFS API, EMV Level 2 Kernel
47 stars 28 forks source link

CashInStatusCommand crash the JVM #80

Closed jifffffy closed 5 years ago

jifffffy commented 5 years ago

When I execute CashInStatusCommand every time, the JVM crashed and generate the following log:

  1. 2019-06-21 14:21:14 [Thread-4]DEBUG: at.o2xfs.xfs.service.cmd.XfsCallable.call(): Waiting ...
  2. 2019-06-21 14:21:14 [MessageHandler]DEBUG: at.o2xfs.xfs.service.EventDispatcher.dispatch(XFSMessage, IXfsEventNotification, WFSResult): xfsMessage=WFS_GETINFO_COMPLETE,eventNotification=at.o2xfs.xfs.service.cmd.XfsCallable@1180ba4,wfsResult=at.o2xfs.xfs.WFSResult@12841d0[requestID=111,service=24,timestamp=at.o2xfs.win32.SYSTEMTIME@29f119[types=[2019, 6, 5, 21, 14, 21, 14, 212]],result=0,u=at.o2xfs.win32.Union@8bb5bd[size=4,fields={commandCode=1306,eventID=1306}],buffer=Address: B268C37D, Value: 1497C07D]
  3. 2019-06-21 14:21:14 [MessageHandler]DEBUG: at.o2xfs.xfs.service.cmd.XfsCallable.fireOperationCompleteEvent(WFSResult): wfsResult=at.o2xfs.xfs.WFSResult@12841d0[requestID=111,service=24,timestamp=at.o2xfs.win32.SYSTEMTIME@29f119[types=[2019, 6, 5, 21, 14, 21, 14, 212]],result=0,u=at.o2xfs.win32.Union@8bb5bd[size=4,fields={commandCode=1306,eventID=1306}],buffer=Address: B268C37D, Value: 1497C07D]
  4. 2019-06-21 14:21:14 [Thread-4]INFO: at.o2xfs.xfs.service.cmd.XfsCallable.call(): error code : 0
  5. 2019-06-21 14:26:07 [Thread-4]DEBUG: at.o2xfs.xfs.util.XfsConstants.valueOf(long, Class): Undefined at.o2xfs.xfs.cim.CashInStatus constant: 15
  6. 2019-06-21 14:26:08 [Thread-4]DEBUG: at.o2xfs.xfs.util.XfsConstants.valueOf(long, Class): Undefined at.o2xfs.xfs.cim.CashInStatus constant: 15
  7. 2019-06-21 14:26:09 [Thread-4]DEBUG: at.o2xfs.xfs.util.XfsConstants.valueOf(long, Class): Undefined at.o2xfs.xfs.cim.CashInStatus constant: 15
  8. 2019-06-21 14:26:25 [Thread-4]DEBUG: at.o2xfs.xfs.util.XfsConstants.valueOf(long, Class): Undefined at.o2xfs.xfs.cim.CashInStatus constant: 15
  9. 2019-06-21 14:26:26 [Thread-4]DEBUG: at.o2xfs.xfs.util.XfsConstants.valueOf(long, Class): Undefined at.o2xfs.xfs.cim.CashInStatus constant: 15
  10. 2019-06-21 14:26:27 [Thread-4]DEBUG: at.o2xfs.xfs.util.XfsConstants.valueOf(long, Class): Undefined at.o2xfs.xfs.cim.CashInStatus constant: 15
  11. 2019-06-21 14:26:28 [Thread-4]DEBUG: at.o2xfs.xfs.util.XfsConstants.valueOf(long, Class): Undefined at.o2xfs.xfs.cim.CashInStatus constant: 15
  12. 2019-06-21 14:26:40 [Thread-4]DEBUG: at.o2xfs.xfs.util.XfsConstants.valueOf(long, Class): Undefined at.o2xfs.xfs.cim.CashInStatus constant: 15
  13. 2019-06-21 14:26:41 [Thread-4]DEBUG: at.o2xfs.xfs.util.XfsConstants.valueOf(long, Class): Undefined at.o2xfs.xfs.cim.CashInStatus constant: 15 error

this is the error file: https://github.com/sunyuyangg555/O2Xfs/blob/057ebbe84a70e36149e846e2f406e31ce94e0f8e/hs_err_pid_4064.txt#L1

I debug the code and find this function https://github.com/sunyuyangg555/O2Xfs/blob/057ebbe84a70e36149e846e2f406e31ce94e0f8e/at.o2xfs.win32/src/main/java/at/o2xfs/win32/Struct.java#L72 crash the jvm when it finishs.

this is another tool's result: wStatus: WFS_CIM_CIUNKNOWN (4) usNumOfRefused: 0 NoteNumberList usNumOfNoteNumbers: 0 lpszExtra: NULL

so how can I fix this error? thanks!

AndreasFagschlunger commented 5 years ago

It would be interesting to see the contents of the buffer, e.g. log or print the contents in the constructor:

    public CashInStatus3(Pointer p) {       
        this();
        System.out.println(Arrays.toString(p.buffer(getSize()).get()));
        assignBuffer(p);
    }

The error message says WORD wStatus has a value of 15, which isn't defined in XFS. You can try to add a enum in CashInStatus.java with a value of 15. The XFS specification also says, wStatus should be UNKNOWN when This status is also set if the lpNoteNumberList details are not known or are not reliable., which seems to be the case since the other tool does say WFS_CIM_CIUNKNOWN.

So I don't know what exactly is going on, WORD wStatus has a value of 15 according to O²Xfs, but this maybe a misinterpretation of the memory contents. But maybe this is the value set by the Service provider - does the value change? And maybe O²XFS should handle this value as UNKNOWN.

jifffffy commented 5 years ago

Thank you very much for your quick reply. I follow what you said. I added a log and add a enum in CashInStatus.java with a value of 15. I executed it twice: 1、This time there is no crash, but a java.lang.NullPointerException: Pointer points to NULL 1 2、The JVM crashed again. 2

the value is [15, 0, -108, -84, -64, 125, 3, 0, 4, 0, 0, 0], I don't know what it means. Is there any other idea?

AndreasFagschlunger commented 5 years ago

I found the error, CashInStatusCommand requests BANKNOTE_TYPES instead of CASH_IN_STATUS. Please pull develop branch and try again.

jifffffy commented 5 years ago

Hi, I have tested the modified CashInStatusCommand with CASH_IN_STATUS, there isn't crash the JVM, thanks very much. But I still get a null pointer error. I find the error is in NoteNumberList3#set . If numOfNoteNumbers is 0, no need to set noteNumber. if I check the noteNumber value, the error is gone.

protected void set(NoteNumberList3 copy) {
        numOfNoteNumbers.set(copy.getNumOfNoteNumbers());
        if(numOfNoteNumbers.get() > 0) {
            noteNumber.pointTo(new NoteNumber3Array(copy.getNoteNumber()));
        }
    }

and the NoteNumberList3#getNoteNumber is also modify . I change it like this:

public NoteNumber3[] getNoteNumber() {
        if(getNumOfNoteNumbers() == 0) {
            return null;
        }
        return new NoteNumber3Array(noteNumber, getNumOfNoteNumbers()).get();
    }