-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
cares: Support malloc(0) scenarios for AIX #6305
Conversation
Many places in cares library, when the stream data arrives from the network with respect to dns and reverse dns resolution, they are populated into data structures created dymaically based on the size of the data. Malloc is heavily used for such cases. Often, based on the data length, malloc(0) is invoked. Linux behavior on zero byte allocation is to return a valid pointer where in AIX, it always return NULL. This manifestst as test failure of test/internet/test-dns.js Solution is to build cares with Linux compatible malloc behavior
LGTM |
Does that mean that c-ares often calls |
It may very well need to be. In this particular case, the options are only being set for |
@jasnell That's exactly the problem here. This patch only fixes this for
Note: I'm not against this patch, as it should solve the issue for |
I believe it is a question of programming style. Whether you want the size check before calling malloc, or you want to go ahead and allocate, but skip further processing of data eventually, as there was no demand for memory in the first place. The problem source here is node/deps/cares/src/ares_parse_ptr_reply.c Line 183 in be68b68
If you validate request size before malloc call, I believe there are quite many places we will need that change. For example this has been the case for v8 for a while, and the workaround was to keep the source in-tact, and address AIX case specifically. See also https://github.com/nodejs/node/blob/master/deps/v8/build/toolchain.gypi#L1086 |
A better fix IMO is to change the call to ares_library_init() in src/cares_wrap.cc to ares_library_init_mem() and pass in malloc/realloc wrappers that change zero-sized allocations to one-sized allocations. |
On second thought, I can live with the |
LTGM |
Given the LGTMs I'll plan to land Thursday unless there are objections before then. |
CI clean except for infrastructure related failure on windows so going to land. |
Many places in cares library, when the stream data arrives from the network with respect to dns and reverse dns resolution, they are populated into data structures created dymaically based on the size of the data. Malloc is heavily used for such cases. Often, based on the data length, malloc(0) is invoked. Linux behavior on zero byte allocation is to return a valid pointer where in AIX, it always return NULL. This manifestst as test failure of test/internet/test-dns.js Solution is to build cares with Linux compatible malloc behavior PR-URL: #6305 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-by: Michael Dawson <michael_dawson@ca.ibm.com>
Landed as 40ede46 |
Did this go upstream? A bit quick to land imo, especially seeing how we're trying to improve the shared library state. |
Hm, I'll check if the current c-ares build system does this already. If so, pardon my negligence. |
cares.gyp is custom to our build, it doesn't exist upstream. |
@jbergstroem The correct way of fixing this upstream would be making it not call |
Many places in cares library, when the stream data arrives from the network with respect to dns and reverse dns resolution, they are populated into data structures created dymaically based on the size of the data. Malloc is heavily used for such cases. Often, based on the data length, malloc(0) is invoked. Linux behavior on zero byte allocation is to return a valid pointer where in AIX, it always return NULL. This manifestst as test failure of test/internet/test-dns.js Solution is to build cares with Linux compatible malloc behavior PR-URL: nodejs#6305 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-by: Michael Dawson <michael_dawson@ca.ibm.com>
Many places in cares library, when the stream data arrives from the network with respect to dns and reverse dns resolution, they are populated into data structures created dymaically based on the size of the data. Malloc is heavily used for such cases. Often, based on the data length, malloc(0) is invoked. Linux behavior on zero byte allocation is to return a valid pointer where in AIX, it always return NULL. This manifestst as test failure of test/internet/test-dns.js Solution is to build cares with Linux compatible malloc behavior PR-URL: #6305 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-by: Michael Dawson <michael_dawson@ca.ibm.com>
@mhdawson is this something we want for LTS? |
@thealphanerd yes it should be safe and would be good to have in LTS |
Many places in cares library, when the stream data arrives from the network with respect to dns and reverse dns resolution, they are populated into data structures created dymaically based on the size of the data. Malloc is heavily used for such cases. Often, based on the data length, malloc(0) is invoked. Linux behavior on zero byte allocation is to return a valid pointer where in AIX, it always return NULL. This manifestst as test failure of test/internet/test-dns.js Solution is to build cares with Linux compatible malloc behavior PR-URL: #6305 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-by: Michael Dawson <michael_dawson@ca.ibm.com>
Many places in cares library, when the stream data arrives from the network with respect to dns and reverse dns resolution, they are populated into data structures created dymaically based on the size of the data. Malloc is heavily used for such cases. Often, based on the data length, malloc(0) is invoked. Linux behavior on zero byte allocation is to return a valid pointer where in AIX, it always return NULL. This manifestst as test failure of test/internet/test-dns.js Solution is to build cares with Linux compatible malloc behavior PR-URL: #6305 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-by: Michael Dawson <michael_dawson@ca.ibm.com>
Many places in cares library, when the stream data arrives from the network with respect to dns and reverse dns resolution, they are populated into data structures created dymaically based on the size of the data. Malloc is heavily used for such cases. Often, based on the data length, malloc(0) is invoked. Linux behavior on zero byte allocation is to return a valid pointer where in AIX, it always return NULL. This manifestst as test failure of test/internet/test-dns.js Solution is to build cares with Linux compatible malloc behavior PR-URL: #6305 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-by: Michael Dawson <michael_dawson@ca.ibm.com>
Checklist
Affected core subsystem(s)
Description of change
Many places in cares library, when the stream data arrives
from the network with respect to dns and reverse dns
resolution, they are populated into data structures created
dymaically based on the size of the data. Malloc is heavily
used for such cases.
Often, based on the data length, malloc(0) is invoked. Linux
behavior on zero byte allocation is to return a valid pointer
where in AIX, it always return NULL.
This manifestst as test failure of test/internet/test-dns.js
Solution is to build cares with Linux compatible malloc behavior