Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libloc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
libloc
Commits
25612764
Commit
25612764
authored
Mar 07, 2022
by
Michael Tremer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address: Prevent under/overflow when incrementing/decrementing
Signed-off-by:
Michael Tremer
<
michael.tremer@ipfire.org
>
parent
9820c51f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
15 deletions
+33
-15
src/libloc/address.h
src/libloc/address.h
+33
-15
No files found.
src/libloc/address.h
View file @
25612764
...
...
@@ -75,6 +75,31 @@ static inline int loc_address_cmp(const struct in6_addr* a1, const struct in6_ad
return
0
;
}
#define foreach_octet_in_address(octet, address) \
for (octet = (IN6_IS_ADDR_V4MAPPED(address) ? 12 : 0); octet <= 15; octet++)
static
inline
int
loc_address_all_zeroes
(
const
struct
in6_addr
*
address
)
{
int
octet
=
0
;
foreach_octet_in_address
(
octet
,
address
)
{
if
(
address
->
s6_addr
[
octet
])
return
0
;
}
return
1
;
}
static
inline
int
loc_address_all_ones
(
const
struct
in6_addr
*
address
)
{
int
octet
=
0
;
foreach_octet_in_address
(
octet
,
address
)
{
if
(
address
->
s6_addr
[
octet
]
<
255
)
return
0
;
}
return
1
;
}
static
inline
int
loc_address_get_bit
(
const
struct
in6_addr
*
address
,
unsigned
int
i
)
{
return
((
address
->
s6_addr
[
i
/
8
]
>>
(
7
-
(
i
%
8
)))
&
1
);
}
...
...
@@ -258,6 +283,10 @@ static inline int loc_address_sub(struct in6_addr* result,
}
static
inline
void
loc_address_increment
(
struct
in6_addr
*
address
)
{
// Prevent overflow when everything is ones
if
(
loc_address_all_ones
(
address
))
return
;
for
(
int
octet
=
15
;
octet
>=
0
;
octet
--
)
{
if
(
address
->
s6_addr
[
octet
]
<
255
)
{
address
->
s6_addr
[
octet
]
++
;
...
...
@@ -269,6 +298,10 @@ static inline void loc_address_increment(struct in6_addr* address) {
}
static
inline
void
loc_address_decrement
(
struct
in6_addr
*
address
)
{
// Prevent underflow when everything is ones
if
(
loc_address_all_zeroes
(
address
))
return
;
for
(
int
octet
=
15
;
octet
>=
0
;
octet
--
)
{
if
(
address
->
s6_addr
[
octet
]
>
0
)
{
address
->
s6_addr
[
octet
]
--
;
...
...
@@ -277,21 +310,6 @@ static inline void loc_address_decrement(struct in6_addr* address) {
}
}
static
inline
int
loc_address_all_zeroes
(
const
struct
in6_addr
*
address
)
{
struct
in6_addr
all_zeroes
=
IN6ADDR_ANY_INIT
;
const
int
family
=
loc_address_family
(
address
);
int
r
=
loc_address_reset
(
&
all_zeroes
,
family
);
if
(
r
)
return
r
;
if
(
loc_address_cmp
(
address
,
&
all_zeroes
)
==
0
)
return
1
;
return
0
;
}
static
inline
int
loc_address_count_trailing_zero_bits
(
const
struct
in6_addr
*
address
)
{
int
zeroes
=
0
;
...
...
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