mavlink fix for cause of intermittent crash

If the posix target is run and the rootfs is not created, then
there is an fopen in mavlink without a return value check and then a write
to the fd. When this condition occurs it tries to write to NULL and will
segfault.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
Mark Charlebois
2015-06-12 10:25:09 -07:00
committed by Lorenz Meier
parent a1b68b5b41
commit e6d9aa2b43
+8 -3
View File
@@ -409,9 +409,14 @@ protected:
snprintf(log_file_path, sizeof(log_file_path), PX4_ROOTFSDIR"/fs/microsd/%s", log_file_name);
fp = fopen(log_file_path, "ab");
/* write first message */
fputs(msg.text, fp);
fputs("\n", fp);
if (fp != NULL) {
/* write first message */
fputs(msg.text, fp);
fputs("\n", fp);
}
else {
warn("Failed to open %s errno=%d", log_file_path, errno);
}
}
}
}