Alexandre Julliard : ntdll: Add _splitpath_s.
Alexandre Julliard
julliard at winehq.org
Thu Jun 30 16:34:20 CDT 2022
Module: wine
Branch: master
Commit: 5d2f0688cfdd782962f7104a87b925890b68dd48
URL: https://source.winehq.org/git/wine.git/?a=commit;h=5d2f0688cfdd782962f7104a87b925890b68dd48
Author: Alexandre Julliard <julliard at winehq.org>
Date: Thu Jun 30 11:06:44 2022 +0200
ntdll: Add _splitpath_s.
Implementation copied from msvcrt.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ntdll/ntdll.spec | 1 +
dlls/ntdll/string.c | 81 +++++++++++++++++++++++++++++++++++++--------------
2 files changed, 60 insertions(+), 22 deletions(-)
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index 9291ed63f77..ffc3cb00fcd 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -1524,6 +1524,7 @@
@ varargs _snwprintf_s(ptr long long wstr)
@ varargs _swprintf(ptr wstr) NTDLL_swprintf
@ cdecl _splitpath(str ptr ptr ptr ptr)
+@ cdecl _splitpath_s(str ptr long ptr long ptr long ptr long)
@ cdecl _strcmpi(str str) _stricmp
@ cdecl _stricmp(str str)
@ cdecl _strlwr(str)
diff --git a/dlls/ntdll/string.c b/dlls/ntdll/string.c
index 5a971a4a0b2..2e3bbc043e5 100644
--- a/dlls/ntdll/string.c
+++ b/dlls/ntdll/string.c
@@ -1852,37 +1852,37 @@ int WINAPIV sscanf( const char *str, const char *format, ... )
}
-/*********************************************************************
- * _splitpath (NTDLL.@)
- *
- * Split a path into its component pieces.
- *
- * PARAMS
- * inpath [I] Path to split
- * drv [O] Destination for drive component (e.g. "A:"). Must be at least 3 characters.
- * dir [O] Destination for directory component. Should be at least MAX_PATH characters.
- * fname [O] Destination for File name component. Should be at least MAX_PATH characters.
- * ext [O] Destination for file extension component. Should be at least MAX_PATH characters.
- *
- * RETURNS
- * Nothing.
+/******************************************************************
+ * _splitpath_s (NTDLL.@)
*/
-void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
- char* fname, char * ext )
+errno_t __cdecl _splitpath_s( const char *inpath, char *drive, size_t sz_drive,
+ char *dir, size_t sz_dir, char *fname, size_t sz_fname,
+ char *ext, size_t sz_ext )
{
const char *p, *end;
+ if (!inpath || (!drive && sz_drive) ||
+ (drive && !sz_drive) ||
+ (!dir && sz_dir) ||
+ (dir && !sz_dir) ||
+ (!fname && sz_fname) ||
+ (fname && !sz_fname) ||
+ (!ext && sz_ext) ||
+ (ext && !sz_ext))
+ return EINVAL;
+
if (inpath[0] && inpath[1] == ':')
{
- if (drv)
+ if (drive)
{
- drv[0] = inpath[0];
- drv[1] = inpath[1];
- drv[2] = 0;
+ if (sz_drive <= 2) goto error;
+ drive[0] = inpath[0];
+ drive[1] = inpath[1];
+ drive[2] = 0;
}
inpath += 2;
}
- else if (drv) drv[0] = 0;
+ else if (drive) drive[0] = '\0';
/* look for end of directory part */
end = NULL;
@@ -1892,6 +1892,7 @@ void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
{
if (dir)
{
+ if (sz_dir <= end - inpath) goto error;
memcpy( dir, inpath, end - inpath );
dir[end - inpath] = 0;
}
@@ -1907,8 +1908,44 @@ void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
if (fname)
{
+ if (sz_fname <= end - inpath) goto error;
memcpy( fname, inpath, end - inpath );
fname[end - inpath] = 0;
}
- if (ext) strcpy( ext, end );
+ if (ext)
+ {
+ if (sz_ext <= strlen(end)) goto error;
+ strcpy( ext, end );
+ }
+ return 0;
+
+error:
+ if (drive) drive[0] = 0;
+ if (dir) dir[0] = 0;
+ if (fname) fname[0]= 0;
+ if (ext) ext[0]= 0;
+ return ERANGE;
+}
+
+
+/*********************************************************************
+ * _splitpath (NTDLL.@)
+ *
+ * Split a path into its component pieces.
+ *
+ * PARAMS
+ * inpath [I] Path to split
+ * drv [O] Destination for drive component (e.g. "A:"). Must be at least 3 characters.
+ * dir [O] Destination for directory component. Should be at least MAX_PATH characters.
+ * fname [O] Destination for File name component. Should be at least MAX_PATH characters.
+ * ext [O] Destination for file extension component. Should be at least MAX_PATH characters.
+ *
+ * RETURNS
+ * Nothing.
+ */
+void __cdecl _splitpath(const char* inpath, char * drv, char * dir,
+ char* fname, char * ext )
+{
+ _splitpath_s( inpath, drv, drv ? _MAX_DRIVE : 0, dir, dir ? _MAX_DIR : 0,
+ fname, fname ? _MAX_FNAME : 0, ext, ext ? _MAX_EXT : 0 );
}
More information about the wine-cvs
mailing list