Skip to content

Conversation

@posix4e
Copy link
Contributor

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-botnodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Dec 1, 2016
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
ContributorAuthor

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
ContributorAuthor

Choose a reason for hiding this comment

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

Copy link
ContributorAuthor

@posix4eposix4eDec 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
ContributorAuthor

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]

@mscdexmscdex added the crypto Issues and PRs related to the crypto subsystem. label Dec 1, 2016
@posix4eposix4eforce-pushed the build-fix branch 4 times, most recently from c78cee8 to cca4236CompareDecember 2, 2016 00:05
@posix4e
Copy link
ContributorAuthor

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
ContributorAuthor

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

@Fishrock123
Copy link
Contributor

Windows passed?

@posix4e
Copy link
ContributorAuthor

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

@gibfahn
Copy link
Member

@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
ContributorAuthor

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
ContributorAuthor

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

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
ContributorAuthor

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

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
ContributorAuthor

@posix4eposix4eDec 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
ContributorAuthor

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
ContributorAuthor

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
ContributorAuthor

updated commit comment

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

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

@MylesBorinsMylesBorins 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]>
@italoacasasitaloacasas mentioned this pull request Dec 17, 2016
italoacasas pushed 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 freeto 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++.cryptoIssues and PRs related to the crypto subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@posix4e@bnoordhuis@Fishrock123@gibfahn@MylesBorins@addaleax@mscdex@nodejs-github-bot