Fix a buffer overflow in the Windows termios emulation.

The  YACK() macro  generates  a  message of  variable  length due  the
__FILE__ string  and a  message returned  by MS  FormatMessage() being
inserted  into a  fixed length  string  buffer. I  have increased  the
buffer length to 1024 bytes and used snprintf to avoid overflows.

It looks like the whole YACK() macro should do nothing unless DEBUG is
defined so  there is probably  a small performance  gain to be  had by
doing that also. I have left that to the experts to decide.
Hamlib-3.0
Bill Somerville 2014-03-24 17:09:03 +00:00
rodzic 6e44327a7c
commit b27b423dce
1 zmienionych plików z 2 dodań i 2 usunięć

Wyświetl plik

@ -39,7 +39,7 @@
#endif /* TRACE */
#define YACK() \
{ \
char *allocTextBuf, message[80]; \
char *allocTextBuf, message[1024]; \
unsigned int errorCode = GetLastError(); \
FormatMessage ( \
FORMAT_MESSAGE_ALLOCATE_BUFFER | \
@ -50,7 +50,7 @@
(LPSTR)&allocTextBuf, \
16, \
NULL ); \
sprintf( message, "Error 0x%x at %s(%d): %s\n", errorCode, __FILE__, __LINE__, allocTextBuf); \
snprintf( message, sizeof (message), "Error 0x%x at %s(%d): %s\n", errorCode, __FILE__, __LINE__, allocTextBuf); \
report_error( message ); \
LocalFree(allocTextBuf); \
}