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
db690fad
Commit
db690fad
authored
4 years ago
by
Deon George
Browse files
Options
Downloads
Patches
Plain Diff
Improve btox() so that it doesnt lead to any buffer overruns
parent
6d0ec492
No related branches found
No related tags found
2 merge requests
!463
MRC mods by Codefenix (2024-10-20)
,
!11
Enable obtaining source IP address if HAproxy is used
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/sbbs3/main.cpp
+14
-10
14 additions, 10 deletions
src/sbbs3/main.cpp
with
14 additions
and
10 deletions
src/sbbs3/main.cpp
+
14
−
10
View file @
db690fad
...
...
@@ -416,11 +416,15 @@ static bool read_socket(SOCKET sock,unsigned char *buffer,int len)
}
/* Convert a binary variable into a hex string - used for printing in the debug log */
static
void
btox
(
char
*
hexstr
,
const
unsigned
char
*
srcbuf
,
int
srcbuflen
)
static
void
btox
(
char
*
hexstr
,
const
unsigned
char
*
srcbuf
,
int
srcbuflen
,
int
hexstrlen
)
{
int
i
;
for
(
i
=
0
;
i
<
srcbuflen
;
i
++
)
sprintf
(
hexstr
+
i
*
2
,
"%02X"
,
srcbuf
[
i
]);
hexstr
[
i
*
2
]
=
0
;
// null terminate the string
if
(
hexstrlen
<
srcbuflen
*
2
)
{
lprintf
(
LOG_WARNING
,
"btox Hexstr buffer too small [%d] - not all data will be shown"
,
hexstrlen
);
srcbuflen
=
hexstrlen
/
2
;
}
*
hexstr
=
'\0'
;
for
(
int
i
=
0
;
i
<
srcbuflen
;
i
++
)
sprintf
(
hexstr
+
strlen
(
hexstr
),
"%02X"
,
srcbuf
[
i
]);
}
/* TODO: IPv6 */
...
...
@@ -5609,7 +5613,7 @@ NO_SSH:
// OK, just for sanity, our next 6 chars should be v2...
if
(
read_socket
(
client_socket
,
hapstr
,
6
)
==
false
||
strcmp
((
char
*
)
hapstr
,
"
\n
QUIT
\n
"
)
!=
0
)
{
btox
(
haphex
,
hapstr
,
6
);
btox
(
haphex
,
hapstr
,
6
,
sizeof
(
haphex
)
);
lprintf
(
LOG_ERR
,
"%04d * HAPROXY Something went wrong [%s] incomplete v2 setup"
,
client_socket
,
haphex
);
close_socket
(
client_socket
);
continue
;
...
...
@@ -5617,7 +5621,7 @@ NO_SSH:
// Command and Version
if
(
read_socket
(
client_socket
,
hapstr
,
1
)
==
false
)
{
btox
(
haphex
,
hapstr
,
1
);
btox
(
haphex
,
hapstr
,
1
,
sizeof
(
haphex
)
);
lprintf
(
LOG_ERR
,
"%04d * HAPROXY, looking for Verson/Command - failed [%s]"
,
client_socket
,
haphex
);
close_socket
(
client_socket
);
continue
;
...
...
@@ -5627,7 +5631,7 @@ NO_SSH:
// Protocol and Family
if
(
read_socket
(
client_socket
,
hapstr
,
1
)
==
false
)
{
btox
(
haphex
,
hapstr
,
1
);
btox
(
haphex
,
hapstr
,
1
,
sizeof
(
haphex
)
);
lprintf
(
LOG_ERR
,
"%04d * HAPROXY, looking for Protocol/Family - failed [%s]"
,
client_socket
,
haphex
);
close_socket
(
client_socket
);
continue
;
...
...
@@ -5638,7 +5642,7 @@ NO_SSH:
// Address Length - 2 bytes
if
(
read_socket
(
client_socket
,
hapstr
,
2
)
==
false
)
{
btox
(
haphex
,
hapstr
,
2
);
btox
(
haphex
,
hapstr
,
2
,
sizeof
(
haphex
)
);
lprintf
(
LOG_ERR
,
"%04d * HAPROXY, looking for address length - failed [%s]"
,
client_socket
,
haphex
);
close_socket
(
client_socket
);
continue
;
...
...
@@ -5656,7 +5660,7 @@ NO_SSH:
}
if
(
read_socket
(
client_socket
,
hapstr
,
i
)
==
false
)
{
btox
(
haphex
,
hapstr
,
i
);
btox
(
haphex
,
hapstr
,
i
,
sizeof
(
haphex
)
);
lprintf
(
LOG_ERR
,
"%04d * HAPROXY looking for IPv4 address - failed [%s]"
,
client_socket
,
haphex
);
close_socket
(
client_socket
);
continue
;
...
...
@@ -5674,7 +5678,7 @@ NO_SSH:
}
if
(
read_socket
(
client_socket
,
hapstr
,
i
)
==
false
)
{
btox
(
haphex
,
hapstr
,
i
);
btox
(
haphex
,
hapstr
,
i
,
sizeof
(
haphex
)
);
lprintf
(
LOG_ERR
,
"%04d * HAPROXY looking for IPv6 address - failed [%s]"
,
client_socket
,
haphex
);
close_socket
(
client_socket
);
continue
;
...
...
This diff is collapsed.
Click to expand it.
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