Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stefan Haun
firmware
Commits
996e63ab
Commit
996e63ab
authored
Sep 05, 2019
by
Christoph 'SuperVirus' Heitkamp
Committed by
Rahix
Sep 05, 2019
Browse files
fix(config): Fix buffer-overflow and close file properly
parent
2a7e41fd
Changes
1
Hide whitespace changes
Inline
Side-by-side
epicardium/modules/config.c
View file @
996e63ab
...
...
@@ -270,17 +270,17 @@ void load_config(void)
);
return
;
}
char
buf
[
CONFIG_MAX_LINE_LENGTH
];
char
buf
[
CONFIG_MAX_LINE_LENGTH
+
1
];
int
lineNumber
=
0
;
int
nread
;
do
{
//zero-terminate in case file is empty
buf
[
0
]
=
'\0'
;
nread
=
epic_file_read
(
fd
,
buf
,
sizeof
(
buf
));
if
(
nread
<
sizeof
(
buf
))
{
nread
=
epic_file_read
(
fd
,
buf
,
CONFIG_MAX_LINE_LENGTH
);
if
(
nread
<
CONFIG_MAX_LINE_LENGTH
)
{
//add fake EOL to ensure termination
buf
[
nread
]
=
'\n'
;
buf
[
nread
++
]
=
'\n'
;
}
//zero-terminate buffer
buf
[
nread
]
=
'\0'
;
char
*
line
=
buf
;
char
*
eol
=
NULL
;
int
last_eol
=
0
;
...
...
@@ -344,4 +344,5 @@ void load_config(void)
}
}
}
while
(
nread
==
sizeof
(
buf
));
epic_file_close
(
fd
);
}
Write
Preview
Supports
Markdown
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