From 5024b77492353db28b69a325d07f3cc123e2b2f0 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 17 Sep 2019 02:43:40 +0200 Subject: [PATCH] Prevent more strlcats that are quite trivial --- libretro-common/file/file_path.c | 23 +++++++++++++--------- libretro-common/include/string/stdstring.h | 9 +++++++-- wiiu/fs/fs_utils.c | 10 ++++++---- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 25d2e39228..83cd4c722e 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -1295,20 +1295,25 @@ void fill_pathname_application_path(char *s, size_t len) CFStringRef bundle_path = CFURLCopyPath(bundle_url); CFStringGetCString(bundle_path, s, len, kCFStringEncodingUTF8); #ifdef HAVE_COCOATOUCH - // This needs to be done so that the path becomes /private/var/... and this - // is used consistently throughout for the iOS bundle path - char resolved_bundle_dir_buf[PATH_MAX_LENGTH] = {0}; - if (realpath(s, resolved_bundle_dir_buf)) - { - strlcpy(s,resolved_bundle_dir_buf, len); - strlcat(s,"/",len); - } + { + /* This needs to be done so that the path becomes + * /private/var/... and this + * is used consistently throughout for the iOS bundle path */ + char resolved_bundle_dir_buf[PATH_MAX_LENGTH] = {0}; + if (realpath(s, resolved_bundle_dir_buf)) + { + size_t copied = strlcpy(s,resolved_bundle_dir_buf, len); + s[copied] = '/'; + s[copied+1] = '\0'; + } + } #endif CFRelease(bundle_path); CFRelease(bundle_url); #ifndef HAVE_COCOATOUCH - // Not sure what this does but it breaks stuff for iOS so skipping + /* Not sure what this does but it breaks + * stuff for iOS, so skipping */ retro_assert(strlcat(s, "nobin", len) < len); #endif return; diff --git a/libretro-common/include/string/stdstring.h b/libretro-common/include/string/stdstring.h index d24b806636..e764eb8ae9 100644 --- a/libretro-common/include/string/stdstring.h +++ b/libretro-common/include/string/stdstring.h @@ -59,15 +59,20 @@ static INLINE bool string_is_equal(const char *a, const char *b) #define string_add_glob_open(s, size) strlcat((s), "glob('*", (size)) #define string_add_glob_close(s, size) strlcat((s), "*')", (size)) +#define string_add_pair_close_fast(s, size) \ + (s)[size] = ')'; \ + (s)[size+1] = '\0' + #define string_is_not_equal_fast(a, b, size) (memcmp(a, b, size) != 0) #define string_is_equal_fast(a, b, size) (memcmp(a, b, size) == 0) static INLINE void string_add_between_pairs(char *s, const char *str, size_t size) { + size_t copied; string_add_pair_open(s, size); - strlcat(s, str, size); - string_add_pair_close(s, size); + copied = strlcat(s, str, size); + string_add_pair_close_fast(s, copied); } static INLINE bool string_is_equal_case_insensitive(const char *a, diff --git a/wiiu/fs/fs_utils.c b/wiiu/fs/fs_utils.c index 92c59eab62..5188970303 100644 --- a/wiiu/fs/fs_utils.c +++ b/wiiu/fs/fs_utils.c @@ -176,14 +176,16 @@ int CreateSubfolder(const char * fullpath) { char parentpath[strlen(dirnoslash)+2]; - strcpy(parentpath, dirnoslash); - char * ptr = strrchr(parentpath, '/'); + size_t copied = strcpy(parentpath, dirnoslash); + char * ptr = strrchr(parentpath, '/'); if (!ptr) { - /* Device root directory (must be with '/') */ - strcat(parentpath, "/"); struct stat filestat; + /* Device root directory (must be with '/') */ + parentpath[copied] = '/'; + parentpath[copied+1] = '\0'; + if (stat(parentpath, &filestat) == 0) return 1;