diff options
author | Clarisse Cheah <clarisse.cheah@mongodb.com> | 2023-04-05 01:23:54 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-04-05 02:26:41 +0000 |
commit | d92ff116aef711e62e19f87a581fc865ebd05a7e (patch) | |
tree | ab6f411bb53983401c1488fad720b653934a0ca3 | |
parent | ce31ea9186fef3e983c2fd3ea892c629228e6dcd (diff) | |
download | mongo-d92ff116aef711e62e19f87a581fc865ebd05a7e.tar.gz |
Import wiredtiger: bd63ad2959da66d388a2199554817840ac8847f8 from branch mongodb-master
ref: aba0d79895..bd63ad2959
for: 7.0.0-rc0
WT-10870 Implement a safe version of strcat and use it in testutil_copy_data_opt
-rw-r--r-- | src/third_party/wiredtiger/dist/s_funcs.list | 1 | ||||
-rw-r--r-- | src/third_party/wiredtiger/dist/s_string.ok | 2 | ||||
-rw-r--r-- | src/third_party/wiredtiger/import.data | 2 | ||||
-rw-r--r-- | src/third_party/wiredtiger/src/include/extern.h | 2 | ||||
-rw-r--r-- | src/third_party/wiredtiger/src/include/misc_inline.h | 22 | ||||
-rw-r--r-- | src/third_party/wiredtiger/test/utility/misc.c | 8 |
6 files changed, 32 insertions, 5 deletions
diff --git a/src/third_party/wiredtiger/dist/s_funcs.list b/src/third_party/wiredtiger/dist/s_funcs.list index 094e9773d74..1b831580e27 100644 --- a/src/third_party/wiredtiger/dist/s_funcs.list +++ b/src/third_party/wiredtiger/dist/s_funcs.list @@ -33,6 +33,7 @@ __wt_print_huffman_code __wt_session_breakpoint __wt_stat_join_aggregate __wt_stat_join_clear_all +__wt_strcat __wt_stream_set_no_buffer __wt_try_readlock populate_thread diff --git a/src/third_party/wiredtiger/dist/s_string.ok b/src/third_party/wiredtiger/dist/s_string.ok index 228d6d8628b..138172982cd 100644 --- a/src/third_party/wiredtiger/dist/s_string.ok +++ b/src/third_party/wiredtiger/dist/s_string.ok @@ -114,6 +114,7 @@ ENOMEM ENOTSUP ENUM EOF +ERANGE ETIME ETIMEDOUT EVICTSERVER @@ -1183,6 +1184,7 @@ stdout stepp str strace +strcat strcmp strdup strerror diff --git a/src/third_party/wiredtiger/import.data b/src/third_party/wiredtiger/import.data index 71ef84d9748..b1c93ed5b02 100644 --- a/src/third_party/wiredtiger/import.data +++ b/src/third_party/wiredtiger/import.data @@ -2,5 +2,5 @@ "vendor": "wiredtiger", "github": "wiredtiger/wiredtiger.git", "branch": "mongodb-master", - "commit": "aba0d7989544c0242d3730ebf9e113d4a0cf1c70" + "commit": "bd63ad2959da66d388a2199554817840ac8847f8" } diff --git a/src/third_party/wiredtiger/src/include/extern.h b/src/third_party/wiredtiger/src/include/extern.h index 8dbc1181230..593887e5c4c 100644 --- a/src/third_party/wiredtiger/src/include/extern.h +++ b/src/third_party/wiredtiger/src/include/extern.h @@ -2252,6 +2252,8 @@ static inline int __wt_spin_trylock(WT_SESSION_IMPL *session, WT_SPINLOCK *t) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); static inline int __wt_spin_trylock_track(WT_SESSION_IMPL *session, WT_SPINLOCK *t) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); +static inline int __wt_strcat(char *dest, size_t size, const char *src) + WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); static inline int __wt_strdup(WT_SESSION_IMPL *session, const char *str, void *retp) WT_GCC_FUNC_DECL_ATTRIBUTE((warn_unused_result)); static inline int __wt_struct_packv(WT_SESSION_IMPL *session, void *buffer, size_t size, diff --git a/src/third_party/wiredtiger/src/include/misc_inline.h b/src/third_party/wiredtiger/src/include/misc_inline.h index d5e8e8812fa..8f955c01fd1 100644 --- a/src/third_party/wiredtiger/src/include/misc_inline.h +++ b/src/third_party/wiredtiger/src/include/misc_inline.h @@ -64,6 +64,28 @@ __wt_strnlen(const char *s, size_t maxlen) } /* + * __wt_strcat -- + * A safe version of string concatenation, which checks the size of the destination buffer; + * return ERANGE on error. + */ +static inline int +__wt_strcat(char *dest, size_t size, const char *src) +{ + size_t dest_length; + size_t src_length; + + dest_length = strlen(dest); + src_length = strlen(src); + + if (dest_length + src_length + 1 > size) /* Account for the null-terminating byte. */ + return (ERANGE); + + memcpy(dest + dest_length, src, src_length); + dest[dest_length + src_length] = '\0'; + return (0); +} + +/* * __wt_snprintf -- * snprintf convenience function, ignoring the returned size. */ diff --git a/src/third_party/wiredtiger/test/utility/misc.c b/src/third_party/wiredtiger/test/utility/misc.c index b66df66f6cc..80d1188d802 100644 --- a/src/third_party/wiredtiger/test/utility/misc.c +++ b/src/third_party/wiredtiger/test/utility/misc.c @@ -325,15 +325,15 @@ testutil_copy_data_opt(const char *dir, const char *readonly_prefix) testutil_system("cp -rp -l %s ../%s.SAVE", to_link, dir); to_link[0] = '\0'; } - strcat(to_link, " "); - strcat(to_link, e->d_name); + testutil_check(__wt_strcat(to_link, sizeof(to_link), " ")); + testutil_check(__wt_strcat(to_link, sizeof(to_link), e->d_name)); } else { if (strlen(to_copy) + strlen(e->d_name) + 2 >= sizeof(to_copy)) { testutil_system("cp -rp %s ../%s.SAVE", to_copy, dir); to_copy[0] = '\0'; } - strcat(to_copy, " "); - strcat(to_copy, e->d_name); + testutil_check(__wt_strcat(to_copy, sizeof(to_copy), " ")); + testutil_check(__wt_strcat(to_copy, sizeof(to_copy), e->d_name)); } } testutil_check(closedir(d)); |