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

src: fix string format mistake for 32 bit node #10082

Closed
wants to merge 1 commit into from

Conversation

posix4e
Copy link
Contributor

@posix4e posix4e commented Dec 1, 2016

Checklist
  • make -j8 test
Affected core subsystem(s)

crypto

Description of change

I noticed a warning reminscint of a format-string vuln. I think i have made the format string correct on non alpha based systems.
The warning was

  unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
     BIO_printf(bio, "0x%lx", exponent_word);

@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Dec 1, 2016
# endif
# ifdef THIRTY_TWO_BIT
BIO_printf(bio, "0x%dx", exponent_word);
# endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A less ifdef-y approach would be BIO_printf(bio, "0x%llx", static_cast<uint64_t>(exponent_word));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get

foo.c:16:65: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘long unsigned int’ [-Wformat=]
BIO_printf(bio, "0x%llx", static_cast<uint64_t>(exponent_word));

When I try 64bit mode

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@posix4e posix4e Dec 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BIO_printf(bio, "0x%llx", static_cast<long long unsigned>(exponent_word));
works though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh damn but then I get

src/node_crypto.cc:1540: Use int16/int64/etc, rather than the C type long [runtime/int] [4]

@mscdex mscdex added the crypto Issues and PRs related to the crypto subsystem. label Dec 1, 2016
@posix4e posix4e force-pushed the build-fix branch 4 times, most recently from c78cee8 to cca4236 Compare December 2, 2016 00:05
@posix4e
Copy link
Contributor Author

posix4e commented Dec 2, 2016

I think this gets us the best of both worlds @bnoordhuis ?

@bnoordhuis
Copy link
Member

I'm fairly sure Visual Studio doesn't have inttypes.h but we'll find out soon enough: https://ci.nodejs.org/job/node-test-pull-request/5099/

@posix4e
Copy link
Contributor Author

posix4e commented Dec 2, 2016

Looks like you were right? Shall we go back to ifdefs ?

@Fishrock123
Copy link
Contributor

Windows passed?

@posix4e
Copy link
Contributor Author

posix4e commented Dec 3, 2016

Looks like nothing passed. Maybe I should try the #ifdef approach again?

@gibfahn
Copy link
Member

gibfahn commented Dec 3, 2016

@posix4e Lots of other stuff failed, but it looks like windows did indeed pass.

https://ci.nodejs.org/job/node-test-commit-windows-fanned/5557/

@posix4e
Copy link
Contributor Author

posix4e commented Dec 3, 2016

Forgive my noobness but what are the next steps? Shall I return the ifdefs or is this sufficient? Does anyone agree about the merit of the patch?It seems windows might have passed (again excuse my noob) what is causing the other build failures?

@posix4e
Copy link
Contributor Author

posix4e commented Dec 3, 2016

Ok going back to my original ifdef patch unless anyone has some suggestions?

BIO_printf(bio, "0x%lx", exponent_word);

# endif
# ifdef THIRTY_TWO_BIT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be an #else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not exactly, there's a third case that I was hoping would break. I can handle it, it only happens on VMS and alpha

# endif
# ifdef THIRTY_TWO_BIT
BIO_printf(bio, "0x%dx", exponent_word);
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it more, what about this?

uint64_t exponent_word = static_cast<uint64_t>(BN_get_word(rsa->e));
uint32_t lo = static_cast<uint32_t>(exponent_word);
uint32_t hi = static_cast<uint32_t>(exponent_word >> 32);
if (hi == 0) {
  BIO_printf(bio, "0x%x", lo);
} else {
  BIO_printf(bio, "0x%x%08x", hi, lo);
}

Copy link
Contributor Author

@posix4e posix4e Dec 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIne by me. Seems less clear, but if you'd prefer

@posix4e
Copy link
Contributor Author

posix4e commented Dec 15, 2016

ring a ling a ding dong. Anything else we should do?

@MylesBorins
Copy link
Contributor

one more run of ci: https://ci.nodejs.org/job/node-test-pull-request/5410/

oh hi @posix4e o/

also can you modify the commit to include the subsystem and under 50 characters, might I suggest
src: fix string format mistake for 32 bit node

@posix4e
Copy link
Contributor Author

posix4e commented Dec 15, 2016

Does this mean great build success?

@MylesBorins
Copy link
Contributor

generally we don't put a colon at the end of the commit title. Otherwise the commit looks in order. I'll have to defer to @bnoordhuis for the actual review.

@addaleax may be able to help out as well.

  warning: format ‘%lx’ expects argument of type ‘long
  unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
     BIO_printf(bio, "0x%lx", exponent_word);
@posix4e
Copy link
Contributor Author

posix4e commented Dec 15, 2016

updated commit comment

@posix4e posix4e changed the title On 32 bit node we have a string format mistake: src: fix string format mistake for 32 bit node Dec 15, 2016
@MylesBorins
Copy link
Contributor

I'll land this end of day if there are no objections
/cc @bnoordhuis

@MylesBorins MylesBorins self-assigned this Dec 16, 2016
@MylesBorins
Copy link
Contributor

landed in 40eba12

MylesBorins pushed a commit that referenced this pull request Dec 16, 2016
  warning: format ‘%lx’ expects argument of type ‘long
  unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
     BIO_printf(bio, "0x%lx", exponent_word);

PR-URL: #10082
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
italoacasas pushed a commit that referenced this pull request Dec 17, 2016
  warning: format ‘%lx’ expects argument of type ‘long
  unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
     BIO_printf(bio, "0x%lx", exponent_word);

PR-URL: #10082
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
@italoacasas italoacasas mentioned this pull request Dec 17, 2016
italoacasas added a commit that referenced this pull request Dec 17, 2016
Notable changes:
* **crypto**:
  - Allow adding extra certificates to well-known CAs. (Sam Roberts)
    [#9139](#9139)
* **buffer**:
  - Fix single-character string filling. (Anna Henningsen)
    [#9837](#9837)
  - Handle UCS2 `.fill()` properly on BE. (Anna Henningsen)
    [#9837](#9837)
* **url**:
  - Add inspect function to TupleOrigin. (Safia Abdalla)
    [#10039](#10039)
  - Including base argument in originFor. (joyeecheung)
    [#10021](#10021)
  - Improve URLSearchParams spec compliance. (Timothy Gu)
    [#9484](#9484)
* **http**:
  - Remove stale timeout listeners. (Karl Böhlmark)
    [#9440](#9440)
* **build**:
  - Fix node_g target. (Daniel Bevenius)
    [#10153](#10153)
* **fs**:
  - Remove unused argument from copyObject(). (EthanArrowood)
    [#10041](#10041)
* **timers**:
  - Fix handling of cleared immediates. (hveldstra)
    [#9759](#9759)
* **src**:
  - Add wrapper for process.emitWarning(). (SamRoberts)
    [#9139](#9139)
  - Fix string format mistake for 32 bit node.(Alex Newman)
    [#10082](#10082)
posix4e added a commit to posix4e/node-1 that referenced this pull request Dec 20, 2016
  warning: format ‘%lx’ expects argument of type ‘long
  unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
     BIO_printf(bio, "0x%lx", exponent_word);

PR-URL: nodejs/node#10082
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
cjihrig pushed a commit that referenced this pull request Dec 20, 2016
  warning: format ‘%lx’ expects argument of type ‘long
  unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
     BIO_printf(bio, "0x%lx", exponent_word);

PR-URL: #10082
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jan 23, 2017
  warning: format ‘%lx’ expects argument of type ‘long
  unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
     BIO_printf(bio, "0x%lx", exponent_word);

PR-URL: #10082
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jan 23, 2017
  warning: format ‘%lx’ expects argument of type ‘long
  unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
     BIO_printf(bio, "0x%lx", exponent_word);

PR-URL: #10082
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jan 24, 2017
  warning: format ‘%lx’ expects argument of type ‘long
  unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
     BIO_printf(bio, "0x%lx", exponent_word);

PR-URL: #10082
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jan 24, 2017
  warning: format ‘%lx’ expects argument of type ‘long
  unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
     BIO_printf(bio, "0x%lx", exponent_word);

PR-URL: #10082
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
This was referenced Jan 24, 2017
MylesBorins pushed a commit that referenced this pull request Jan 31, 2017
  warning: format ‘%lx’ expects argument of type ‘long
  unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
     BIO_printf(bio, "0x%lx", exponent_word);

PR-URL: #10082
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
MylesBorins pushed a commit that referenced this pull request Feb 1, 2017
  warning: format ‘%lx’ expects argument of type ‘long
  unsigned int’, but argument 3 has type ‘unsigned int’ [-Wformat=]
     BIO_printf(bio, "0x%lx", exponent_word);

PR-URL: #10082
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants