Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/discof/restore/utils/fd_ssarchive.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ fd_ssarchive_parse_filename( char const * _name,

ptr = next + 1;

if( FD_LIKELY( 0==strncmp( ptr, "tar.zst", 7UL ) ) ) *is_zstd = 1;
else if ( FD_LIKELY( 0==strncmp( ptr, "tar", 3UL ) ) ) *is_zstd = 0;
if( FD_LIKELY( 0==strcmp( ptr, "tar.zst" ) ) ) *is_zstd = 1;
else if ( FD_LIKELY( 0==strcmp( ptr, "tar" ) ) ) *is_zstd = 0;
else return -1;

return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/discof/restore/utils/fd_sshttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ follow_redirect( fd_sshttp_t * http,
char const * location = NULL;

for( ulong i=0UL; i<header_cnt; i++ ) {
if( FD_UNLIKELY( !strncasecmp( headers[ i ].name, "location", headers[ i ].name_len ) ) ) {
if( FD_UNLIKELY( headers[ i ].name_len == 8 && !strncasecmp( headers[ i ].name, "location", headers[ i ].name_len ) ) ) {
if( FD_UNLIKELY( !headers [ i ].value_len || headers[ i ].value[ 0 ]!='/' ) ) {
FD_LOG_WARNING(( "invalid location header `%.*s`", (int)headers[ i ].value_len, headers[ i ].value ));
fd_sshttp_cancel( http );
Expand Down
7 changes: 6 additions & 1 deletion src/discof/restore/utils/fd_ssresolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ fd_ssresolve_parse_redirect( fd_ssresolve_t * ssresolve,
char const * location = NULL;

for( ulong i=0UL; i<header_cnt; i++ ) {
if( FD_UNLIKELY( !strncasecmp( headers[ i ].name, "location", headers[ i ].name_len ) ) ) {
if( FD_UNLIKELY( headers[ i ].name_len == 8 && !strncasecmp( headers[ i ].name, "location", headers[ i ].name_len ) ) ) {
if( FD_UNLIKELY( !headers [ i ].value_len || headers[ i ].value[ 0 ]!='/' ) ) {
FD_LOG_WARNING(( "invalid location header `%.*s`", (int)headers[ i ].value_len, headers[ i ].value ));
return FD_SSRESOLVE_ADVANCE_ERROR;
Expand All @@ -272,6 +272,11 @@ fd_ssresolve_parse_redirect( fd_ssresolve_t * ssresolve,
}
}

if( FD_UNLIKELY( !location ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if( FD_UNLIKELY( !location ) ) {
if( FD_UNLIKELY( !location_len ) ) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a specific reason you prefer this?
When location is not NULL, location_len >= 1 should be guaranteed by line 264.
But of course happy to change this.

Copy link
Contributor

Choose a reason for hiding this comment

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

We typically always do "slice empty?" type checks on the length field. It's a more complete solution because often slices with an invalid (but not NULL) base pointer and a zero size length are considered valid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense!
Should I align

if( FD_UNLIKELY( !location ) ) {
FD_LOG_WARNING(( "no location header in redirect response" ));
fd_sshttp_cancel( http );
return FD_SSHTTP_ADVANCE_ERROR;
}
to this pattern as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes please

FD_LOG_WARNING(( "no location header in redirect response" ));
return FD_SSRESOLVE_ADVANCE_ERROR;
}

if( FD_UNLIKELY( location_len>=PATH_MAX-1UL ) ) return FD_SSRESOLVE_ADVANCE_ERROR;

char snapshot_name[ PATH_MAX ];
Expand Down
Loading