Win32: Updated various native string handling to use the new _s "secure" variants.
This commit is contained in:
parent
4dcd3421c0
commit
cce631748d
|
@ -83,7 +83,7 @@ static jstring sprintfJavaString(JNIEnv *env, const char *format, va_list ap) {
|
||||||
char buffer[BUFFER_SIZE];
|
char buffer[BUFFER_SIZE];
|
||||||
jstring str;
|
jstring str;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
_vsnprintf(buffer, BUFFER_SIZE, format, ap);
|
vsnprintf_s(buffer, BUFFER_SIZE, _TRUNCATE, format, ap);
|
||||||
#else
|
#else
|
||||||
vsnprintf(buffer, BUFFER_SIZE, format, ap);
|
vsnprintf(buffer, BUFFER_SIZE, format, ap);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -263,9 +263,11 @@ void restoreDisplayMode(void) {
|
||||||
|
|
||||||
jstring getVersion(JNIEnv * env, char *driver)
|
jstring getVersion(JNIEnv * env, char *driver)
|
||||||
{
|
{
|
||||||
|
#define BUFFER_SIZE 1024
|
||||||
jstring ret = NULL;
|
jstring ret = NULL;
|
||||||
|
|
||||||
TCHAR driverDLL[256] = "\0";
|
const char *dll_ext = ".dll";
|
||||||
|
TCHAR driverDLL[BUFFER_SIZE] = "\0";
|
||||||
DWORD var = 0;
|
DWORD var = 0;
|
||||||
DWORD dwInfoSize;
|
DWORD dwInfoSize;
|
||||||
LPVOID lpInfoBuff;
|
LPVOID lpInfoBuff;
|
||||||
|
@ -274,8 +276,8 @@ jstring getVersion(JNIEnv * env, char *driver)
|
||||||
if (driver == NULL) {
|
if (driver == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
strcat(driverDLL, driver);
|
strncat_s(driverDLL, BUFFER_SIZE, driver, strlen(driver));
|
||||||
strcat(driverDLL, ".dll");
|
strncat_s(driverDLL, BUFFER_SIZE, dll_ext, strlen(dll_ext));
|
||||||
dwInfoSize = GetFileVersionInfoSize(driverDLL, &var);
|
dwInfoSize = GetFileVersionInfoSize(driverDLL, &var);
|
||||||
lpInfoBuff = malloc(dwInfoSize);
|
lpInfoBuff = malloc(dwInfoSize);
|
||||||
bRetval = GetFileVersionInfo(driverDLL, 0, dwInfoSize, lpInfoBuff);
|
bRetval = GetFileVersionInfo(driverDLL, 0, dwInfoSize, lpInfoBuff);
|
||||||
|
@ -286,11 +288,11 @@ jstring getVersion(JNIEnv * env, char *driver)
|
||||||
UINT uiLen = 0;
|
UINT uiLen = 0;
|
||||||
bRetval = VerQueryValue(lpInfoBuff, TEXT("\\"), (void **) &fxdFileInfo, &uiLen);
|
bRetval = VerQueryValue(lpInfoBuff, TEXT("\\"), (void **) &fxdFileInfo, &uiLen);
|
||||||
if (bRetval != 0) {
|
if (bRetval != 0) {
|
||||||
TCHAR version[256];
|
TCHAR version[BUFFER_SIZE];
|
||||||
TCHAR ms[10], ls[10];
|
TCHAR ms[BUFFER_SIZE], ls[BUFFER_SIZE];
|
||||||
sprintf(ms, "%d.%d\0", fxdFileInfo->dwProductVersionMS >> 16, fxdFileInfo->dwProductVersionMS & 0xFFFF);
|
_snprintf_s(ms, BUFFER_SIZE, _TRUNCATE, "%d.%d\0", fxdFileInfo->dwProductVersionMS >> 16, fxdFileInfo->dwProductVersionMS & 0xFFFF);
|
||||||
sprintf(ls, "%d.%d\0", fxdFileInfo->dwProductVersionLS >> 16, fxdFileInfo->dwProductVersionLS & 0xFFFF);
|
_snprintf_s(ls, BUFFER_SIZE, _TRUNCATE, "%d.%d\0", fxdFileInfo->dwProductVersionLS >> 16, fxdFileInfo->dwProductVersionLS & 0xFFFF);
|
||||||
sprintf(version, "%s.%s\0", ms, ls);
|
_snprintf_s(version, BUFFER_SIZE, _TRUNCATE, "%s.%s\0", ms, ls);
|
||||||
ret = NewStringNative(env, version);
|
ret = NewStringNative(env, version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,15 +101,17 @@ JNIEXPORT void JNICALL Java_org_lwjgl_NativeSysImplementation_alert
|
||||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_NativeSysImplementation_openURL
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_NativeSysImplementation_openURL
|
||||||
(JNIEnv * env, jobject ignored, jstring url)
|
(JNIEnv * env, jobject ignored, jstring url)
|
||||||
{
|
{
|
||||||
|
#define BUFFER_SIZE 1024
|
||||||
|
const char *std_args = "rundll32 url.dll,FileProtocolHandler ";
|
||||||
STARTUPINFO si;
|
STARTUPINFO si;
|
||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
|
|
||||||
char * urlString = GetStringNativeChars(env, url);
|
char * urlString = GetStringNativeChars(env, url);
|
||||||
|
|
||||||
char command[256];
|
char command[BUFFER_SIZE];
|
||||||
strcpy(command, "");
|
strncpy_s(command, BUFFER_SIZE, "", 1);
|
||||||
strcat(command, "rundll32 url.dll,FileProtocolHandler ");
|
strncat_s(command, BUFFER_SIZE, std_args, _TRUNCATE);
|
||||||
strncat(command, urlString, 200); // Prevent buffer overflow
|
strncat_s(command, BUFFER_SIZE, urlString, _TRUNCATE);
|
||||||
free(urlString);
|
free(urlString);
|
||||||
|
|
||||||
ZeroMemory( &si, sizeof(si) );
|
ZeroMemory( &si, sizeof(si) );
|
||||||
|
@ -140,8 +142,6 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_NativeSysImplementation_openURL
|
||||||
return JNI_TRUE;
|
return JNI_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const void * getClipboard(int type)
|
const void * getClipboard(int type)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue