Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of BINARY Parameter w/Stored Procedure Call Corrupts the Node Process #150

Open
DavidRusso opened this issue Nov 30, 2021 · 3 comments
Labels
bug Something isn't working keep-open

Comments

@DavidRusso
Copy link

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:

  1. This simple example will reproduce the problem and crash the Node process with a segmentation fault.
  2. 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'
  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();
    }
  
  }

})();
  1. After usually 5-6 repetitions, the process will crash with output like this:
0 [ '1' ]
1 [ '1' ]
2 [ '1' ]
3 [ '1' ]
4 [ '1' ]
5 [ '1' ]
6 [ '1' ]


#
# Fatal error in , line 0
# Check failed: result.second.
#
#
#
#FailureMessage Object: fffffffffffe510
Trace/BPT trap (core dumped)
  • Node.js version: v14.18.1
  • idb-connector version: 1.2.13
  • IBM i version:: 7.3

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

@DavidRusso DavidRusso added the bug Something isn't working label Nov 30, 2021
@github-actions
Copy link

👋 Hi! This issue has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed.

@github-actions github-actions bot added the stale label Oct 28, 2022
@DavidRusso
Copy link
Author

Please keep this active.

@abmusse abmusse removed the stale label Nov 8, 2022
@kadler
Copy link
Member

kadler commented Nov 10, 2022

@abmusse can you please add keep-open rules to our stale bot config?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working keep-open
Projects
None yet
Development

No branches or pull requests

3 participants