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

feat: impl dns.getServers #3982

Merged
merged 2 commits into from
Aug 6, 2023
Merged

Conversation

Hanaasagi
Copy link
Collaborator

@Hanaasagi Hanaasagi commented Aug 4, 2023

Close: #3981

What does this PR do?

  • Implement the dns.getServers function

Reference:

  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

I wrote automated tests

  • I ran make js and committed the transpiled changes

  • I or my editor ran Prettier on the changed files (or I ran bun fmt)

  • I included a test for the new code, or an existing test covers it

  • I checked the lifetime of memory allocated to verify it's (1) freed and (2) only freed when it should be

  • I or my editor ran zig fmt on the changed files

  • I included a test for the new code, or an existing test covers it

  • JSValue used outside outside of the stack is either wrapped in a JSC.Strong or is JSValueProtect'ed

@Jarred-Sumner
Copy link
Collaborator

nice

@Hanaasagi Hanaasagi changed the title [WIP]feat: impl dns.getServers feat: impl dns.getServers Aug 5, 2023
@Hanaasagi Hanaasagi marked this pull request as ready for review August 5, 2023 09:51
function parseResolvConf() {
let servers = [];
try {
const content = fs.readFileSync("/etc/resolv.conf", "utf-8");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this test will only work on linux

can use test.skipIf(process.platform === “darwin”)

Copy link
Collaborator

@Jarred-Sumner Jarred-Sumner left a comment

Choose a reason for hiding this comment

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

Thank you. This looks good. Let’s let the tests run.

Only part I’m not sure about is the buffer length. If any of the numbers are not 100% correct in all the cases it could cause a crash or undefined behavior and it’d be hard to reproduce.

Assuming the current length isn’t huge (like 64 bytes probably), I suggest adding an extra 512 bytes to it just for wiggle room

@Hanaasagi
Copy link
Collaborator Author

Hanaasagi commented Aug 5, 2023

About the buffer length, I checked the source code of ares_inet_ntop. It checks the size parameter we pass in, so overflow should not occur. However, I think I should handle the case where the return value is NULL.

https://github.com/c-ares/c-ares/blob/bad62225b7f6b278b92e8e85a255600b629ef517/src/lib/inet_ntop.c#L58-L95

And std.fmt.bufPrint will also check buf length.

https://github.com/ziglang/zig/blob/fc6e5756848cd627b69756853937ce22500e62cc/lib/std/fmt.zig#L1996
https://github.com/ziglang/zig/blob/fc6e5756848cd627b69756853937ce22500e62cc/lib/std/io/fixed_buffer_stream.zig#L63

@Jarred-Sumner Jarred-Sumner merged commit ecdf2ff into oven-sh:main Aug 6, 2023
@Jarred-Sumner
Copy link
Collaborator

About the buffer length, I checked the source code of ares_inet_ntop. It checks the size parameter we pass in, so overflow should not occur. However, I think I should handle the case where the return value is NULL.

https://github.com/c-ares/c-ares/blob/bad62225b7f6b278b92e8e85a255600b629ef517/src/lib/inet_ntop.c#L58-L95

And std.fmt.bufPrint will also check buf length.

https://github.com/ziglang/zig/blob/fc6e5756848cd627b69756853937ce22500e62cc/lib/std/fmt.zig#L1996 https://github.com/ziglang/zig/blob/fc6e5756848cd627b69756853937ce22500e62cc/lib/std/io/fixed_buffer_stream.zig#L63

👍

trnxdev pushed a commit to trnxdev/bun that referenced this pull request Aug 9, 2023
* feat: impl `dns.getServers`
Close: oven-sh#3981

* check return value of `ares_inet_ntop`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dns.getServers is not implemented.
2 participants