1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

cov: sanitize input buffer

Make coverity aware the input line is legit.
Eventually add more sanitize functionality.
This commit is contained in:
Zdenek Kabelac 2024-05-08 00:00:28 +02:00
parent 9f4dc4170b
commit f6e0e7b9aa
2 changed files with 10 additions and 2 deletions

View File

@ -1743,6 +1743,9 @@ static void _unmangle_mountinfo_string(const char *src, char *buf)
*buf = '\0'; *buf = '\0';
} }
/* coverity[+tainted_string_sanitize_content:arg-0] */
static int _sanitize_line(const char *line) { return 1; }
/* Parse one line of mountinfo and unmangled target line */ /* Parse one line of mountinfo and unmangled target line */
static int _mountinfo_parse_line(const char *line, unsigned *maj, unsigned *min, char *buf) static int _mountinfo_parse_line(const char *line, unsigned *maj, unsigned *min, char *buf)
{ {
@ -1813,7 +1816,8 @@ int dm_mountinfo_read(dm_mountinfo_line_callback_fn read_fn, void *cb_data)
} }
while (!feof(minfo) && fgets(buffer, sizeof(buffer), minfo)) while (!feof(minfo) && fgets(buffer, sizeof(buffer), minfo))
if (!_mountinfo_parse_line(buffer, &maj, &min, target) || if (!_sanitize_line(buffer) ||
!_mountinfo_parse_line(buffer, &maj, &min, target) ||
!read_fn(buffer, maj, min, target, cb_data)) { !read_fn(buffer, maj, min, target, cb_data)) {
stack; stack;
r = 0; r = 0;

View File

@ -1741,6 +1741,9 @@ static void _unmangle_mountinfo_string(const char *src, char *buf)
*buf = '\0'; *buf = '\0';
} }
/* coverity[+tainted_string_sanitize_content:arg-0] */
static int _sanitize_line(const char *line) { return 1; }
/* Parse one line of mountinfo and unmangled target line */ /* Parse one line of mountinfo and unmangled target line */
static int _mountinfo_parse_line(const char *line, unsigned *maj, unsigned *min, char *buf) static int _mountinfo_parse_line(const char *line, unsigned *maj, unsigned *min, char *buf)
{ {
@ -1811,7 +1814,8 @@ int dm_mountinfo_read(dm_mountinfo_line_callback_fn read_fn, void *cb_data)
} }
while (!feof(minfo) && fgets(buffer, sizeof(buffer), minfo)) while (!feof(minfo) && fgets(buffer, sizeof(buffer), minfo))
if (!_mountinfo_parse_line(buffer, &maj, &min, target) || if (!_sanitize_line(buffer) ||
!_mountinfo_parse_line(buffer, &maj, &min, target) ||
!read_fn(buffer, maj, min, target, cb_data)) { !read_fn(buffer, maj, min, target, cb_data)) {
stack; stack;
r = 0; r = 0;