[前][次][番号順一覧][スレッド一覧]

ruby-changes:26852

From: nobu <ko1@a...>
Date: Wed, 23 Jan 2013 12:28:39 +0900 (JST)
Subject: [ruby-changes:26852] nobu:r38904 (trunk): win32.c: acp_to_wstr results check

nobu	2013-01-23 12:28:25 +0900 (Wed, 23 Jan 2013)

  New Revision: 38904

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38904

  Log:
    win32.c: acp_to_wstr results check
    
    * win32/win32.c (rb_w32_spawn, rb_w32_aspawn_flags): check the results
      of acp_to_wstr() which can return NULL.  [ruby-core:51557] [Bug #7721]

  Modified files:
    trunk/ChangeLog
    trunk/win32/win32.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38903)
+++ ChangeLog	(revision 38904)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jan 23 12:28:22 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* win32/win32.c (rb_w32_spawn, rb_w32_aspawn_flags): check the results
+	  of acp_to_wstr() which can return NULL.  [ruby-core:51557] [Bug #7721]
+
 Wed Jan 23 10:40:49 2013  Eric Hodel  <drbrain@s...>
 
 	* doc/syntax/assignment.rdoc (Implicit Array Assignment):  Clarify
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 38903)
+++ win32/win32.c	(revision 38904)
@@ -1182,7 +1182,8 @@ rb_w32_spawn(int mode, const char *cmd, https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1182
     char fbuf[MAXPATHLEN];
     char *p = NULL;
     const char *shell = NULL;
-    WCHAR *wcmd, *wshell;
+    WCHAR *wcmd = NULL, *wshell = NULL;
+    int e = 0;
     rb_pid_t ret;
     VALUE v = 0;
     VALUE v2 = 0;
@@ -1267,14 +1268,17 @@ rb_w32_spawn(int mode, const char *cmd, https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1268
     }
 
     /* assume ACP */
-    wcmd = cmd ? acp_to_wstr(cmd, NULL) : NULL;
+    if (!e && cmd && !(wcmd = acp_to_wstr(cmd, NULL))) e = E2BIG;
     if (v) ALLOCV_END(v);
-    wshell = shell ? acp_to_wstr(shell, NULL) : NULL;
+    if (!e && shell && !(wshell = acp_to_wstr(shell, NULL))) e = E2BIG;
     if (v2) ALLOCV_END(v2);
 
-    ret = child_result(CreateChild(wcmd, wshell, NULL, NULL, NULL, NULL, 0), mode);
+    if (!e) {
+	ret = child_result(CreateChild(wcmd, wshell, NULL, NULL, NULL, NULL, 0), mode);
+    }
     free(wshell);
     free(wcmd);
+    if (e) errno = e;
     return ret;
 }
 
@@ -1287,7 +1291,8 @@ rb_w32_aspawn_flags(int mode, const char https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1291
     BOOL ntcmd = FALSE, tmpnt;
     const char *shell;
     char *cmd, fbuf[MAXPATHLEN];
-    WCHAR *wcmd, *wprog;
+    WCHAR *wcmd = NULL, *wprog = NULL;
+    int e = 0;
     rb_pid_t ret;
     VALUE v = 0;
 
@@ -1335,13 +1340,16 @@ rb_w32_aspawn_flags(int mode, const char https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1340
     }
 
     /* assume ACP */
-    wcmd = cmd ? acp_to_wstr(cmd, NULL) : NULL;
+    if (!e && cmd && !(wcmd = acp_to_wstr(cmd, NULL))) e = E2BIG;
     if (v) ALLOCV_END(v);
-    wprog = prog ? acp_to_wstr(prog, NULL) : NULL;
+    if (!e && prog && !(wprog = acp_to_wstr(prog, NULL))) e = E2BIG;
 
-    ret = child_result(CreateChild(wcmd, wprog, NULL, NULL, NULL, NULL, flags), mode);
+    if (!e) {
+	ret = child_result(CreateChild(wcmd, wprog, NULL, NULL, NULL, NULL, flags), mode);
+    }
     free(wprog);
     free(wcmd);
+    if (e) errno = e;
     return ret;
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]