sipcapture / hep-js

HEP: Javascript/Node implementation of HEP/EEP Encapsulation Protocol

Home Page:http://sipcapture.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect Handling of HEP3 Chunks ends in Incorrect Payload strings (from Buffer)

haeferer opened this issue · comments

Hi,

first thx for your work in HEP. We tried to use HepOp together with OpenSips, but HepOps fails on Sending our Messages to Postgres.

After going down to the root-problem we found a Problem with Handling of Chunks in HEP-JS:

hep-js/index.js

Lines 385 to 390 in 51b3221

var hepParse = new Parser()
.endianess("big")
.uint16("vendor")
.uint16("type")
.uint16("length")
.buffer("chunk", { length: "length" });

incorrectly implements the length of the chunk (line 390)

Correct would be

var hepParse = new Parser() 
   .endianess("big") 
   .uint16("vendor") 
   .uint16("type") 
   .uint16("length") 
   .buffer("chunk", { length: function() {return this.length - 6} })  ; // Vendor Typ and Length are part oft the length 

after this change the Patches at

hep-js/index.js

Line 422 in 51b3221

return { rcinfo: { capturePass: data.chunk.slice(0,data.chunk.length-6).toString() } };

hep-js/index.js

Line 426 in 51b3221

return { rcinfo: { correlation_id: data.chunk.slice(0,data.chunk.length-6).toString() } };

hep-js/index.js

Line 428 in 51b3221

return { rcinfo: { hepNodeName: data.chunk.slice(0,data.chunk.length-6).toString() } };

correcting the "too long" chunk must be removed!

The Root cause for our problem was the missing correction (-6) at line

hep-js/index.js

Line 424 in 51b3221

return { payload: data.chunk.toString() };

Without the correction the next Vendor ID (0x00) will be part of the string, and this crashes pg-promise during execution of SQL containing 0x00

Thanks for your report and in-depth analysis! Could you submit a PR with your changes for review and integration?

Jup, we will do this tomorrow.

Have a nice Evening,

Cu

Andreas