Bug 203499 - KASSERT for non-NULL in g_uzip.c after value is dereferenced
Summary: KASSERT for non-NULL in g_uzip.c after value is dereferenced
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Andriy Voskoboinyk
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2015-10-02 03:20 UTC by chadf
Modified: 2019-01-31 11:38 UTC (History)
2 users (show)

See Also:
avos: mfc-stable12+
avos: mfc-stable11+
avos: mfc-stable10+


Attachments
Patch to correct error (619 bytes, patch)
2015-10-02 03:20 UTC, chadf
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description chadf 2015-10-02 03:20:33 UTC
Created attachment 161639 [details]
Patch to correct error

g_uzip_destroy_geom() in g_uzip.c deferences the variable 'gp' before the KASSERT(gp != NULL) is called. The assertion should be moved up.

        if (gp->softc == NULL) {
                DPRINTF(("%s(%s): gp->softc == NULL\n", __func__, gp->name));
                return (ENXIO);
        }

        KASSERT(gp != NULL, ("NULL geom"));

-->>

        KASSERT(gp != NULL, ("NULL geom"));
        if (gp->softc == NULL) {
                DPRINTF(("%s(%s): gp->softc == NULL\n", __func__, gp->name));
                return (ENXIO);
        }

Patch included.
Comment 1 commit-hook freebsd_committer freebsd_triage 2019-01-26 14:54:31 UTC
A commit references this bug:

Author: avos
Date: Sat Jan 26 14:54:07 UTC 2019
New revision: 343473
URL: https://svnweb.freebsd.org/changeset/base/343473

Log:
  geom_uzip(4): move NULL pointer KASSERT check before it is dereferenced

  PR:		203499
  Submitted by:	<chadf@triularity.org>
  MFC after:	5 days

Changes:
  head/sys/geom/uzip/g_uzip.c
Comment 2 Conrad Meyer freebsd_committer freebsd_triage 2019-01-26 16:46:40 UTC
@avos, See also:

@@ -889,13 +889,13 @@ g_uzip_destroy_geom(struct gctl_req *req, struct g_cla
 	g_trace(G_T_TOPOLOGY, "%s(%s, %s)", __func__, mp->name, gp->name);
                                                                ^^^^^^^^
 	g_topology_assert();
 
+	KASSERT(gp != NULL, ("NULL geom"));
 	if (gp->softc == NULL) {
Comment 3 commit-hook freebsd_committer freebsd_triage 2019-01-26 17:18:24 UTC
A commit references this bug:

Author: avos
Date: Sat Jan 26 17:17:25 UTC 2019
New revision: 343475
URL: https://svnweb.freebsd.org/changeset/base/343475

Log:
  geom_uzip(4): set 'gp != NULL' assertion on top of the function

  There was yet another access to this variable in g_trace() few
  lines upper.

  PR:		203499
  Reported by:	cem
  MFC after:	5 days
  MFC with:	343473

Changes:
  head/sys/geom/uzip/g_uzip.c
Comment 4 commit-hook freebsd_committer freebsd_triage 2019-01-31 11:37:09 UTC
A commit references this bug:

Author: avos
Date: Thu Jan 31 11:36:29 UTC 2019
New revision: 343605
URL: https://svnweb.freebsd.org/changeset/base/343605

Log:
  MFC r343473:
  geom_uzip(4): move NULL pointer KASSERT check before it is dereferenced

  PR:		203499
  Submitted by:	<chadf@triularity.org>

  MFC r343475:
  geom_uzip(4): set 'gp != NULL' assertion on top of the function

  There was yet another access to this variable in g_trace() few
  lines upper.

  PR:		203499
  Reported by:	cem

Changes:
_U  stable/10/
  stable/10/sys/geom/uzip/g_uzip.c
_U  stable/11/
  stable/11/sys/geom/uzip/g_uzip.c
_U  stable/12/
  stable/12/sys/geom/uzip/g_uzip.c
Comment 5 commit-hook freebsd_committer freebsd_triage 2019-01-31 11:37:12 UTC
A commit references this bug:

Author: avos
Date: Thu Jan 31 11:36:29 UTC 2019
New revision: 343605
URL: https://svnweb.freebsd.org/changeset/base/343605

Log:
  MFC r343473:
  geom_uzip(4): move NULL pointer KASSERT check before it is dereferenced

  PR:		203499
  Submitted by:	<chadf@triularity.org>

  MFC r343475:
  geom_uzip(4): set 'gp != NULL' assertion on top of the function

  There was yet another access to this variable in g_trace() few
  lines upper.

  PR:		203499
  Reported by:	cem

Changes:
_U  stable/10/
  stable/10/sys/geom/uzip/g_uzip.c
_U  stable/11/
  stable/11/sys/geom/uzip/g_uzip.c
_U  stable/12/
  stable/12/sys/geom/uzip/g_uzip.c