From 8ebe5b99302bdf0590aa7c3facac1998a3a51cea Mon Sep 17 00:00:00 2001 From: David PHAM-VAN Date: Fri, 12 Feb 2016 11:32:18 -0800 Subject: [PATCH] Fix bad malloc size in statvfs --- channels/drive/client/statvfs.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/channels/drive/client/statvfs.c b/channels/drive/client/statvfs.c index 60722a5..e92a975 100644 --- a/channels/drive/client/statvfs.c +++ b/channels/drive/client/statvfs.c @@ -3,6 +3,8 @@ * statvfs emulation for Windows * * Copyright 2012 Gerald Richter + * Copyright 2016 Inuvika Inc. + * Copyright 2016 David PHAM-VAN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,17 +31,18 @@ int statvfs(const char *path, struct statvfs *buf) { BOOL res; int len; - LPWSTR unicodestr; + LPWSTR unicodestr = NULL; DWORD lpSectorsPerCluster; DWORD lpBytesPerSector; DWORD lpNumberOfFreeClusters; DWORD lpTotalNumberOfClusters; - len = MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0); - unicodestr = (LPWSTR) malloc(len); - MultiByteToWideChar(CP_ACP, 0, path, -1, unicodestr, len); + len = ConvertToUnicode(CP_ACP, 0, path, -1, &unicodestr, 0); + if (len <= 0) + return -1; - res = GetDiskFreeSpace(unicodestr, &lpSectorsPerCluster, &lpBytesPerSector, &lpNumberOfFreeClusters, &lpTotalNumberOfClusters); + res = GetDiskFreeSpaceW(unicodestr, &lpSectorsPerCluster, &lpBytesPerSector, &lpNumberOfFreeClusters, &lpTotalNumberOfClusters); + free(unicodestr); buf->f_bsize = lpBytesPerSector; /* file system block size */ buf->f_frsize = 0; /* fragment size */ -- 2.7.4