Bugfix: Fix possible buffer overflow (#901)
authorLuke Dashjr <luke-jr+git@utopios.org>
Sat, 3 Mar 2012 18:51:10 +0000 (13:51 -0500)
committerLuke Dashjr <luke-jr+git@utopios.org>
Sat, 3 Mar 2012 18:51:10 +0000 (13:51 -0500)
Upstream commit: 21ae37d (partial)

src/util.cpp

index e2e104c..0f496bc 100644 (file)
@@ -653,20 +653,25 @@ string MyGetSpecialFolderPath(int nFolder, bool fCreate)
     }
 
     // Backup option
-    pszPath[0] = '\0';
+    std::string strPath;
     {
+        const char *pszEnv;
         if (nFolder == CSIDL_STARTUP)
         {
-            strcpy(pszPath, getenv("USERPROFILE"));
-            strcat(pszPath, "\\Start Menu\\Programs\\Startup");
+            pszEnv = getenv("USERPROFILE");
+            if (pszEnv)
+                strPath = pszEnv;
+            strPath += "\\Start Menu\\Programs\\Startup";
         }
         else if (nFolder == CSIDL_APPDATA)
         {
-            strcpy(pszPath, getenv("APPDATA"));
+            pszEnv = getenv("APPDATA");
+            if (pszEnv)
+                strPath = pszEnv;
         }
     }
 
-    return pszPath;
+    return strPath;
 }
 #endif