Index: sandbox/win/src/sandbox_nt_util.cc |
diff --git a/sandbox/win/src/sandbox_nt_util.cc b/sandbox/win/src/sandbox_nt_util.cc |
index 64fd1f1f6d7f2c173b39d476925b2c1e3a90da6a..d56a45a30d5c6c9d8b7e43a8e773bded72cfadc6 100644 |
--- a/sandbox/win/src/sandbox_nt_util.cc |
+++ b/sandbox/win/src/sandbox_nt_util.cc |
@@ -306,18 +306,10 @@ NTSTATUS AllocAndCopyName(const OBJECT_ATTRIBUTES* in_object, |
if (NULL == in_object->ObjectName->Buffer) |
break; |
- size_t size = in_object->ObjectName->Length + sizeof(wchar_t); |
- *out_name = new(NT_ALLOC) wchar_t[size/sizeof(wchar_t)]; |
- if (NULL == *out_name) |
- break; |
- |
- ret = CopyData(*out_name, in_object->ObjectName->Buffer, |
- size - sizeof(wchar_t)); |
+ ret = AllocAndCopyUnicodeString(in_object->ObjectName, out_name); |
if (!NT_SUCCESS(ret)) |
break; |
- (*out_name)[size / sizeof(wchar_t) - 1] = L'\0'; |
- |
if (attributes) |
*attributes = in_object->Attributes; |
@@ -617,6 +609,25 @@ bool IsSupportedRenameCall(FILE_RENAME_INFORMATION* file_info, DWORD length, |
return true; |
} |
+NTSTATUS AllocAndCopyUnicodeString(const UNICODE_STRING* in_string, |
+ wchar_t** out_string) { |
+ if (!in_string) |
+ return STATUS_INVALID_PARAMETER; |
+ |
+ size_t size = in_string->Length + sizeof(wchar_t); |
+ *out_string = new(NT_ALLOC) wchar_t[size/sizeof(wchar_t)]; |
+ if (NULL == *out_string) |
+ return STATUS_UNSUCCESSFUL; |
+ |
+ NTSTATUS ret = CopyData(*out_string, in_string->Buffer, |
+ size - sizeof(wchar_t)); |
+ if (!NT_SUCCESS(ret)) |
+ return ret; |
+ |
+ (*out_string)[size / sizeof(wchar_t) - 1] = L'\0'; |
+ return STATUS_SUCCESS; |
+} |
+ |
} // namespace sandbox |
void* operator new(size_t size, sandbox::AllocationType type, |