Skip to content

Commit

Permalink
Stop buffer overrun in lou_getProgramPath, and also free memory after…
Browse files Browse the repository at this point in the history
… usage.

As compilation on Windows could  define "UNICODE", GetModuleFilename may provide a unicode path, yet,  further code expects it to be single-byte chars.
Therefore, explicitly use GetModuleFilenameA.
  • Loading branch information
michaelDCurran committed Mar 9, 2016
1 parent 75ac434 commit fb65ff0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions liblouis/compileTranslationTable.c
Expand Up @@ -84,7 +84,9 @@ lou_getProgramPath ()
buffer = reallocWrapper (buffer, size <<= 1);

{
DWORD length = GetModuleFileName (handle, buffer, size);
// As the "UNICODE" Windows define may have been set at compilation,
// This call must be specifically GetModuleFilenameA as further code expects it to be single byte chars.
DWORD length = GetModuleFileNameA (handle, buffer, size);

if (!length)
{
Expand Down Expand Up @@ -4552,8 +4554,11 @@ getTablePath()
"tables");
#ifdef _WIN32
path = lou_getProgramPath ();
if (path != NULL && path[0] != '\0')
cp += sprintf (cp, ",%s%s", path, "\\share\\liblouis\\tables");
if (path != NULL) {
if(path[0] != '\0')
cp += sprintf (cp, ",%s%s", path, "\\share\\liblouis\\tables");
free(path);
}
#else
cp += sprintf (cp, ",%s", TABLESDIR);
#endif
Expand Down

0 comments on commit fb65ff0

Please sign in to comment.