[3/4] mount: don't dereference pointer before null check

Submitted by Andrey Vagin on July 12, 2018, 8:41 p.m.

Details

Message ID 20180712204145.6494-3-avagin@virtuozzo.com
State Accepted
Series "Series without cover letter"
Headers show

Commit Message

Andrey Vagin July 12, 2018, 8:41 p.m.
CID 190775 (#1 of 1): Dereference before null check (REVERSE_INULL)
check_after_deref: Null-checking m->parent suggests that it may be null,
but it has already been dereferenced on all paths leading to the check.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 criu/mount.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/mount.c b/criu/mount.c
index 9cc8f6e94..f347a2e28 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -833,13 +833,14 @@  static int resolve_external_mounts(struct mount_info *info)
 static int root_path_from_parent(struct mount_info *m, char *buf, int size)
 {
 	bool head_slash = false, tail_slash = false;
-	int p_len = strlen(m->parent->mountpoint),
-	    m_len = strlen(m->mountpoint),
-	    len;
+	int p_len, m_len, len;
 
 	if (!m->parent)
 		return -1;
 
+	p_len = strlen(m->parent->mountpoint),
+	m_len = strlen(m->mountpoint),
+
 	len = snprintf(buf, size, "%s", m->parent->root);
 	if (len >= size)
 		return -1;