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

util: fix inspection of errors with tampered stack property for node v10 #33948

Closed
analog-nico opened this issue Jun 18, 2020 · 6 comments
Closed
Labels
util Issues and PRs related to the built-in util module.

Comments

@analog-nico
Copy link

This is an error report for node v10 which has already been fixed for node v12 and may make sense to fix in node v10 as well. The fix in node v12 could have been made via pull request #30576 .

  • Version: 10.21.0
  • Platform: Mac OS X
  • Subsystem: util

What steps will reproduce the bug?

'use strict'

let util = require('util')

let err1 = new Error()
let err2 = new Error()

err2.stack = String(err2.stack).split('\n') // This breaks it.

util.inspect(err1) // -> OK
util.inspect(err2) // -> OK
util.inspect({ err1 }) // -> OK
util.inspect({ err2 }) // -> TypeError: formatError(...).replace is not a function

How often does it reproduce? Is there a required condition?

Every time in node v10.21.0. Never in node v12.16.1.

What is the expected behavior?

The err2.stack array is inspected as an array would usually be inspected.

What do you see instead?

util.inspect({ err2 }) throws this error: TypeError: formatError(...).replace is not a function

Additional information

Feel free to close if such a fix is not within the scope of the LTS maintenance phase in which node v10 is currently in.

@ZYSzys
Copy link
Member

ZYSzys commented Jun 21, 2020

/cc @nodejs/release, maybe we could backport #30576 to next v10 LTS release.

@ZYSzys ZYSzys added util Issues and PRs related to the built-in util module. v10.x labels Jun 21, 2020
@richardlau
Copy link
Member

#30576 doesn't land cleanly on v10.x-staging so would need a manual backport.

@ZYSzys
Copy link
Member

ZYSzys commented Jul 3, 2020

However, I found if we want to land #30576, we need to land #26923 first, which was marked as dont-land-on-v10.x.

/cc @BridgeAR

@BridgeAR
Copy link
Member

BridgeAR commented Jul 3, 2020

@ZYSzys #26923 should not be backported. The actual fix is to change the formatError function as it is in v10 to return value.stack ? String(value.stack) : errorToString(value);

@BridgeAR
Copy link
Member

I am closing this as it's not a security issue and Node.js 10 is soon not maintained anymore.

@analog-nico I hope you were able to move to Node.js 12 or above by now!

@analog-nico
Copy link
Author

@BridgeAR Sounds good! I made sure to not run into this issue in my code and upgrading node makes sense anyways. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
util Issues and PRs related to the built-in util module.
Projects
None yet
Development

No branches or pull requests

4 participants