diff mbox

[1/2] build-id: fix minor quirks

Message ID 57ADFD0E0200007800105808@prv-mh.provo.novell.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Beulich Aug. 12, 2016, 2:45 p.m. UTC
The initial size check in xen_build_id_check() came too late (after the
first access to the structure), but was mostly redundant with checks
done in all callers; convert it to a properly placed ASSERT(). The
"mostly" part being addressed too: xen_build_init() was off by one.

And then there was a stray semicolon.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
build-id: fix minor quirks

The initial size check in xen_build_id_check() came too late (after the
first access to the structure), but was mostly redundant with checks
done in all callers; convert it to a properly placed ASSERT(). The
"mostly" part being addressed too: xen_build_init() was off by one.

And then there was a stray semicolon.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/common/version.c
+++ b/xen/common/version.c
@@ -1,6 +1,7 @@
 #include <xen/compile.h>
 #include <xen/init.h>
 #include <xen/errno.h>
+#include <xen/lib.h>
 #include <xen/string.h>
 #include <xen/types.h>
 #include <xen/elf.h>
@@ -90,12 +91,11 @@ int xen_build_id_check(const Elf_Note *n
                        const void **p, unsigned int *len)
 {
     /* Check if we really have a build-id. */
+    ASSERT(n_sz > sizeof(*n));
+
     if ( NT_GNU_BUILD_ID != n->type )
         return -ENODATA;
 
-    if ( n_sz <= sizeof(*n) )
-        return -EINVAL;
-
     if ( n->namesz + n->descsz < n->namesz )
         return -EINVAL;
 
@@ -127,8 +127,8 @@ static int __init xen_build_init(void)
         return -ENODATA;
 
     /* Check for full Note header. */
-    if ( &n[1] > __note_gnu_build_id_end )
-        return -ENODATA;;
+    if ( &n[1] >= __note_gnu_build_id_end )
+        return -ENODATA;
 
     sz = (void *)__note_gnu_build_id_end - (void *)n;

Comments

Konrad Rzeszutek Wilk Aug. 12, 2016, 8:30 p.m. UTC | #1
On Fri, Aug 12, 2016 at 08:45:02AM -0600, Jan Beulich wrote:
> The initial size check in xen_build_id_check() came too late (after the
> first access to the structure), but was mostly redundant with checks
> done in all callers; convert it to a properly placed ASSERT(). The
> "mostly" part being addressed too: xen_build_init() was off by one.
> 
> And then there was a stray semicolon.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
diff mbox

Patch

--- a/xen/common/version.c
+++ b/xen/common/version.c
@@ -1,6 +1,7 @@ 
 #include <xen/compile.h>
 #include <xen/init.h>
 #include <xen/errno.h>
+#include <xen/lib.h>
 #include <xen/string.h>
 #include <xen/types.h>
 #include <xen/elf.h>
@@ -90,12 +91,11 @@  int xen_build_id_check(const Elf_Note *n
                        const void **p, unsigned int *len)
 {
     /* Check if we really have a build-id. */
+    ASSERT(n_sz > sizeof(*n));
+
     if ( NT_GNU_BUILD_ID != n->type )
         return -ENODATA;
 
-    if ( n_sz <= sizeof(*n) )
-        return -EINVAL;
-
     if ( n->namesz + n->descsz < n->namesz )
         return -EINVAL;
 
@@ -127,8 +127,8 @@  static int __init xen_build_init(void)
         return -ENODATA;
 
     /* Check for full Note header. */
-    if ( &n[1] > __note_gnu_build_id_end )
-        return -ENODATA;;
+    if ( &n[1] >= __note_gnu_build_id_end )
+        return -ENODATA;
 
     sz = (void *)__note_gnu_build_id_end - (void *)n;