Bug 568079: Fix potential buffer overflows

Change-Id: I79898944575f895bfe4d99ce2aabaa88ea58d678
Signed-off-by: Torbjörn Svensson <azoff@svenskalinuxforeningen.se>
This commit is contained in:
Torbjörn Svensson 2020-11-04 22:52:51 +01:00 committed by Jonah Graham
parent 7f7a310c07
commit 60bdeb63ca
5 changed files with 3 additions and 3 deletions

View file

@ -53,7 +53,7 @@ static void closeAndthrowIOException(HANDLE handle, JNIEnv *env, const char *msg
#endif
char buff[256];
#ifndef __MINGW32__
sprintf(buff, "%s: %s", msg, strerror(errno));
snprintf(buff, sizeof(buff), "%s: %s", msg, strerror(errno));
close(fd);
#else
sprintf_s(buff, sizeof(buff), "%s (%d)", msg, GetLastError());
@ -67,7 +67,7 @@ static void closeAndthrowIOException(HANDLE handle, JNIEnv *env, const char *msg
static void throwIOException(JNIEnv *env, const char *msg) {
char buff[256];
#ifndef __MINGW32__
sprintf(buff, "%s: %s", msg, strerror(errno));
snprintf(buff, sizeof(buff), "%s: %s", msg, strerror(errno));
#else
sprintf_s(buff, sizeof(buff), "%s (%d)", msg, GetLastError());
#endif
@ -82,7 +82,7 @@ JNIEXPORT jlong JNICALL FUNC(open0)(JNIEnv *env, jobject jobj, jstring portName,
int fd = open(cportName, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd < 0) {
char msg[256];
sprintf(msg, "Error opening %s", cportName);
snprintf(msg, sizeof(msg), "Error opening %s", cportName);
(*env)->ReleaseStringUTFChars(env, portName, cportName);
throwIOException(env, msg);
return fd;