libxl/libxl_arm_acpi.c: fix 'memcpy' forming offset out of the bounds
PATCH 1/1 libxl/libxl_arm_acpi.c: fix 'memcpy' forming offset out of the bounds
gcc-8.1 complains:
libxl_arm_acpi.c:208:5: error: 'memcpy' forming offset [5, 6] is out of the bounds [0, 4] [-Werror=array-bounds]
memcpy(h->oem_id, ACPI_OEM_ID, sizeof(h->oem_id));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libxl_arm_acpi.c:209:5: error: 'memcpy' forming offset [5, 8] is out of
the bounds [0, 4] [-Werror=array-bounds]
memcpy(h->oem_table_id, ACPI_OEM_TABLE_ID,
sizeof(h->oem_table_id));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libxl_arm_acpi.c:211:5: error: 'memcpy' forming offset 4 is out of the
bounds [0, 3] [-Werror=array-bounds]
memcpy(h->asl_compiler_id, ACPI_ASL_COMPILER_ID,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sizeof(h->asl_compiler_id));
~~~~~~~~~~~~~~~~~~~~~~~~~~~
libxl_arm_acpi.c:193:5: error: 'memcpy' forming offset [5, 6] is out of
the bounds [0, 4] [-Werror=array-bounds]
memcpy(rsdp->oem_id, ACPI_OEM_ID, sizeof(rsdp->oem_id));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~This patch fixes the above errors.
--- tools/libxl/libxl_arm_acpi.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
tools/libxl/libxl_arm_acpi.c +4 -5
@@ -190,7 +190,7 @@ static void make_acpi_rsdp(libxl__gc *gc, struct xc_dom_image *dom,struct acpi_table_rsdp *rsdp = (void *)dom->acpi_modules[0 ].data + offset;memcpy (rsdp->signature,"RSD PTR " ,sizeof (rsdp->signature)); -memcpy (rsdp->oem_id,ACPI_OEM_ID ,sizeof (rsdp->oem_id)); +memcpy (rsdp->oem_id,ACPI_OEM_ID ,sizeof (ACPI_OEM_ID )); rsdp->length = acpitables[RSDP ].size; rsdp->revision =0x02 ; rsdp->xsdt_physical_address = acpitables[XSDT ].addr;
@@ -205,11 +205,10 @@ static void make_acpi_header(struct acpi_table_header *h, const char *sig,memcpy (h->signature, sig,4 ); h->length = len; h->revision = rev; -memcpy (h->oem_id,ACPI_OEM_ID ,sizeof (h->oem_id)); -memcpy (h->oem_table_id,ACPI_OEM_TABLE_ID ,sizeof (h->oem_table_id)); +memcpy (h->oem_id,ACPI_OEM_ID ,sizeof (ACPI_OEM_ID )); +memcpy (h->oem_table_id,ACPI_OEM_TABLE_ID ,sizeof (ACPI_OEM_TABLE_ID )); h->oem_revision =0 ; -memcpy (h->asl_compiler_id,ACPI_ASL_COMPILER_ID , -sizeof (h->asl_compiler_id)); +memcpy (h->asl_compiler_id,ACPI_ASL_COMPILER_ID ,sizeof (ACPI_ASL_COMPILER_ID )); h->asl_compiler_revision =0 ; h->checksum =0 ; }
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 34 lines · Manjukumar Matha
gcc-8.1 complains:
libxl_arm_acpi.c:208:5: error: 'memcpy' forming offset [5, 6] is out of the bounds [0, 4] [-Werror=array-bounds]
memcpy(h->oem_id, ACPI_OEM_ID, sizeof(h->oem_id)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libxl_arm_acpi.c:209:5: error: 'memcpy' forming offset [5, 8] is out of the bounds [0, 4] [-Werror=array-bounds] memcpy(h->oem_table_id, ACPI_OEM_TABLE_ID, sizeof(h->oem_table_id)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libxl_arm_acpi.c:211:5: error: 'memcpy' forming offset 4 is out of the bounds [0, 3] [-Werror=array-bounds] memcpy(h->asl_compiler_id, ACPI_ASL_COMPILER_ID, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sizeof(h->asl_compiler_id)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~ libxl_arm_acpi.c:193:5: error: 'memcpy' forming offset [5, 6] is out of the bounds [0, 4] [-Werror=array-bounds] memcpy(rsdp->oem_id, ACPI_OEM_ID, sizeof(rsdp->oem_id)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~This patch fixes the above errors.
Signed-off-by Manjukumar Matha <[email protected]>--- tools/libxl/libxl_arm_acpi.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)tools/libxl/libxl_arm_acpi.c +0
-0
tools/libxl/libxl_arm_acpi.c static void make_acpi_rsdp(libxl__gc *gc, struct xc_dom_image *dom, · line 193
Quoted 5 lines
tools/libxl/libxl_arm_acpi.c +1
-1@@ -190,7 +190,7 @@ static void make_acpi_rsdp(libxl__gc *gc, struct xc_dom_image *dom,struct acpi_table_rsdp *rsdp = (void *)dom->acpi_modules[0 ].data + offset;memcpy (rsdp->signature,"RSD PTR " ,sizeof (rsdp->signature)); -memcpy (rsdp->oem_id,ACPI_OEM_ID ,sizeof (rsdp->oem_id)); +memcpy (rsdp->oem_id,ACPI_OEM_ID ,sizeof (ACPI_OEM_ID ));
The code should pick the smaller size of the two as the copy length. Or, since this is string, use strncpy with size of the destination array.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 37 lines · Wei Liu
Quoted 36 lines · Manjukumar Matha
gcc-8.1 complains:
libxl_arm_acpi.c:208:5: error: 'memcpy' forming offset [5, 6] is out of the bounds [0, 4] [-Werror=array-bounds]
memcpy(h->oem_id, ACPI_OEM_ID, sizeof(h->oem_id)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libxl_arm_acpi.c:209:5: error: 'memcpy' forming offset [5, 8] is out of the bounds [0, 4] [-Werror=array-bounds] memcpy(h->oem_table_id, ACPI_OEM_TABLE_ID, sizeof(h->oem_table_id)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libxl_arm_acpi.c:211:5: error: 'memcpy' forming offset 4 is out of the bounds [0, 3] [-Werror=array-bounds] memcpy(h->asl_compiler_id, ACPI_ASL_COMPILER_ID, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sizeof(h->asl_compiler_id)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~ libxl_arm_acpi.c:193:5: error: 'memcpy' forming offset [5, 6] is out of the bounds [0, 4] [-Werror=array-bounds] memcpy(rsdp->oem_id, ACPI_OEM_ID, sizeof(rsdp->oem_id)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~This patch fixes the above errors.
Signed-off-by Manjukumar Matha <[email protected]>--- tools/libxl/libxl_arm_acpi.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)tools/libxl/libxl_arm_acpi.c +0
-0@@ -190,7 +190,7 @@ static void make_acpi_rsdp(libxl__gc *gc, struct xc_dom_image *dom,struct acpi_table_rsdp *rsdp = (void *)dom->acpi_modules[0 ].data + offset;
Quoted 6 lines
tools/libxl/libxl_arm_acpi.c static void make_acpi_rsdp(libxl__gc *gc, struct xc_dom_image *dom, · line 193
Quoted 3 lines
tools/libxl/libxl_arm_acpi.c +1
-1memcpy (rsdp->signature,"RSD PTR " ,sizeof (rsdp->signature)); -memcpy (rsdp->oem_id,ACPI_OEM_ID ,sizeof (rsdp->oem_id)); +memcpy (rsdp->oem_id,ACPI_OEM_ID ,sizeof (ACPI_OEM_ID ));The code should pick the smaller size of the two as the copy length. Or, since this is string, use strncpy with size of the destination array.
Urgh - this is mess.
The behaviour you want is something like that of strncpy(), because it will add trailing NUL's to the destination if the size exceeds the length of src.
The problem with this is that a) you want space rather than NUL padding,
b) Coverity/compilers are going to complain bitterly (because of the use of str*() functions) that you end up with a non-NUL terminated.
Perhaps the best option is to write a new helper which has strncpy()'s behaviour except for having space padding, and which Coverity/compilers won't apply str*() sanity checking to.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 51 lines · Andrew Cooper
Quoted 37 lines · Wei Liu
Quoted 36 lines · Manjukumar Matha
gcc-8.1 complains:
libxl_arm_acpi.c:208:5: error: 'memcpy' forming offset [5, 6] is out of the bounds [0, 4] [-Werror=array-bounds]
memcpy(h->oem_id, ACPI_OEM_ID, sizeof(h->oem_id)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libxl_arm_acpi.c:209:5: error: 'memcpy' forming offset [5, 8] is out of the bounds [0, 4] [-Werror=array-bounds] memcpy(h->oem_table_id, ACPI_OEM_TABLE_ID, sizeof(h->oem_table_id)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libxl_arm_acpi.c:211:5: error: 'memcpy' forming offset 4 is out of the bounds [0, 3] [-Werror=array-bounds] memcpy(h->asl_compiler_id, ACPI_ASL_COMPILER_ID, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sizeof(h->asl_compiler_id)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~ libxl_arm_acpi.c:193:5: error: 'memcpy' forming offset [5, 6] is out of the bounds [0, 4] [-Werror=array-bounds] memcpy(rsdp->oem_id, ACPI_OEM_ID, sizeof(rsdp->oem_id)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~This patch fixes the above errors.
Signed-off-by Manjukumar Matha <[email protected]>--- tools/libxl/libxl_arm_acpi.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)tools/libxl/libxl_arm_acpi.c +0
-0@@ -190,7 +190,7 @@ static void make_acpi_rsdp(libxl__gc *gc, struct xc_dom_image *dom,struct acpi_table_rsdp *rsdp = (void *)dom->acpi_modules[0 ].data + offset;Quoted 6 lines
tools/libxl/libxl_arm_acpi.c static void make_acpi_rsdp(libxl__gc *gc, struct xc_dom_image *dom, · line 193
Quoted 3 lines
tools/libxl/libxl_arm_acpi.c +1
-1memcpy (rsdp->signature,"RSD PTR " ,sizeof (rsdp->signature)); -memcpy (rsdp->oem_id,ACPI_OEM_ID ,sizeof (rsdp->oem_id)); +memcpy (rsdp->oem_id,ACPI_OEM_ID ,sizeof (ACPI_OEM_ID ));The code should pick the smaller size of the two as the copy length. Or, since this is string, use strncpy with size of the destination array.
Urgh - this is mess.
The behaviour you want is something like that of
strncpy(), because it will add trailing NUL's to the destination if the size exceeds the length of src.
Quoted 7 lines
The problem with this is that a) you want space rather than NUL padding,
b) Coverity/compilers are going to complain bitterly (because of the use of str*() functions) that you end up with a non-NUL terminated.Perhaps the best option is to write a new helper which has strncpy()'s behaviour except for having space padding, and which Coverity/compilers won't apply str*() sanity checking to.
This works for me too.
The ideal location of that function should be in libacpi.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel