mirror of
https://github.com/HDFGroup/hdf5.git
synced 2026-09-25 04:09:44 +03:00
Security hardening (#6302)
Addresses CodeQL issues (Critical and High).
This commit is contained in:
@@ -73,9 +73,15 @@ jobs:
|
||||
|
||||
# Excluded rules justification:
|
||||
#
|
||||
# ── Global exclusions (legitimate across the entire codebase) ──
|
||||
#
|
||||
# Security false positives:
|
||||
# - cpp/toctou-race-condition: HDF5 file operations inherently involve
|
||||
# check-then-act patterns that cannot be avoided in a file I/O library.
|
||||
# - cpp/type-confusion: HDF5 object header messages use a void* dispatch
|
||||
# pattern where H5O_shared_t is embedded as the first member of message
|
||||
# structs (C "base class" idiom). Runtime type guards prevent invalid casts.
|
||||
# H5TSpool thread arg is always passed as the correct type.
|
||||
# - cpp/non-constant-format, cpp/uncontrolled-format-string,
|
||||
# cpp/tainted-format-string: All flagged sites are intentional
|
||||
# format-string-as-template patterns:
|
||||
@@ -98,18 +104,38 @@ jobs:
|
||||
# reference during ongoing development.
|
||||
# - cpp/use-of-goto: HDF5 uses goto for centralized cleanup (HGOTO_ERROR /
|
||||
# HGOTO_DONE macros), a well-established C resource management pattern.
|
||||
#
|
||||
# ── Tools-only exclusions (enforced for core library via filter-sarif) ──
|
||||
#
|
||||
# The following rules are excluded only for CLI tools and benchmarks
|
||||
# via path-scoped filter-sarif patterns (see filter-sarif step below),
|
||||
# but remain ENFORCED for the core library (src/, hl/src/):
|
||||
#
|
||||
# - cpp/path-injection: CLI tools (h5dump, h5repack, h5import, h5jam,
|
||||
# h5ls, h5perf) accept file paths from command-line arguments by design.
|
||||
# Kept enforced for src/ to surface env-var path usage in VFDs
|
||||
# (e.g., H5FDsubfiling, H5FDioc) for review.
|
||||
# - cpp/uncontrolled-allocation-size: CLI tools and benchmarks intentionally
|
||||
# accept allocation sizes from command-line arguments (block size, dataset
|
||||
# dimensions). Kept enforced for src/ to catch library allocation issues.
|
||||
# - cpp/world-writable-file-creation: CLI tools create files using fopen()
|
||||
# which defaults to 0666 & ~umask. Kept enforced for src/ to review
|
||||
# library file creation (VFD logging, cache logging).
|
||||
#
|
||||
config: |
|
||||
query-filters:
|
||||
- exclude:
|
||||
id: cpp/toctou-race-condition
|
||||
- exclude:
|
||||
id: cpp/short-global-name
|
||||
id: cpp/type-confusion
|
||||
- exclude:
|
||||
id: cpp/non-constant-format
|
||||
- exclude:
|
||||
id: cpp/uncontrolled-format-string
|
||||
- exclude:
|
||||
id: cpp/tainted-format-string
|
||||
- exclude:
|
||||
id: cpp/short-global-name
|
||||
- exclude:
|
||||
id: cpp/long-switch
|
||||
- exclude:
|
||||
@@ -135,10 +161,21 @@ jobs:
|
||||
- name: filter-sarif
|
||||
uses: advanced-security/filter-sarif@f3b8118a9349d88f7b1c0c488476411145b6270d # v1
|
||||
with:
|
||||
# Path-scoped exclusions:
|
||||
# - Test directories are excluded entirely (no security value in test harnesses).
|
||||
# - Tools-only rules: cpp/path-injection, cpp/uncontrolled-allocation-size,
|
||||
# and cpp/world-writable-file-creation are excluded for CLI tools and
|
||||
# benchmarks but remain enforced for the core library (src/, hl/src/).
|
||||
patterns: |
|
||||
-**/test/**
|
||||
-**/testpar/**
|
||||
-**/tools/test/**
|
||||
-tools/**:cpp/path-injection
|
||||
-tools/**:cpp/uncontrolled-allocation-size
|
||||
-tools/**:cpp/world-writable-file-creation
|
||||
-hl/tools/**:cpp/path-injection
|
||||
-hl/tools/**:cpp/uncontrolled-allocation-size
|
||||
-hl/tools/**:cpp/world-writable-file-creation
|
||||
input: sarif-results/cpp.sarif
|
||||
output: sarif-results/cpp.sarif
|
||||
|
||||
|
||||
@@ -728,13 +728,17 @@ parse_command_line(int argc, const char *const *argv)
|
||||
error_msg("memory allocation failed (file %s:line %d)\n", __FILE__, __LINE__);
|
||||
leave(EXIT_FAILURE);
|
||||
}
|
||||
if ((g_list_of_fields = (char *)realloc(g_list_of_fields, strlen(g_list_of_fields) +
|
||||
strlen(str) + 2)) == NULL) {
|
||||
error_msg("memory allocation failed (file %s:line %d)\n", __FILE__, __LINE__);
|
||||
leave(EXIT_FAILURE);
|
||||
{
|
||||
size_t cur_len = strlen(g_list_of_fields);
|
||||
size_t new_len = cur_len + strlen(FIELD_SEP) + strlen(str) + 1;
|
||||
char *realloc_tmp = (char *)realloc(g_list_of_fields, new_len);
|
||||
if (realloc_tmp == NULL) {
|
||||
error_msg("memory allocation failed (file %s:line %d)\n", __FILE__, __LINE__);
|
||||
leave(EXIT_FAILURE);
|
||||
}
|
||||
g_list_of_fields = realloc_tmp;
|
||||
snprintf(g_list_of_fields + cur_len, new_len - cur_len, "%s%s", FIELD_SEP, str);
|
||||
}
|
||||
strcat(g_list_of_fields, FIELD_SEP);
|
||||
strcat(g_list_of_fields, str);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
+1
-1
@@ -689,7 +689,7 @@ H5C__autoadjust__ageout__insert_new_marker(H5C_t *cache_ptr)
|
||||
|
||||
/* find an unused marker */
|
||||
i = 0;
|
||||
while ((cache_ptr->epoch_marker_active)[i] && i < H5C__MAX_EPOCH_MARKERS)
|
||||
while (i < H5C__MAX_EPOCH_MARKERS && (cache_ptr->epoch_marker_active)[i])
|
||||
i++;
|
||||
if (i >= H5C__MAX_EPOCH_MARKERS)
|
||||
HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Can't find unused marker");
|
||||
|
||||
+9
-7
@@ -387,16 +387,17 @@ H5FD__core_write_to_bstore(H5FD_core_t *file, haddr_t addr, size_t size)
|
||||
} while (-1 == bytes_wrote && EINTR == errno);
|
||||
|
||||
if (-1 == bytes_wrote) { /* error */
|
||||
int myerrno = errno;
|
||||
time_t mytime = time(NULL);
|
||||
int myerrno = errno;
|
||||
char time_str[32];
|
||||
|
||||
H5_get_localtime_str(time_str, sizeof(time_str));
|
||||
offset = HDlseek(file->fd, 0, SEEK_CUR);
|
||||
|
||||
HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL,
|
||||
"write to backing store failed: time = %s, filename = '%s', file descriptor = %d, "
|
||||
"errno = %d, error message = '%s', ptr = %p, total write size = %llu, bytes this "
|
||||
"sub-write = %llu, bytes actually written = %llu, offset = %llu",
|
||||
ctime(&mytime), file->name, file->fd, myerrno, strerror(myerrno), (void *)ptr,
|
||||
time_str, file->name, file->fd, myerrno, strerror(myerrno), (void *)ptr,
|
||||
(unsigned long long)size, (unsigned long long)bytes_in,
|
||||
(unsigned long long)bytes_wrote, (unsigned long long)offset);
|
||||
} /* end if */
|
||||
@@ -893,9 +894,10 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr
|
||||
} while (-1 == bytes_read && EINTR == errno);
|
||||
|
||||
if (-1 == bytes_read) { /* error */
|
||||
int myerrno = errno;
|
||||
time_t mytime = time(NULL);
|
||||
int myerrno = errno;
|
||||
char time_str[32];
|
||||
|
||||
H5_get_localtime_str(time_str, sizeof(time_str));
|
||||
offset = HDlseek(file->fd, 0, SEEK_CUR);
|
||||
|
||||
HGOTO_ERROR(
|
||||
@@ -903,8 +905,8 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr
|
||||
"file read failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, "
|
||||
"error message = '%s', file->mem = %p, total read size = %llu, bytes this "
|
||||
"sub-read = %llu, bytes actually read = %llu, offset = %llu",
|
||||
ctime(&mytime), file->name, file->fd, myerrno, strerror(myerrno),
|
||||
(void *)file->mem, (unsigned long long)size, (unsigned long long)bytes_in,
|
||||
time_str, file->name, file->fd, myerrno, strerror(myerrno), (void *)file->mem,
|
||||
(unsigned long long)size, (unsigned long long)bytes_in,
|
||||
(unsigned long long)bytes_read, (unsigned long long)offset);
|
||||
} /* end if */
|
||||
|
||||
|
||||
+8
-6
@@ -1181,9 +1181,10 @@ H5FD__log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had
|
||||
} while (-1 == bytes_read && EINTR == errno);
|
||||
|
||||
if (-1 == bytes_read) { /* error */
|
||||
int myerrno = errno;
|
||||
time_t mytime = time(NULL);
|
||||
int myerrno = errno;
|
||||
char time_str[32];
|
||||
|
||||
H5_get_localtime_str(time_str, sizeof(time_str));
|
||||
offset = HDlseek(file->fd, 0, SEEK_CUR);
|
||||
|
||||
if (file->fa.flags & H5FD_LOG_LOC_READ)
|
||||
@@ -1194,7 +1195,7 @@ H5FD__log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had
|
||||
"file read failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, "
|
||||
"error message = '%s', buf = %p, total read size = %llu, bytes this sub-read = %llu, "
|
||||
"bytes actually read = %llu, offset = %llu",
|
||||
ctime(&mytime), file->filename, file->fd, myerrno, strerror(myerrno), buf,
|
||||
time_str, file->filename, file->fd, myerrno, strerror(myerrno), buf,
|
||||
(unsigned long long)size, (unsigned long long)bytes_in,
|
||||
(unsigned long long)bytes_read, (unsigned long long)offset);
|
||||
}
|
||||
@@ -1404,9 +1405,10 @@ H5FD__log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, ha
|
||||
} while (-1 == bytes_wrote && EINTR == errno);
|
||||
|
||||
if (-1 == bytes_wrote) { /* error */
|
||||
int myerrno = errno;
|
||||
time_t mytime = time(NULL);
|
||||
int myerrno = errno;
|
||||
char time_str[32];
|
||||
|
||||
H5_get_localtime_str(time_str, sizeof(time_str));
|
||||
offset = HDlseek(file->fd, 0, SEEK_CUR);
|
||||
|
||||
if (file->fa.flags & H5FD_LOG_LOC_WRITE)
|
||||
@@ -1417,7 +1419,7 @@ H5FD__log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, ha
|
||||
"file write failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, "
|
||||
"error message = '%s', buf = %p, total write size = %llu, bytes this sub-write = "
|
||||
"%llu, bytes actually written = %llu, offset = %llu",
|
||||
ctime(&mytime), file->filename, file->fd, myerrno, strerror(myerrno), buf,
|
||||
time_str, file->filename, file->fd, myerrno, strerror(myerrno), buf,
|
||||
(unsigned long long)size, (unsigned long long)bytes_in,
|
||||
(unsigned long long)bytes_wrote, (unsigned long long)offset);
|
||||
} /* end if */
|
||||
|
||||
+5
-4
@@ -448,14 +448,15 @@ H5FD__onion_commit_new_revision_record(H5FD_onion_t *file)
|
||||
H5FD_onion_history_t *history = &file->history;
|
||||
H5FD_onion_record_loc_t *new_list = NULL;
|
||||
|
||||
time_t rawtime;
|
||||
struct tm *info;
|
||||
time_t rawtime;
|
||||
struct tm tm_buf;
|
||||
|
||||
FUNC_ENTER_PACKAGE
|
||||
|
||||
time(&rawtime);
|
||||
info = gmtime(&rawtime);
|
||||
strftime(rec->time_of_creation, sizeof(rec->time_of_creation), "%Y%m%dT%H%M%SZ", info);
|
||||
if (HDgmtime_r(&rawtime, &tm_buf) == NULL)
|
||||
HGOTO_ERROR(H5E_VFL, H5E_CANTGET, FAIL, "unable to convert time");
|
||||
strftime(rec->time_of_creation, sizeof(rec->time_of_creation), "%Y%m%dT%H%M%SZ", &tm_buf);
|
||||
|
||||
rec->logical_eof = file->logical_eof;
|
||||
|
||||
|
||||
+8
-6
@@ -649,9 +649,10 @@ H5FD__sec2_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU
|
||||
} while (-1 == bytes_read && EINTR == errno);
|
||||
|
||||
if (-1 == bytes_read) { /* error */
|
||||
int myerrno = errno;
|
||||
time_t mytime = time(NULL);
|
||||
int myerrno = errno;
|
||||
char time_str[32];
|
||||
|
||||
H5_get_localtime_str(time_str, sizeof(time_str));
|
||||
#ifndef H5_HAVE_PREADWRITE
|
||||
offset = HDlseek(file->fd, 0, SEEK_CUR);
|
||||
#endif
|
||||
@@ -660,7 +661,7 @@ H5FD__sec2_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU
|
||||
"file read failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, "
|
||||
"error message = '%s', buf = %p, total read size = %zu, bytes this sub-read = %llu, "
|
||||
"offset = %llu",
|
||||
ctime(&mytime), file->filename, file->fd, myerrno, strerror(myerrno), buf, size,
|
||||
time_str, file->filename, file->fd, myerrno, strerror(myerrno), buf, size,
|
||||
(unsigned long long)bytes_in, (unsigned long long)offset);
|
||||
} /* end if */
|
||||
|
||||
@@ -760,9 +761,10 @@ H5FD__sec2_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UN
|
||||
} while (-1 == bytes_wrote && EINTR == errno);
|
||||
|
||||
if (-1 == bytes_wrote) { /* error */
|
||||
int myerrno = errno;
|
||||
time_t mytime = time(NULL);
|
||||
int myerrno = errno;
|
||||
char time_str[32];
|
||||
|
||||
H5_get_localtime_str(time_str, sizeof(time_str));
|
||||
#ifndef H5_HAVE_PREADWRITE
|
||||
offset = HDlseek(file->fd, 0, SEEK_CUR);
|
||||
#endif
|
||||
@@ -771,7 +773,7 @@ H5FD__sec2_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UN
|
||||
"file write failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, "
|
||||
"error message = '%s', buf = %p, total write size = %zu, bytes this sub-write = "
|
||||
"%llu, offset = %llu",
|
||||
ctime(&mytime), file->filename, file->fd, myerrno, strerror(myerrno), buf, size,
|
||||
time_str, file->filename, file->fd, myerrno, strerror(myerrno), buf, size,
|
||||
(unsigned long long)bytes_in, (unsigned long long)offset);
|
||||
} /* end if */
|
||||
|
||||
|
||||
+26
-16
@@ -61,6 +61,28 @@
|
||||
/* Local Variables */
|
||||
/*******************/
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: H5O__print_time_field
|
||||
*
|
||||
* Purpose: Format and print a time_t value as a debug field.
|
||||
* Prints "(invalid time)" if localtime_r fails.
|
||||
*
|
||||
* Return: void
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
static void
|
||||
H5O__print_time_field(FILE *stream, int indent, int fwidth, const char *label, const time_t *time_val)
|
||||
{
|
||||
struct tm tm_buf;
|
||||
char buf[128];
|
||||
|
||||
if (HDlocaltime_r(time_val, &tm_buf) != NULL)
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", &tm_buf);
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "(invalid time)");
|
||||
fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, label, buf);
|
||||
} /* end H5O__print_time_field() */
|
||||
|
||||
#ifdef H5O_DEBUG
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
@@ -309,22 +331,10 @@ H5O__debug_real(H5F_t *f, H5O_t *oh, haddr_t addr, FILE *stream, int indent, int
|
||||
|
||||
/* Only dump times, if they are tracked */
|
||||
if (oh->flags & H5O_HDR_STORE_TIMES) {
|
||||
struct tm *tm; /* Time structure */
|
||||
char buf[128]; /* Buffer for formatting time info */
|
||||
|
||||
/* Time fields */
|
||||
tm = localtime(&oh->atime);
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tm);
|
||||
fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Access Time:", buf);
|
||||
tm = localtime(&oh->mtime);
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tm);
|
||||
fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Modification Time:", buf);
|
||||
tm = localtime(&oh->ctime);
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tm);
|
||||
fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Change Time:", buf);
|
||||
tm = localtime(&oh->btime);
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tm);
|
||||
fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Birth Time:", buf);
|
||||
H5O__print_time_field(stream, indent, fwidth, "Access Time:", &oh->atime);
|
||||
H5O__print_time_field(stream, indent, fwidth, "Modification Time:", &oh->mtime);
|
||||
H5O__print_time_field(stream, indent, fwidth, "Change Time:", &oh->ctime);
|
||||
H5O__print_time_field(stream, indent, fwidth, "Birth Time:", &oh->btime);
|
||||
} /* end if */
|
||||
|
||||
/* Attribute tracking fields */
|
||||
|
||||
+15
-10
@@ -261,9 +261,10 @@ H5O__mtime_encode(H5F_t H5_ATTR_UNUSED *f, bool H5_ATTR_UNUSED disable_shared, s
|
||||
const void *_mesg)
|
||||
{
|
||||
const time_t *mesg = (const time_t *)_mesg;
|
||||
struct tm *tm;
|
||||
struct tm tm_buf;
|
||||
herr_t ret_value = SUCCEED;
|
||||
|
||||
FUNC_ENTER_PACKAGE_NOERR
|
||||
FUNC_ENTER_PACKAGE
|
||||
|
||||
/* check args */
|
||||
assert(f);
|
||||
@@ -271,11 +272,14 @@ H5O__mtime_encode(H5F_t H5_ATTR_UNUSED *f, bool H5_ATTR_UNUSED disable_shared, s
|
||||
assert(mesg);
|
||||
|
||||
/* encode */
|
||||
tm = gmtime(mesg);
|
||||
snprintf((char *)p, p_size, "%04d%02d%02d%02d%02d%02d", 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday,
|
||||
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||
if (HDgmtime_r(mesg, &tm_buf) == NULL)
|
||||
HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, FAIL, "gmtime_r failed on time value");
|
||||
|
||||
FUNC_LEAVE_NOAPI(SUCCEED)
|
||||
snprintf((char *)p, p_size, "%04d%02d%02d%02d%02d%02d", 1900 + tm_buf.tm_year, 1 + tm_buf.tm_mon,
|
||||
tm_buf.tm_mday, tm_buf.tm_hour, tm_buf.tm_min, tm_buf.tm_sec);
|
||||
|
||||
done:
|
||||
FUNC_LEAVE_NOAPI(ret_value)
|
||||
} /* end H5O__mtime_encode() */
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
@@ -402,7 +406,7 @@ static herr_t
|
||||
H5O__mtime_debug(H5F_t H5_ATTR_UNUSED *f, const void *_mesg, FILE *stream, int indent, int fwidth)
|
||||
{
|
||||
const time_t *mesg = (const time_t *)_mesg;
|
||||
struct tm *tm;
|
||||
struct tm tm_buf;
|
||||
char buf[128];
|
||||
|
||||
FUNC_ENTER_PACKAGE_NOERR
|
||||
@@ -415,9 +419,10 @@ H5O__mtime_debug(H5F_t H5_ATTR_UNUSED *f, const void *_mesg, FILE *stream, int i
|
||||
assert(fwidth >= 0);
|
||||
|
||||
/* debug */
|
||||
tm = localtime(mesg);
|
||||
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tm);
|
||||
if (HDlocaltime_r(mesg, &tm_buf) != NULL)
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", &tm_buf);
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "(invalid time)");
|
||||
fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Time:", buf);
|
||||
|
||||
FUNC_LEAVE_NOAPI(SUCCEED)
|
||||
|
||||
@@ -140,7 +140,8 @@ H5VL__native_str_to_token(void *obj, H5I_type_t obj_type, const char *token_str,
|
||||
/* Check parameters */
|
||||
assert(token_str);
|
||||
|
||||
sscanf(token_str, "%" PRIuHADDR, &addr);
|
||||
if (sscanf(token_str, "%" PRIuHADDR, &addr) != 1)
|
||||
HGOTO_ERROR(H5E_FILE, H5E_CANTDECODE, FAIL, "can't parse token string");
|
||||
|
||||
if (H5VL_native_addr_to_token(obj, obj_type, addr, token) < 0)
|
||||
HGOTO_ERROR(H5E_FILE, H5E_CANTDECODE, FAIL, "can't convert address to object token");
|
||||
|
||||
+2
-1
@@ -650,7 +650,8 @@ H5VL_pass_through_str_to_info(const char *str, void **_info)
|
||||
#endif
|
||||
|
||||
/* Retrieve the underlying VOL connector value and info */
|
||||
sscanf(str, "under_vol=%u;", &under_vol_value);
|
||||
if (sscanf(str, "under_vol=%u;", &under_vol_value) != 1)
|
||||
return -1;
|
||||
under_vol_id = H5VLregister_connector_by_value((H5VL_class_value_t)under_vol_value, H5P_DEFAULT);
|
||||
under_vol_info_start = strchr(str, '{');
|
||||
under_vol_info_end = strrchr(str, '}');
|
||||
|
||||
+1
-1
@@ -960,7 +960,7 @@ H5Z__filter_nbit(unsigned flags, size_t cd_nelmts, const unsigned cd_values[], s
|
||||
} /* end if */
|
||||
/* output; compress */
|
||||
else {
|
||||
assert(nbytes == d_nelmts * cd_values[4]);
|
||||
assert(nbytes == (size_t)d_nelmts * (size_t)cd_values[4]);
|
||||
|
||||
size_out = nbytes;
|
||||
|
||||
|
||||
@@ -1298,7 +1298,7 @@ H5Z__filter_scaleoffset(unsigned flags, size_t cd_nelmts, const unsigned cd_valu
|
||||
size_t used_bytes;
|
||||
size_t unused_bytes;
|
||||
|
||||
assert(nbytes == d_nelmts * p.size);
|
||||
assert(nbytes == (size_t)d_nelmts * (size_t)p.size);
|
||||
|
||||
/* before preprocess, convert to memory endianness order if needed */
|
||||
if (need_convert)
|
||||
|
||||
@@ -698,6 +698,12 @@ H5_DLL herr_t HDqsort_fallback(void *base, size_t nel, size_t size,
|
||||
#ifndef HDlstat
|
||||
#define HDlstat(S, B) lstat(S, B)
|
||||
#endif
|
||||
#ifndef HDgmtime_r
|
||||
#define HDgmtime_r(T, R) gmtime_r(T, R)
|
||||
#endif
|
||||
#ifndef HDlocaltime_r
|
||||
#define HDlocaltime_r(T, R) localtime_r(T, R)
|
||||
#endif
|
||||
#ifndef HDmkdir
|
||||
#define HDmkdir(S, M) mkdir(S, M)
|
||||
#endif
|
||||
@@ -1814,6 +1820,7 @@ H5_DLL uint32_t H5_hash_string(const char *str);
|
||||
H5_DLL time_t H5_make_time(struct tm *tm);
|
||||
H5_DLL void H5_nanosleep(uint64_t nanosec);
|
||||
H5_DLL double H5_get_time(void);
|
||||
H5_DLL void H5_get_localtime_str(char *buf, size_t buf_size);
|
||||
|
||||
/* Functions for building paths, etc. */
|
||||
H5_DLL herr_t H5_build_extpath(const char *name, char **extpath /*out*/);
|
||||
|
||||
@@ -222,6 +222,29 @@ done:
|
||||
FUNC_LEAVE_NOAPI(ret_value)
|
||||
} /* end H5_make_time() */
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: H5_get_localtime_str
|
||||
*
|
||||
* Purpose: Formats the current local time into a string buffer using
|
||||
* the thread-safe HDlocaltime_r wrapper. On failure, writes
|
||||
* "(unknown)" so callers always get a printable result.
|
||||
*
|
||||
* Return: void
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
H5_get_localtime_str(char *buf, size_t buf_size)
|
||||
{
|
||||
time_t now;
|
||||
struct tm tm_buf;
|
||||
|
||||
time(&now);
|
||||
if (HDlocaltime_r(&now, &tm_buf) != NULL)
|
||||
strftime(buf, buf_size, "%c", &tm_buf); /* %c is locale-dependent; fine for diagnostics */
|
||||
else
|
||||
snprintf(buf, buf_size, "(unknown)");
|
||||
} /* end H5_get_localtime_str() */
|
||||
|
||||
#ifdef H5_HAVE_WIN32_API
|
||||
|
||||
/* Offset between 1/1/1601 and 1/1/1970 in 100 nanosecond units */
|
||||
|
||||
@@ -60,6 +60,28 @@ struct timezone {
|
||||
#define HDstrtok_r(X, Y, Z) strtok_s(X, Y, Z)
|
||||
#define HDunsetenv(N) Wsetenv(N, "", 1)
|
||||
|
||||
/* Windows localtime_s/gmtime_s have reversed parameter order and return
|
||||
* errno_t instead of struct tm*. Inline wrappers adapt the POSIX signature.
|
||||
*
|
||||
* The #define macros are required because H5private.h uses #ifndef HDgmtime_r
|
||||
* to decide whether to define its own passthrough macro. Without these
|
||||
* #defines the inline functions alone would not prevent that fallback, and
|
||||
* the POSIX gmtime_r/localtime_r (which MSVC does not provide) would be
|
||||
* referenced, causing LNK2019 unresolved-external errors on Windows. */
|
||||
static __inline struct tm *
|
||||
H5_gmtime_r(const time_t *timep, struct tm *result)
|
||||
{
|
||||
return gmtime_s(result, timep) == 0 ? result : NULL;
|
||||
}
|
||||
#define HDgmtime_r(T, R) H5_gmtime_r(T, R)
|
||||
|
||||
static __inline struct tm *
|
||||
H5_localtime_r(const time_t *timep, struct tm *result)
|
||||
{
|
||||
return localtime_s(result, timep) == 0 ? result : NULL;
|
||||
}
|
||||
#define HDlocaltime_r(T, R) H5_localtime_r(T, R)
|
||||
|
||||
#ifndef H5_HAVE_MINGW
|
||||
#define HDftruncate(F, L) _chsize_s(F, L)
|
||||
#define HDfseek(F, O, W) _fseeki64(F, O, W)
|
||||
|
||||
+2
-2
@@ -1037,8 +1037,8 @@ h5diff(const char *fname1, const char *fname2, const char *objname1, const char
|
||||
MPI_Abort(MPI_COMM_WORLD, 0);
|
||||
} /* end if */
|
||||
|
||||
strcpy(filenames[0], fname1);
|
||||
strcpy(filenames[1], fname2);
|
||||
snprintf(filenames[0], MAX_FILENAME, "%s", fname1);
|
||||
snprintf(filenames[1], MAX_FILENAME, "%s", fname2);
|
||||
|
||||
/* Alert the worker tasks that there's going to be work. */
|
||||
for (int i = 1; i < g_nTasks; i++)
|
||||
|
||||
@@ -396,14 +396,15 @@ xml_dump_all_cb(hid_t group, const char *name, const H5L_info2_t *linfo, void H5
|
||||
char *t_targbuf = xml_escape_the_name(targbuf);
|
||||
char *t_obj_path = xml_escape_the_name(obj_path);
|
||||
char *t_link_path;
|
||||
int res;
|
||||
/* +2 accounts for '/' separator and NUL terminator */
|
||||
size_t t_link_path_len = strlen(prefix) + linfo->u.val_size + 2;
|
||||
int res;
|
||||
|
||||
t_link_path = (char *)malloc(strlen(prefix) + linfo->u.val_size + 1);
|
||||
t_link_path = (char *)malloc(t_link_path_len);
|
||||
if (targbuf[0] == '/')
|
||||
strcpy(t_link_path, targbuf);
|
||||
snprintf(t_link_path, t_link_path_len, "%s", targbuf);
|
||||
else {
|
||||
strcpy(t_link_path, prefix);
|
||||
strcat(strcat(t_link_path, "/"), targbuf);
|
||||
snprintf(t_link_path, t_link_path_len, "%s/%s", prefix, targbuf);
|
||||
} /* end else */
|
||||
|
||||
/* Create OBJ-XIDs for the parent and object */
|
||||
|
||||
@@ -131,7 +131,11 @@ main(int argc, char *argv[])
|
||||
|
||||
case 1: /* counting input files */
|
||||
if (opt->fcount < 29) {
|
||||
(void)strcpy(opt->infiles[opt->fcount].datafile, argv[i]);
|
||||
if (snprintf(opt->infiles[opt->fcount].datafile, MAX_PATH_NAME_LENGTH, "%s", argv[i]) >=
|
||||
MAX_PATH_NAME_LENGTH) {
|
||||
(void)fprintf(rawerrorstream, err10, argv[i]);
|
||||
goto err;
|
||||
}
|
||||
in = &(opt->infiles[opt->fcount].in);
|
||||
opt->infiles[opt->fcount].config = 0;
|
||||
setDefaultValues(in, opt->fcount);
|
||||
@@ -148,7 +152,11 @@ main(int argc, char *argv[])
|
||||
break;
|
||||
|
||||
case 3: /* get configfile name */
|
||||
(void)strcpy(opt->infiles[opt->fcount - 1].configfile, argv[i]);
|
||||
if (snprintf(opt->infiles[opt->fcount - 1].configfile, MAX_PATH_NAME_LENGTH, "%s", argv[i]) >=
|
||||
MAX_PATH_NAME_LENGTH) {
|
||||
(void)fprintf(rawerrorstream, err10, argv[i]);
|
||||
goto err;
|
||||
}
|
||||
opt->infiles[opt->fcount - 1].config = 1;
|
||||
break;
|
||||
|
||||
@@ -160,7 +168,7 @@ main(int argc, char *argv[])
|
||||
(void)fprintf(rawerrorstream, err10, argv[i]);
|
||||
goto err;
|
||||
}
|
||||
(void)strcpy(opt->outfile, argv[i]);
|
||||
snprintf(opt->outfile, MAX_PATH_NAME_LENGTH, "%s", argv[i]);
|
||||
outfile_named = true;
|
||||
break;
|
||||
|
||||
@@ -2524,7 +2532,7 @@ parsePathInfo(struct path_info *path, char *temp)
|
||||
(void)fprintf(rawerrorstream, "%s", err1);
|
||||
return (-1);
|
||||
}
|
||||
strcpy(path->group[i++], token);
|
||||
snprintf(path->group[i++], MAX_PATH_NAME_LENGTH, "%s", token);
|
||||
|
||||
while (1) {
|
||||
token = strtok(NULL, delimiter);
|
||||
@@ -2534,7 +2542,7 @@ parsePathInfo(struct path_info *path, char *temp)
|
||||
(void)fprintf(rawerrorstream, "%s", err1);
|
||||
return (-1);
|
||||
}
|
||||
strcpy(path->group[i++], token);
|
||||
snprintf(path->group[i++], MAX_PATH_NAME_LENGTH, "%s", token);
|
||||
}
|
||||
path->count = i;
|
||||
return (0);
|
||||
@@ -3973,8 +3981,7 @@ getExternalFilename(struct Input *in, FILE *strm)
|
||||
|
||||
temp_len = strlen(temp);
|
||||
in->externFilename = (char *)malloc((temp_len + 1) * sizeof(char));
|
||||
(void)strcpy(in->externFilename, temp);
|
||||
in->externFilename[temp_len] = '\0';
|
||||
snprintf(in->externFilename, temp_len + 1, "%s", temp);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@@ -401,9 +401,9 @@ struct infilesformat {
|
||||
};
|
||||
|
||||
struct Options {
|
||||
struct infilesformat infiles[30]; /* structure to hold the list of input file names. Limited to 30*/
|
||||
char outfile[256]; /* output file name */
|
||||
int fcount; /* number of input files */
|
||||
struct infilesformat infiles[30]; /* structure to hold the list of input file names. Limited to 30*/
|
||||
char outfile[MAX_PATH_NAME_LENGTH]; /* output file name */
|
||||
int fcount; /* number of input files */
|
||||
};
|
||||
|
||||
static char keytable[NUM_KEYS][30] = {"PATH",
|
||||
|
||||
@@ -2285,14 +2285,15 @@ list_obj(const char *name, const H5O_info2_t *oinfo, const char *first_seen, voi
|
||||
/* Modification time */
|
||||
if (oinfo->mtime > 0) {
|
||||
char buf[256];
|
||||
struct tm *tm;
|
||||
struct tm tm_buf;
|
||||
struct tm *tm_result;
|
||||
|
||||
if (simple_output_g)
|
||||
tm = gmtime(&(oinfo->mtime));
|
||||
tm_result = HDgmtime_r(&(oinfo->mtime), &tm_buf);
|
||||
else
|
||||
tm = localtime(&(oinfo->mtime));
|
||||
if (tm) {
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tm);
|
||||
tm_result = HDlocaltime_r(&(oinfo->mtime), &tm_buf);
|
||||
if (tm_result) {
|
||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", &tm_buf);
|
||||
h5tools_str_reset(&buffer);
|
||||
h5tools_str_append(&buffer, " %-10s %s\n", "Modified:", buf);
|
||||
h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos,
|
||||
|
||||
@@ -429,10 +429,12 @@ pio_create_filename(iotype iot, const char *base_name, char *fullname, size_t si
|
||||
fullname[size - 1] = '\0';
|
||||
}
|
||||
|
||||
if ((strlen(fullname) + strlen(base_name) + 1) < size) {
|
||||
{
|
||||
/* Append the base_name with a slash first. Multiple slashes are
|
||||
* handled below. */
|
||||
h5_stat_t buf;
|
||||
size_t cur_len;
|
||||
int nchars;
|
||||
|
||||
memset(&buf, 0, sizeof(h5_stat_t));
|
||||
if (HDstat(fullname, &buf) < 0)
|
||||
@@ -440,15 +442,13 @@ pio_create_filename(iotype iot, const char *base_name, char *fullname, size_t si
|
||||
if (HDmkdir(fullname, (mode_t)0755) < 0 && errno != EEXIST) {
|
||||
/* We couldn't make the "/tmp/${USER,LOGIN}" subdirectory.
|
||||
* Default to PREFIX's original prefix value. */
|
||||
strcpy(fullname, prefix);
|
||||
snprintf(fullname, size, "%s", prefix);
|
||||
}
|
||||
|
||||
strcat(fullname, "/");
|
||||
strcat(fullname, base_name);
|
||||
}
|
||||
else {
|
||||
/* Buffer is too small */
|
||||
return NULL;
|
||||
cur_len = strlen(fullname);
|
||||
nchars = snprintf(fullname + cur_len, size - cur_len, "/%s", base_name);
|
||||
if (nchars < 0 || (size_t)nchars >= size - cur_len)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if (strlen(base_name) >= size) {
|
||||
@@ -456,15 +456,17 @@ pio_create_filename(iotype iot, const char *base_name, char *fullname, size_t si
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
strcpy(fullname, base_name);
|
||||
snprintf(fullname, size, "%s", base_name);
|
||||
}
|
||||
|
||||
/* Append a suffix */
|
||||
if (suffix) {
|
||||
if (strlen(fullname) + strlen(suffix) >= size)
|
||||
size_t cur_len = strlen(fullname);
|
||||
|
||||
if (cur_len + strlen(suffix) >= size)
|
||||
return NULL;
|
||||
|
||||
strcat(fullname, suffix);
|
||||
snprintf(fullname + cur_len, size - cur_len, "%s", suffix);
|
||||
}
|
||||
|
||||
/* Remove any double slashes in the filename */
|
||||
|
||||
@@ -338,10 +338,12 @@ sio_create_filename(iotype iot, const char *base_name, char *fullname, size_t si
|
||||
fullname[size - 1] = '\0';
|
||||
}
|
||||
|
||||
if ((strlen(fullname) + strlen(base_name) + 1) < size) {
|
||||
{
|
||||
/* Append the base_name with a slash first. Multiple slashes are
|
||||
* handled below. */
|
||||
h5_stat_t buf;
|
||||
size_t cur_len;
|
||||
int nchars;
|
||||
|
||||
memset(&buf, 0, sizeof(h5_stat_t));
|
||||
if (HDstat(fullname, &buf) < 0)
|
||||
@@ -349,15 +351,13 @@ sio_create_filename(iotype iot, const char *base_name, char *fullname, size_t si
|
||||
if (HDmkdir(fullname, 0755) < 0 && errno != EEXIST) {
|
||||
/* We couldn't make the "/tmp/${USER,LOGIN}" subdirectory.
|
||||
* Default to PREFIX's original prefix value. */
|
||||
strcpy(fullname, prefix);
|
||||
snprintf(fullname, size, "%s", prefix);
|
||||
}
|
||||
|
||||
strcat(fullname, "/");
|
||||
strcat(fullname, base_name);
|
||||
}
|
||||
else {
|
||||
/* Buffer is too small */
|
||||
return NULL;
|
||||
cur_len = strlen(fullname);
|
||||
nchars = snprintf(fullname + cur_len, size - cur_len, "/%s", base_name);
|
||||
if (nchars < 0 || (size_t)nchars >= size - cur_len)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else if (strlen(base_name) >= size) {
|
||||
@@ -365,15 +365,17 @@ sio_create_filename(iotype iot, const char *base_name, char *fullname, size_t si
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
strcpy(fullname, base_name);
|
||||
snprintf(fullname, size, "%s", base_name);
|
||||
}
|
||||
|
||||
/* Append a suffix */
|
||||
if (suffix) {
|
||||
if (strlen(fullname) + strlen(suffix) >= size)
|
||||
size_t cur_len = strlen(fullname);
|
||||
|
||||
if (cur_len + strlen(suffix) >= size)
|
||||
return NULL;
|
||||
|
||||
strcat(fullname, suffix);
|
||||
snprintf(fullname + cur_len, size - cur_len, "%s", suffix);
|
||||
}
|
||||
|
||||
/* Remove any double slashes in the filename */
|
||||
|
||||
@@ -680,7 +680,7 @@ parse_command_line(int argc, const char *const *argv, pack_opt_t *options)
|
||||
else {
|
||||
char msgType[10];
|
||||
|
||||
strcpy(msgType, msgPtr + 1);
|
||||
snprintf(msgType, sizeof(msgType), "%s", msgPtr + 1);
|
||||
msgPtr[0] = '\0';
|
||||
ssize = atoi(H5_optarg);
|
||||
if (!strncmp(msgType, "dspace", 6))
|
||||
@@ -725,7 +725,7 @@ parse_command_line(int argc, const char *const *argv, pack_opt_t *options)
|
||||
case 'S': {
|
||||
char strategy[MAX_NC_NAME];
|
||||
|
||||
strcpy(strategy, H5_optarg);
|
||||
snprintf(strategy, MAX_NC_NAME, "%s", H5_optarg);
|
||||
if (!strcmp(strategy, "FSM_AGGR"))
|
||||
options->fs_strategy = H5F_FSPACE_STRATEGY_FSM_AGGR;
|
||||
else if (!strcmp(strategy, "PAGE"))
|
||||
|
||||
@@ -94,7 +94,7 @@ parse_filter(const char *str, unsigned *n_objs, filter_info_t *filt, pack_opt_t
|
||||
else
|
||||
sobj[k + 1] = '\0';
|
||||
|
||||
strcpy(obj_list[n].obj, sobj);
|
||||
snprintf(obj_list[n].obj, MAX_NC_NAME, "%s", sobj);
|
||||
memset(sobj, 0, sizeof(sobj));
|
||||
n++;
|
||||
k = -1;
|
||||
@@ -530,7 +530,7 @@ parse_layout(const char *str, unsigned *n_objs, pack_info_t *pack, /* info about
|
||||
sobj[k] = '\0';
|
||||
else
|
||||
sobj[k + 1] = '\0';
|
||||
strcpy(obj_list[n].obj, sobj);
|
||||
snprintf(obj_list[n].obj, MAX_NC_NAME, "%s", sobj);
|
||||
memset(sobj, 0, sizeof(sobj));
|
||||
n++;
|
||||
k = -1;
|
||||
|
||||
Reference in New Issue
Block a user