You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Calling a stored procedure with a binary parameter corrupts the Node process. The problem manifests itself in different ways depending on the program. For example, the process may crash with a segmentation fault.
To Reproduce
Steps to reproduce the behavior:
This simple example will reproduce the problem and crash the Node process with a segmentation fault.
Create this SQL stored procedure on the IBM i system:
create or replace procedure yourlib.testbin
(
in bin_data binary(16),
out char_data char(1)
)
specific yourlib/testbin
language sql
set char_data = '1'
Run this Node.js program:
"use strict";
const db2i = require("idb-connector");
const util = require("util");
(async () => {
let dbconn;
try {
dbconn = new db2i.dbconn();
dbconn.conn("*LOCAL");
for (let i = 0; i < 1000; i++)
console.log(i, await call());
}
catch (error) {
console.error(error);
}
finally {
dbconn.disconn();
dbconn.close();
process.exit(0);
}
async function call() {
let dbstmt = new db2i.dbstmt(dbconn);
try {
await util.promisify(dbstmt.prepare).bind(dbstmt)("call yourlib.testbin(?,?)");
await util.promisify(dbstmt.bindParam).bind(dbstmt)([
[Buffer.alloc(16), db2i.IN, db2i.BINARY],
[null, db2i.OUT, db2i.CHAR]
]);
const output = await new Promise((resolve, reject) => {
dbstmt.execute((outputParams, error) => {
if (error)
reject(error);
else
resolve(outputParams);
});
});
return output;
}
finally {
dbstmt.close();
}
}
})();
After usually 5-6 repetitions, the process will crash with output like this:
As I mentioned above, the problem can manifest in different ways depending on the program. I originally encountered this issue in an HTTP/Express server application. In that case the process produces output like above, but doesn't crash. Instead it remains running, but appears to be stuck in a loop or something -- it runs with high CPU, stops responding to requests, and stays that way until killed with ENDJOB.
I'm guessing that something in idb-connector native code is writing into memory that doesn't belong to it, which corrupts the process in unpredictable ways.
I noticed this commit, which skips the blob/binary tests:
Describe the bug
Calling a stored procedure with a binary parameter corrupts the Node process. The problem manifests itself in different ways depending on the program. For example, the process may crash with a segmentation fault.
To Reproduce
Steps to reproduce the behavior:
The same problem affects BLOB parameters.
As I mentioned above, the problem can manifest in different ways depending on the program. I originally encountered this issue in an HTTP/Express server application. In that case the process produces output like above, but doesn't crash. Instead it remains running, but appears to be stuck in a loop or something -- it runs with high CPU, stops responding to requests, and stays that way until killed with
ENDJOB
.I'm guessing that something in
idb-connector
native code is writing into memory that doesn't belong to it, which corrupts the process in unpredictable ways.I noticed this commit, which skips the blob/binary tests:
b02cd36
The text was updated successfully, but these errors were encountered: