-
-
Notifications
You must be signed in to change notification settings - Fork 337
Fix several undefined behavior issues noted by UBsan #6319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,7 +72,7 @@ typedef struct { | |
| /* Local Prototypes */ | ||
| /********************/ | ||
|
|
||
| static herr_t H5A__close_cb(H5VL_object_t *attr_vol_obj, void **request); | ||
| static herr_t H5A__close_cb(void *attr_vol_obj, void **request); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There were several instances in the library where an |
||
| static herr_t H5A__compact_build_table_cb(H5O_t *oh, H5O_mesg_t *mesg /*in,out*/, unsigned sequence, | ||
| void *_udata /*in,out*/); | ||
| static herr_t H5A__dense_build_table_cb(const H5A_t *attr, void *_udata); | ||
|
|
@@ -124,10 +124,10 @@ H5FL_SEQ_DEFINE_STATIC(H5A_t_ptr); | |
|
|
||
| /* Attribute ID class */ | ||
| static const H5I_class_t H5I_ATTR_CLS[1] = {{ | ||
| H5I_ATTR, /* ID class value */ | ||
| 0, /* Class flags */ | ||
| 0, /* # of reserved IDs for class */ | ||
| (H5I_free_t)H5A__close_cb /* Callback routine for closing objects of this class */ | ||
| H5I_ATTR, /* ID class value */ | ||
| 0, /* Class flags */ | ||
| 0, /* # of reserved IDs for class */ | ||
| H5A__close_cb /* Callback routine for closing objects of this class */ | ||
| }}; | ||
|
|
||
| /* Flag indicating "top" of interface has been initialized */ | ||
|
|
@@ -1277,21 +1277,22 @@ H5A__shared_free(H5A_t *attr) | |
| *------------------------------------------------------------------------- | ||
| */ | ||
| static herr_t | ||
| H5A__close_cb(H5VL_object_t *attr_vol_obj, void **request) | ||
| H5A__close_cb(void *attr_vol_obj, void **request) | ||
| { | ||
| herr_t ret_value = SUCCEED; /* Return value */ | ||
| H5VL_object_t *attr_vol_obj_p = (H5VL_object_t *)attr_vol_obj; | ||
| herr_t ret_value = SUCCEED; /* Return value */ | ||
|
|
||
| FUNC_ENTER_PACKAGE | ||
|
|
||
| /* Sanity check */ | ||
| assert(attr_vol_obj); | ||
| assert(attr_vol_obj_p); | ||
|
|
||
| /* Close the attribute */ | ||
| if (H5VL_attr_close(attr_vol_obj, H5P_DATASET_XFER_DEFAULT, request) < 0) | ||
| if (H5VL_attr_close(attr_vol_obj_p, H5P_DATASET_XFER_DEFAULT, request) < 0) | ||
| HGOTO_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "problem closing attribute"); | ||
|
|
||
| /* Free the VOL object */ | ||
| if (H5VL_free_object(attr_vol_obj) < 0) | ||
| if (H5VL_free_object(attr_vol_obj_p) < 0) | ||
| HGOTO_ERROR(H5E_ATTR, H5E_CANTDEC, FAIL, "unable to free VOL object"); | ||
|
|
||
| done: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1264,12 +1264,21 @@ H5D__scatgath_write_select(H5D_io_info_t *io_info) | |
|
|
||
| if ((H5T_BKG_YES == dset_info->type_info.need_bkg) && | ||
| !H5D__SCATGATH_USE_CMPD_OPT_WRITE(dset_info, io_info->sel_pieces[i]->in_place_tconv)) { | ||
| /* Non-const write_buf[i]. Use pointer math here to avoid const warnings. When | ||
| * there's a background buffer write_buf[i] always points inside the non-const tconv | ||
| * buf so this is OK. */ | ||
| void *tmp_write_buf = | ||
| (void *)((uint8_t *)io_info->tconv_buf + | ||
| ((const uint8_t *)write_bufs[i] - (const uint8_t *)io_info->tconv_buf)); | ||
| void *tmp_write_buf; | ||
|
|
||
| if (io_info->sel_pieces[i]->in_place_tconv) { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fortnern do these changes look correct? UBSan was complaining because in this particular case (where modifying of write buffers is enabled), the type conversion buffer wasn't allocated, so the previous logic was adding a non-zero offset to a |
||
| H5_flexible_const_ptr_t flex_buf = {.cvp = write_bufs[i]}; | ||
|
|
||
| tmp_write_buf = flex_buf.vp; | ||
| } | ||
| else { | ||
| /* Non-const write_buf[i]. Use pointer math here to avoid const warnings. When | ||
| * there's a background buffer write_buf[i] always points inside the non-const tconv | ||
| * buf so this is OK. */ | ||
| tmp_write_buf = | ||
| (void *)((uint8_t *)io_info->tconv_buf + | ||
| ((const uint8_t *)write_bufs[i] - (const uint8_t *)io_info->tconv_buf)); | ||
| } | ||
|
|
||
| /* Do the data transform before the type conversion (since | ||
| * transforms must be done in the memory type). */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -340,7 +340,7 @@ H5EA__lookup_elmt(const H5EA_t *ea, hsize_t idx, bool will_extend, unsigned thin | |
| *thing = NULL; | ||
| *thing_elmt_buf = NULL; | ||
| *thing_elmt_idx = 0; | ||
| *thing_unprot_func = (H5EA__unprotect_func_t)NULL; | ||
| *thing_unprot_func = NULL; | ||
|
|
||
| /* Check if we should create the index block */ | ||
| if (!H5_addr_defined(hdr->idx_blk_addr)) { | ||
|
|
@@ -368,7 +368,7 @@ H5EA__lookup_elmt(const H5EA_t *ea, hsize_t idx, bool will_extend, unsigned thin | |
| *thing = iblock; | ||
| *thing_elmt_buf = (uint8_t *)iblock->elmts; | ||
| *thing_elmt_idx = idx; | ||
| *thing_unprot_func = (H5EA__unprotect_func_t)H5EA__iblock_unprotect; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to |
||
| *thing_unprot_func = H5EA__iblock_unprotect; | ||
| } /* end if */ | ||
| else { | ||
| unsigned sblk_idx; /* Which superblock does this index fall in? */ | ||
|
|
@@ -436,7 +436,7 @@ H5EA__lookup_elmt(const H5EA_t *ea, hsize_t idx, bool will_extend, unsigned thin | |
| *thing = dblock; | ||
| *thing_elmt_buf = (uint8_t *)dblock->elmts; | ||
| *thing_elmt_idx = elmt_idx; | ||
| *thing_unprot_func = (H5EA__unprotect_func_t)H5EA__dblock_unprotect; | ||
| *thing_unprot_func = H5EA__dblock_unprotect; | ||
| } /* end if */ | ||
| else { | ||
| size_t sblk_off; /* Offset of super block in index block array of super blocks */ | ||
|
|
@@ -569,7 +569,7 @@ H5EA__lookup_elmt(const H5EA_t *ea, hsize_t idx, bool will_extend, unsigned thin | |
| *thing = dblk_page; | ||
| *thing_elmt_buf = (uint8_t *)dblk_page->elmts; | ||
| *thing_elmt_idx = elmt_idx; | ||
| *thing_unprot_func = (H5EA__unprotect_func_t)H5EA__dblk_page_unprotect; | ||
| *thing_unprot_func = H5EA__dblk_page_unprotect; | ||
| } /* end if */ | ||
| else { | ||
| /* Protect data block */ | ||
|
|
@@ -593,7 +593,7 @@ H5EA__lookup_elmt(const H5EA_t *ea, hsize_t idx, bool will_extend, unsigned thin | |
| *thing = dblock; | ||
| *thing_elmt_buf = (uint8_t *)dblock->elmts; | ||
| *thing_elmt_idx = elmt_idx; | ||
| *thing_unprot_func = (H5EA__unprotect_func_t)H5EA__dblock_unprotect; | ||
| *thing_unprot_func = H5EA__dblock_unprotect; | ||
| } /* end else */ | ||
| } /* end else */ | ||
| } /* end else */ | ||
|
|
@@ -608,7 +608,7 @@ H5EA__lookup_elmt(const H5EA_t *ea, hsize_t idx, bool will_extend, unsigned thin | |
| *thing = NULL; | ||
| *thing_elmt_buf = NULL; | ||
| *thing_elmt_idx = 0; | ||
| *thing_unprot_func = (H5EA__unprotect_func_t)NULL; | ||
| *thing_unprot_func = NULL; | ||
| } /* end if */ | ||
|
|
||
| /* Check for updating array statistics */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
_Float16type currently crashes UBSan, preventing further analysis in dt_arith.c.