summaryrefslogtreecommitdiffstats
path: root/src/H5Lexternal.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2014-02-20 21:29:26 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2014-02-20 21:29:26 (GMT)
commit1e36b5a348415501aa8eb992fd57c09d834900cd (patch)
tree9a423be6cbe38eed62268779703258972fb94191 /src/H5Lexternal.c
parentb30e37ea78a85c9a2e3abda7fddaabb636935b1c (diff)
downloadhdf5-1e36b5a348415501aa8eb992fd57c09d834900cd.zip
hdf5-1e36b5a348415501aa8eb992fd57c09d834900cd.tar.gz
hdf5-1e36b5a348415501aa8eb992fd57c09d834900cd.tar.bz2
[svn-r24726] Description:
Revert some earlier usage of strncpy, which was incorrect. Bring Coverity changes from branch back to trunk: r20821: Use HDstrncpy. --gh (Fixed already, with strdup) r20822: (Not merged, incorrect use of HDstrncpy()) r20823: (Not merged, incorrect use of HDstrncpy()) r20824: Maintenance: Bug fix: addressed CID 666. Value stored at *expression_len should be used in the call to HD5packFstring to avoid overflow (and unnecessary arithmetic calculation and casting) r20825: Issue 642: Added check for error and handler with print to stderr and exit. r20826: Undo revision 20818, as that issue has already been fixed in the 1.8 branch and trunk (but not coverity branch) r20827: (Not merged, incorrect use of HDstrncpy()) r20828: Use HDstrncpy. --gh (Corrected use of strncpy()) r20829: Check return of H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT) and if error set trgbuf[0] to 0. Check if H5Lunpack_elink_val(targbuf, linfo->u.val_size, NULL, &filename, &objname) was successful and allow print. Otherwise filename and objname are not created. (init those to NULL) r20830: resolved coverity issues 939, 940, 941, 944, and 947. all were complaints about use of sprintf, and in all cases, the buffers used were large enough for all eventualities. Resolved issue by replacing calls to sprintf with calls to snprintf. r20831: Maintenance: Addressed CID 852 Replaced sprintf with snprintf r20832: Purpose: Fix valgrind issues with hl/examples/ex_image2 Description: Modified hl/examples/ex_image2 to free global "gbuf" before exit. Tested on: Mac OSX/64 10.9.1 (amaon) w/C++, FORTRAN & Threadsafety (too minor to require h5committest)
Diffstat (limited to 'src/H5Lexternal.c')
-rw-r--r--src/H5Lexternal.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/H5Lexternal.c b/src/H5Lexternal.c
index a1245ba..a5302e0 100644
--- a/src/H5Lexternal.c
+++ b/src/H5Lexternal.c
@@ -208,6 +208,7 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group,
char *parent_group_name = NULL;/* Temporary pointer to group name */
char local_group_name[H5L_EXT_TRAVERSE_BUF_SIZE]; /* Local buffer to hold group name */
char *temp_file_name = NULL; /* Temporary pointer to file name */
+ size_t temp_file_name_len; /* Length of temporary file name */
char *actual_file_name = NULL; /* Parent file's actual name */
H5P_genplist_t *fa_plist; /* File access property list pointer */
H5F_close_degree_t fc_degree = H5F_CLOSE_WEAK; /* File close degree for target file */
@@ -312,6 +313,7 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group,
/* Copy the file name to use */
if(NULL == (temp_file_name = H5MM_strdup(file_name)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+ temp_file_name_len = HDstrlen(temp_file_name);
/* target file_name is an absolute pathname: see RM for detailed description */
if(H5_CHECK_ABSOLUTE(file_name) || H5_CHECK_ABS_PATH(file_name)) {
@@ -329,7 +331,8 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group,
ptr++;
/* Copy into the temp. file name */
- HDstrncpy(temp_file_name, ptr, HDstrlen(ptr) + 1);
+ HDstrncpy(temp_file_name, ptr, temp_file_name_len);
+ temp_file_name[temp_file_name_len - 1] = '\0';
} /* end if */
} /* end if */
else if(H5_CHECK_ABS_DRIVE(file_name)) {
@@ -339,7 +342,8 @@ H5L_extern_traverse(const char UNUSED *link_name, hid_t cur_group,
H5E_clear_stack(NULL);
/* strip "<drive-letter>:" */
- HDstrncpy(temp_file_name, &file_name[2], (HDstrlen(file_name) - 2) + 1);
+ HDstrncpy(temp_file_name, &file_name[2], temp_file_name_len);
+ temp_file_name[temp_file_name_len - 1] = '\0';
} /* end if */
} /* end if */
@@ -579,9 +583,9 @@ H5Lcreate_external(const char *file_name, const char *obj_name,
/* Encode the external link information */
p = (uint8_t *)ext_link_buf;
*p++ = (H5L_EXT_VERSION << 4) | H5L_EXT_FLAGS_ALL; /* External link version & flags */
- HDstrncpy((char *)p, file_name, file_name_len); /* Name of file containing external link's object */
+ HDstrncpy((char *)p, file_name, buf_size - 1); /* Name of file containing external link's object */
p += file_name_len;
- HDstrncpy((char *)p, norm_obj_name, norm_obj_name_len); /* External link's object */
+ HDstrncpy((char *)p, norm_obj_name, buf_size - (file_name_len + 1)); /* External link's object */
/* Create an external link */
if(H5L_create_ud(&link_loc, link_name, ext_link_buf, buf_size, H5L_TYPE_EXTERNAL, lcpl_id, lapl_id, H5AC_dxpl_id) < 0)