From 71e6011d63fde90dc7f6dda1e93acfe0c6eae585 Mon Sep 17 00:00:00 2001 From: suke Date: Sat, 25 Aug 2007 21:57:46 +0000 Subject: [PATCH] * ext/win32ole/win32ole.c (ole_wc2mb, reg_enum_key): allocate buffer should be NULL terminated. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13277 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/win32ole/win32ole.c | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d696a4658b..1c2713760d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Aug 26 06:51:46 2007 Masaki Suketa + + * ext/win32ole/win32ole.c (ole_wc2mb, reg_enum_key): allocate + buffer should be NULL terminated. + Sun Aug 26 06:04:13 2007 Koichi Sasada * insnhelper.ci (vm_setup_method): reorder code for branch prediction. diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c index 8d76bc5fbb..28a6ec79f7 100644 --- a/ext/win32ole/win32ole.c +++ b/ext/win32ole/win32ole.c @@ -116,7 +116,7 @@ #define WC2VSTR(x) ole_wc2vstr((x), TRUE) -#define WIN32OLE_VERSION "1.0.4" +#define WIN32OLE_VERSION "1.0.5" typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX) (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*); @@ -768,8 +768,9 @@ ole_wc2mb(LPWSTR pw) LPSTR pm; size = WideCharToMultiByte(cWIN32OLE_cp, 0, pw, -1, NULL, 0, NULL, NULL); if (size) { - pm = ALLOC_N(char, size); + pm = ALLOC_N(char, size + 1); WideCharToMultiByte(cWIN32OLE_cp, 0, pw, -1, pm, size, NULL, NULL); + pm[size] = '\0'; } else { pm = ALLOC_N(char, 1); @@ -1913,12 +1914,13 @@ reg_open_vkey(HKEY hkey, VALUE key, HKEY *phkey) static VALUE reg_enum_key(HKEY hkey, DWORD i) { - char buf[BUFSIZ]; + char buf[BUFSIZ + 1]; DWORD size_buf = sizeof(buf); FILETIME ft; LONG err = RegEnumKeyEx(hkey, i, buf, &size_buf, NULL, NULL, NULL, &ft); if(err == ERROR_SUCCESS) { + buf[BUFSIZ] = '\0'; return rb_str_new2(buf); } return Qnil;