Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
paho.mqtt.c
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eclipse
paho.mqtt.c
Commits
93a064db
Commit
93a064db
authored
Apr 23, 2014
by
Ian Craggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix buffer overflow in addressPort
Bug: 433290
parent
c009e27c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
17 deletions
+17
-17
MQTTProtocolOut.c
src/MQTTProtocolOut.c
+17
-17
No files found.
src/MQTTProtocolOut.c
View file @
93a064db
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
* Contributors:
* Contributors:
* Ian Craggs - initial API and implementation and/or initial documentation
* Ian Craggs - initial API and implementation and/or initial documentation
* Ian Craggs, Allan Stockdill-Mander - SSL updates
* Ian Craggs, Allan Stockdill-Mander - SSL updates
* Ian Craggs - fix for buffer overflow in addressPort bug #433290
*******************************************************************************/
*******************************************************************************/
/**
/**
...
@@ -34,43 +35,40 @@ extern ClientStates* bstate;
...
@@ -34,43 +35,40 @@ extern ClientStates* bstate;
/**
/**
* Separates an address:port into two separate values
* Separates an address:port into two separate values
* @param
ip_address the input string
* @param
uri the input string - hostname:port
* @param port the returned port integer
* @param port the returned port integer
* @return the address string
* @return the address string
*/
*/
char
*
MQTTProtocol_addressPort
(
char
*
ip_address
,
int
*
port
)
char
*
MQTTProtocol_addressPort
(
char
*
uri
,
int
*
port
)
{
{
static
char
buf
[
INET6_ADDRSTRLEN
+
1
];
char
*
colon_pos
=
strrchr
(
uri
,
':'
);
/* reverse find to allow for ':' in IPv6 addresses */
char
*
pos
=
strrchr
(
ip_address
,
':'
);
/* reverse find to allow for ':' in IPv6 addresses */
char
*
buf
=
uri
;
int
len
;
int
len
;
FUNC_ENTRY
;
FUNC_ENTRY
;
if
(
ip_address
[
0
]
==
'['
)
if
(
uri
[
0
]
==
'['
)
{
/* ip v6 */
{
/* ip v6 */
if
(
pos
<
strrchr
(
ip_address
,
']'
))
if
(
colon_pos
<
strrchr
(
uri
,
']'
))
pos
=
NULL
;
/* means it was an IPv6 separator, not for host:port */
colon_
pos
=
NULL
;
/* means it was an IPv6 separator, not for host:port */
}
}
if
(
pos
)
if
(
colon_
pos
)
{
{
int
len
=
pos
-
ip_address
;
int
addr_len
=
colon_pos
-
uri
;
*
port
=
atoi
(
pos
+
1
);
buf
=
malloc
(
addr_len
+
1
);
strncpy
(
buf
,
ip_address
,
len
);
*
port
=
atoi
(
colon_pos
+
1
);
buf
[
len
]
=
'\0'
;
strncpy
(
buf
,
uri
,
addr_len
)
;
pos
=
buf
;
buf
[
addr_len
]
=
'\0'
;
}
}
else
else
{
*
port
=
DEFAULT_PORT
;
*
port
=
DEFAULT_PORT
;
pos
=
ip_address
;
}
len
=
strlen
(
buf
);
len
=
strlen
(
buf
);
if
(
buf
[
len
-
1
]
==
']'
)
if
(
buf
[
len
-
1
]
==
']'
)
buf
[
len
-
1
]
=
'\0'
;
buf
[
len
-
1
]
=
'\0'
;
FUNC_EXIT
;
FUNC_EXIT
;
return
pos
;
return
buf
;
}
}
...
@@ -126,6 +124,8 @@ int MQTTProtocol_connect(char* ip_address, Clients* aClient)
...
@@ -126,6 +124,8 @@ int MQTTProtocol_connect(char* ip_address, Clients* aClient)
aClient
->
connect_state
=
0
;
aClient
->
connect_state
=
0
;
}
}
}
}
if
(
addr
!=
ip_address
)
free
(
addr
);
FUNC_EXIT_RC
(
rc
);
FUNC_EXIT_RC
(
rc
);
return
rc
;
return
rc
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment