Page MenuHomeFreeBSD

flua: add libfetch functionality
Needs ReviewPublic

Authored by dch on May 25 2023, 8:20 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Apr 18, 1:19 AM
Unknown Object (File)
Feb 19 2024, 11:10 PM
Unknown Object (File)
Feb 17 2024, 12:57 PM
Unknown Object (File)
Dec 25 2023, 1:45 AM
Unknown Object (File)
Dec 20 2023, 4:37 AM
Unknown Object (File)
Dec 16 2023, 6:35 PM
Unknown Object (File)
Dec 8 2023, 2:13 AM
Unknown Object (File)
Oct 16 2023, 4:28 PM

Details

Summary
  • needs a manpage
Test Plan
lua

> f.parse_url("http:\\")
nil     Failed to parse URL

> r = f.parse_url("http://localhost/")
> for k,v in pairs(r) do; print('\t',k,v); end
                user
                scheme  http
                host    localhost
                doc     /
                password

> r = f.parse_url("http://user:pass@localhost:1999/rain?beret=raspberry")
> for k,v in pairs(r) do; print('\t',k,v); end
                user    user
                doc     /rain?beret=raspberry
                scheme  http
                host    localhost
                port    1999
                password        pass

> f.get_url("file:///var/run/motd", "/tmp/m")
true

> f.get_url("http://w3.org/", "/tmp/w")
true

> f.get_url("https://freebsd.org/", "/tmp/f")
true

> f.get_url("https://invalid.site/", "/tmp/i")
nil     Failed to read from URL: No error: 0

> f.get_url("https://wrong.host.badssl.com/", "/tmp/i")
SSL certificate subject doesn't match host wrong.host.badssl.com
nil     Failed to read from URL: Authentication error
>

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 51695
Build 48586: arc lint + arc unit

Event Timeline

dch requested review of this revision.May 25 2023, 8:20 PM

i'd like to see some documentation for this.

This revision now requires changes to proceed.May 25 2023, 11:15 PM

baby can walk now

  • parse a url
  • fetch a file, fetch a url
libexec/flua/modules/lfetch.c
69

My gut reaction to this is that we probably shouldn't expose the port at all if it's not explicitly set, just leave it nil in this table to allow for more idiomatic usage where you can simply test the port as truthy before using it.f

80

Brace on its own line

84

This should move up above the blank line

92

IIRC style(9) still doesn't allow declarations mid-block, it would need to be at the top of this function.

103

Leaks file

106

Ditto for these declarations; chunk_size I'd probably just make a #define since we're not going to be altering it

114

Leaks fetch

clean up free, indentation.

Stop at fetchGet(), because fetchPutHTTP() is sadly not implemented

dch marked 7 inline comments as done.

clean up following review

f.parse_url("http:\\")

nil Failed to parse URL

r = f.parse_url("http://localhost/")
for k,v in pairs(r) do; print('\t',k,v); end

user
scheme  http
host    localhost
doc     /
password

r = f.parse_url("http://user:pass@localhost:1999/rain?beret=raspberry")
for k,v in pairs(r) do; print('\t',k,v); end

user    user
doc     /rain?beret=raspberry
scheme  http
host    localhost
port    1999
password        pass

f.get_url("file:///var/run/motd", "/tmp/m")

true

f.get_url("http://w3.org/", "/tmp/w")

true

f.get_url("https://freebsd.org/", "/tmp/f")

true

f.get_url("https://invalid/", "/tmp/i")

nil Failed to read from URL: No error: 0

f.get_url("https://womp.us/", "/tmp/i")

SSL certificate subject doesn't match host womp.us
nil Failed to read from URL: Authentication error

Clean up test formatting.

To Do:

add a manpage.

> f.parse_url("http:\\")
nil     Failed to parse URL
> r = f.parse_url("http://localhost/")
> for k,v in pairs(r) do; print('\t',k,v); end
                user
                scheme  http
                host    localhost
                doc     /
                password
> r = f.parse_url("http://user:pass@localhost:1999/rain?beret=raspberry")
> for k,v in pairs(r) do; print('\t',k,v); end
                user    user
                doc     /rain?beret=raspberry
                scheme  http
                host    localhost
                port    1999
                password        pass
> f.get_url("file:///var/run/motd", "/tmp/m")
true
> f.get_url("http://w3.org/", "/tmp/w")
true
> f.get_url("https://freebsd.org/", "/tmp/f")
true
> f.get_url("https://invalid.site/", "/tmp/i")
nil     Failed to read from URL: No error: 0
> f.get_url("https://wrong.host.badssl.com/", "/tmp/i")
SSL certificate subject doesn't match host wrong.host.badssl.com
nil     Failed to read from URL: Authentication error
>
dch edited the test plan for this revision. (Show Details)
dch marked an inline comment as not done.May 26 2023, 9:22 PM
dch added inline comments.
libexec/flua/modules/lfetch.c
114

If I fclose(fetch); here, this segfaults:

Lua 5.4.4 Copyright (C) 1994-2022 Lua.org, PUC-Rio

f.get_url("https://invalid.site/", "/tmp/i")

fish: Job 1, '/usr/libexec/flua $argv' terminated by signal SIGSEGV (Address boundary error)

(lldb) thr backtrace all
* thread #1, name = 'flua', stop reason = signal SIGSEGV
  * frame #0: 0x00001252697ad0f9
    frame #1: 0xffadb0abacff9a89
libexec/flua/modules/lfetch.c
114

The context for this one has changed, the comment was originally down in the error path in the loop. This branch looks fine