Page MenuHomeFreeBSD

flua: add libfetch functionality
Needs ReviewPublic

Authored by dch on May 25 2023, 8:20 PM.
Tags
None
Referenced Files
F103122763: D40274.id122500.diff
Thu, Nov 21, 7:35 AM
F103084046: D40274.id122499.diff
Wed, Nov 20, 5:57 PM
F103084045: D40274.id122499.diff
Wed, Nov 20, 5:57 PM
F103084041: D40274.id122499.diff
Wed, Nov 20, 5:57 PM
F103084039: D40274.id122499.diff
Wed, Nov 20, 5:57 PM
F103084029: D40274.id122499.diff
Wed, Nov 20, 5:57 PM
Unknown Object (File)
Fri, Nov 1, 3:20 PM
Unknown Object (File)
Oct 22 2024, 10:13 AM

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 51726
Build 48617: 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
68

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

79

Brace on its own line

83

This should move up above the blank line

91

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

102

Leaks file

105

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

113

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
113

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
113

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

dch marked an inline comment as done.

add manpage, align with latest flua dir layout

bcr added a subscriber: bcr.

Man page looks good to me. The actual code has to be reviewed/accepted by someone else.