-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
net: lib: downloader: limit number of redirects #20224
base: main
Are you sure you want to change the base?
net: lib: downloader: limit number of redirects #20224
Conversation
CI InformationTo view the history of this post, clich the 'edited' button above Inputs:Sources:sdk-nrf: PR head: 6c388d17536e9c148d7556e885272c94e100a9d1 more detailssdk-nrf:
Github labels
List of changed files detected by CI (6)
Outputs:ToolchainVersion: 4cff34261a Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped;
|
You can find the documentation preview for this PR at this link. Note: This comment is automatically posted by the Documentation Publish GitHub Action. |
include/net/downloader.h
Outdated
* Maximum number of HTTP redirects. | ||
* Use 0 to set default value of CONFIG_DOWNLOADER_MAX_REDIRECTS. | ||
*/ | ||
int redirects_max; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, there is no way to disable this feature by setting the maximum number of redirects to zero?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that, but the case is that if we are disabling it and the server misbehaves (which it should not do), we will end in a endless loop. In reality there should not be many redirects to get to a file, so setting a high number will result in similar behavior. I would rather have a number of attempts by default than unlimited.
882964d
to
d147faa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Some nits.
if (dl->host_cfg.range_override) { | ||
if (tls_force_range && dl->host_cfg.range_override > (TLS_RANGE_MAX)) { | ||
if (tls_force_range) { | ||
if (dl->host_cfg.range_override > (TLS_RANGE_MAX)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (dl->host_cfg.range_override > (TLS_RANGE_MAX)) { | |
if (dl->host_cfg.range_override > TLS_RANGE_MAX) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
if (dl->host_cfg.range_override) { | ||
if (tls_force_range && dl->host_cfg.range_override > (TLS_RANGE_MAX)) { | ||
if (tls_force_range) { | ||
if (dl->host_cfg.range_override > (TLS_RANGE_MAX)) { | ||
LOG_WRN("Range override > TLS max range, setting to TLS max range"); | ||
dl->host_cfg.range_override = (TLS_RANGE_MAX); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dl->host_cfg.range_override = (TLS_RANGE_MAX); | |
dl->host_cfg.range_override = TLS_RANGE_MAX; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
return len; | ||
} | ||
if (dl->progress + len == dl->file_size) { | ||
/* A full file have been received */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My fault 😞
/* A full file have been received */ | |
/* A full file has been received */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
d147faa
to
f6fd041
Compare
include/net/downloader.h
Outdated
@@ -195,6 +196,11 @@ struct downloader_host_cfg { | |||
* This string is used in case you are requesting a proxied file from a CoAP server. | |||
*/ | |||
const char *proxy_uri; | |||
/** | |||
* Maximum number of HTTP redirects. | |||
* Use 0 to set default value of CONFIG_DOWNLOADER_MAX_REDIRECTS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems incorrect. The implementation sets the value of CONFIG_DOWNLOADER_MAX_REDIRECTS
, not its default (10).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see your point. I thought of the value of CONFIG_DOWNLOADER_MAX_REDIRECTS
as the default, but that is not the default value of CONFIG_DOWNLOADER_MAX_REDIRECTS
. I'll rewrite.
dl->host_cfg.range_override = (TLS_RANGE_MAX); | ||
dl->host_cfg.range_override = TLS_RANGE_MAX; | ||
} else if (dl->host_cfg.range_override == 0) { | ||
dl->host_cfg.range_override = TLS_RANGE_MAX; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no warning here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because here it is not explicitly set to something else by the application, as it is above.
@@ -960,6 +960,8 @@ static ssize_t z_impl_zsock_recvfrom_http_redirect_and_close( | |||
return 0; | |||
} | |||
|
|||
memcpy(buf, HTTP_HDR_REDIRECT, strlen(HTTP_HDR_REDIRECT)); | |||
return strlen(HTTP_HDR_REDIRECT); | |||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unreachable and should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
f6fd041
to
36e2f23
Compare
@@ -95,6 +95,9 @@ struct transport_params_http { | |||
|
|||
/** Request new data */ | |||
bool new_data_req; | |||
/** Redirect retries */ | |||
uint32_t redirects; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the right commit now.
@@ -26,6 +26,12 @@ config DOWNLOADER_MAX_FILENAME_SIZE | |||
range 8 2048 | |||
default 255 | |||
|
|||
config DOWNLOADER_MAX_REDIRECTS | |||
int "Default maximum number of redirects before download is aborted" | |||
default 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possible range value to limit range so someone doesn't set this to 0 or -40?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to the wrong commit, thanks!
2e20e9c
to
bc7785e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issues have been fixed in the wrong commit and need fixing in the first
4b4faa9
to
6a24117
Compare
Limit the number of redirects before downloader fails the download. Co-authored-by: Seppo Takalo <seppo.takalo@nordicsemi.no> Signed-off-by: Eivind Jølsgard <eivind.jolsgard@nordicsemi.no>
Cleanup formatting and some code restructuring. Co-authored-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no> Signed-off-by: Eivind Jølsgard <eivind.jolsgard@nordicsemi.no>
6a24117
to
6c388d1
Compare
After documentation is built, you will find the preview for this PR here. |
Limit the number of redirects before downloader fails the download.
Cleanup formatting and some code indentation.