Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
b33a40e7
Commit
b33a40e7
authored
1 year ago
by
Deucе
Browse files
Options
Downloads
Patches
Plain Diff
Do not allow NULs in paths.
Even on filesystems where you can do it, you shouldn't. Stop it.
parent
530724a4
No related branches found
No related tags found
No related merge requests found
Pipeline
#5357
passed
1 year ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/sftp/sftp.h
+1
-1
1 addition, 1 deletion
src/sftp/sftp.h
src/sftp/sftp_server.c
+49
-8
49 additions, 8 deletions
src/sftp/sftp_server.c
with
50 additions
and
9 deletions
src/sftp/sftp.h
+
1
−
1
View file @
b33a40e7
...
...
@@ -130,7 +130,7 @@ typedef struct sftp_server_state {
bool
(
*
mkdir
)(
sftp_str_t
path
,
sftp_file_attr_t
attributes
,
void
*
cb_data
);
bool
(
*
rmdir
)(
sftp_str_t
path
,
void
*
cb_data
);
bool
(
*
opendir
)(
sftp_str_t
path
,
void
*
cb_data
);
bool
(
*
readdir
)(
sftp_
str
_t
handle
,
void
*
cb_data
);
bool
(
*
readdir
)(
sftp_
dirhandle
_t
handle
,
void
*
cb_data
);
bool
(
*
stat
)(
sftp_str_t
path
,
void
*
cb_data
);
bool
(
*
lstat
)(
sftp_str_t
path
,
void
*
cb_data
);
bool
(
*
fstat
)(
sftp_filehandle_t
handle
,
void
*
cb_data
);
...
...
This diff is collapsed.
Click to expand it.
src/sftp/sftp_server.c
+
49
−
8
View file @
b33a40e7
...
...
@@ -15,6 +15,17 @@ get64(sftps_state_t state)
return
sftp_get64
(
state
->
rxp
);
}
static
sftp_str_t
getcstring
(
sftps_state_t
state
)
{
sftp_str_t
str
=
getstring
(
state
);
if
(
memchr
(
str
->
c_str
,
0
,
str
->
len
)
!=
NULL
)
{
free_sftp_str
(
str
);
return
NULL
;
}
return
str
;
}
static
bool
appendcstring
(
sftps_state_t
state
,
const
char
*
s
)
{
...
...
@@ -92,7 +103,7 @@ s_open(sftps_state_t state)
sftp_file_attr_t
attrs
;
state
->
id
=
get32
(
state
);
fname
=
getstring
(
state
);
fname
=
get
c
string
(
state
);
if
(
fname
==
NULL
)
return
false
;
flags
=
get32
(
state
);
...
...
@@ -150,6 +161,36 @@ s_write(sftps_state_t state)
return
ret
;
}
static
bool
s_close
(
sftps_state_t
state
)
{
bool
ret
;
sftp_str_t
handle
;
state
->
id
=
get32
(
state
);
handle
=
getstring
(
state
);
if
(
handle
==
NULL
)
return
false
;
ret
=
state
->
close
(
handle
,
state
->
cb_data
);
free_sftp_str
(
handle
);
return
ret
;
}
static
bool
s_readdir
(
sftps_state_t
state
)
{
bool
ret
;
sftp_dirhandle_t
handle
;
state
->
id
=
get32
(
state
);
handle
=
getstring
(
state
);
if
(
handle
==
NULL
)
return
false
;
ret
=
state
->
readdir
(
handle
,
state
->
cb_data
);
free_sftp_str
(
handle
);
return
ret
;
}
static
bool
s_id_str
(
sftps_state_t
state
,
bool
(
*
cb
)(
sftp_str_t
,
void
*
))
{
...
...
@@ -157,7 +198,7 @@ s_id_str(sftps_state_t state, bool (*cb)(sftp_str_t, void *))
sftp_str_t
str
;
state
->
id
=
get32
(
state
);
str
=
getstring
(
state
);
str
=
get
c
string
(
state
);
if
(
str
==
NULL
)
return
false
;
ret
=
cb
(
str
,
state
->
cb_data
);
...
...
@@ -188,7 +229,7 @@ s_id_str_attr(sftps_state_t state, bool (*cb)(sftp_str_t, sftp_file_attr_t, void
sftp_file_attr_t
attrs
;
state
->
id
=
get32
(
state
);
str
=
getstring
(
state
);
str
=
get
c
string
(
state
);
if
(
str
==
NULL
)
return
false
;
attrs
=
sftp_getfattr
(
state
->
rxp
);
...
...
@@ -232,10 +273,10 @@ s_id_str_str(sftps_state_t state, bool (*cb)(sftp_str_t, sftp_str_t, void *))
sftp_str_t
str2
;
state
->
id
=
get32
(
state
);
str1
=
getstring
(
state
);
str1
=
get
c
string
(
state
);
if
(
str1
==
NULL
)
return
false
;
str2
=
getstring
(
state
);
str2
=
get
c
string
(
state
);
if
(
str2
==
NULL
)
{
free_sftp_str
(
str1
);
return
false
;
...
...
@@ -269,7 +310,7 @@ sftps_recv(sftps_state_t state, uint8_t *buf, uint32_t sz)
break
;
case
SSH_FXP_CLOSE
:
if
(
state
->
close
)
{
if
(
!
s_
id_str
(
state
,
state
->
clos
e
))
if
(
!
s_
close
(
stat
e
))
return
exit_function
(
state
,
false
);
handled
=
true
;
}
...
...
@@ -325,7 +366,7 @@ sftps_recv(sftps_state_t state, uint8_t *buf, uint32_t sz)
break
;
case
SSH_FXP_READDIR
:
if
(
state
->
readdir
)
{
if
(
!
s_
id_st
r
(
state
,
state
->
readdir
))
if
(
!
s_
readdi
r
(
state
))
return
exit_function
(
state
,
false
);
handled
=
true
;
}
...
...
@@ -389,7 +430,7 @@ sftps_recv(sftps_state_t state, uint8_t *buf, uint32_t sz)
case
SSH_FXP_EXTENDED
:
if
(
state
->
version
>=
3
&&
state
->
extended
)
{
state
->
id
=
get32
(
state
);
sftp_str_t
request
=
getstring
(
state
);
sftp_str_t
request
=
get
c
string
(
state
);
if
(
request
==
NULL
)
return
exit_function
(
state
,
false
);
handled
=
state
->
extended
(
request
,
state
->
rxp
,
state
->
cb_data
);
...
...
This diff is collapsed.
Click to expand it.
Dan Cross
@tenser
mentioned in issue
#714 (closed)
·
1 year ago
mentioned in issue
#714 (closed)
mentioned in issue #714
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment