Message ID | 1381182185-10896-3-git-send-email-zab@redhat.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
On Mon, 7 Oct 2013 14:42:55 -0700, Zach Brown wrote: > Check for fopen() failure. This shows up in static analysis as a > possible null pointer derference. > > Signed-off-by: Zach Brown <zab@redhat.com> > --- > cmds-send.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/cmds-send.c b/cmds-send.c > index 374d040..5f6ff86 100644 > --- a/cmds-send.c > +++ b/cmds-send.c > @@ -72,6 +72,11 @@ int find_mount_root(const char *path, char **mount_root) > close(fd); > > mnttab = fopen("/proc/mounts", "r"); > + if (!mnttab) { > + close(fd); > + return -errno; close() can modify errno. And close(fd) is already called 4 lines above. You didn't run the static code analysis again after applying your patch :) > + } > + > while ((ent = getmntent(mnttab))) { > len = strlen(ent->mnt_dir); > if (strncmp(ent->mnt_dir, path, len) == 0) { > -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
> And close(fd) is already called 4 lines above. You didn't run the static > code analysis again after applying your patch :) Nice, thanks for catching that. I certainly didn't run it again, no :). - z -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/cmds-send.c b/cmds-send.c index 374d040..5f6ff86 100644 --- a/cmds-send.c +++ b/cmds-send.c @@ -72,6 +72,11 @@ int find_mount_root(const char *path, char **mount_root) close(fd); mnttab = fopen("/proc/mounts", "r"); + if (!mnttab) { + close(fd); + return -errno; + } + while ((ent = getmntent(mnttab))) { len = strlen(ent->mnt_dir); if (strncmp(ent->mnt_dir, path, len) == 0) {
Check for fopen() failure. This shows up in static analysis as a possible null pointer derference. Signed-off-by: Zach Brown <zab@redhat.com> --- cmds-send.c | 5 +++++ 1 file changed, 5 insertions(+)