Author: futatuki
Date: Tue May 18 19:53:53 2021
New Revision: 1890013

URL: http://svn.apache.org/viewvc?rev=1890013&view=rev
Log:
Follow-up to r1887641: Fix file path transcoding around editor invocation.

On r1887641, we use svn_utf_cstring_to_utf8() to transcode the command
line string from native file path on OS into UTF-8. However as svn_utf_
functions are for console/file I/O, it was incorrect and actually it
caused string corruption if editor invocation had failed on Windows
(and perhaps macOS) platform.

With this commit we use svn_path_cstring_to_utf8() and 
svn_path_cstring_from_utf8() for transcoding file paths instead. This
fixes the string corruption above, and also fix potential string
corruption on transcoding temporary filename, which is always ascii
string and safe on encodings we handle in current implementation.

* subversion/libsvn_subr/cmdline.c
  (svn_cmdline__edit_file_externally):
    Use svn_path_cstring_to_utf8 to transcode file paths.
  (svn_cmdline__edit_string_externally):
    Use svn_path_cstring_from_utf8 and svn_path_cstring_to_utf8 to
    transcode file paths.

Found by: jun66j5
Review by: jun66j5
Tested by: jun66j5

Modified:
    subversion/trunk/subversion/libsvn_subr/cmdline.c

Modified: subversion/trunk/subversion/libsvn_subr/cmdline.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cmdline.c?rev=1890013&r1=1890012&r2=1890013&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/cmdline.c (original)
+++ subversion/trunk/subversion/libsvn_subr/cmdline.c Tue May 18 19:53:53 2021
@@ -1504,7 +1504,7 @@ svn_cmdline__edit_file_externally(const
 
       /* Extracting any meaning from sys_err is platform specific, so just
          use the raw value. */
-      SVN_ERR(svn_utf_cstring_to_utf8(&cmd_utf8, cmd, pool));
+      SVN_ERR(svn_path_cstring_to_utf8(&cmd_utf8, cmd, pool));
       return svn_error_createf(SVN_ERR_EXTERNAL_PROGRAM, NULL,
                                _("system('%s') returned %d"),
                                cmd_utf8, sys_err);
@@ -1654,8 +1654,8 @@ svn_cmdline__edit_string_externally(svn_
     goto cleanup;
 
   /* Prepare the editor command line.  */
-  err = svn_utf_cstring_from_utf8(&tmpfile_native,
-                                  escape_path(pool, tmpfile_name), pool);
+  err = svn_path_cstring_from_utf8(&tmpfile_native,
+                                   escape_path(pool, tmpfile_name), pool);
   if (err)
     goto cleanup;
 
@@ -1688,7 +1688,7 @@ svn_cmdline__edit_string_externally(svn_
 
       /* Extracting any meaning from sys_err is platform specific, so just
          use the raw value. */
-      SVN_ERR(svn_utf_cstring_to_utf8(&cmd_utf8, cmd, pool));
+      SVN_ERR(svn_path_cstring_to_utf8(&cmd_utf8, cmd, pool));
       err =  svn_error_createf(SVN_ERR_EXTERNAL_PROGRAM, NULL,
                                _("system('%s') returned %d"),
                                cmd_utf8, sys_err);


Reply via email to