Skip to content
Memory corruption Disclosed report Intermediate

A stack buffer overflow in BabyGrid.cpp can lead to program crashes via a malicious localization file

A stack buffer overflow in Notepad++'s BabyGrid.cpp occurs when a malicious nativeLang.xml file contains an overly long name attribute for certain ShortcutMapper tags, due to unsafe lstrcat and lstrcpy calls without bounds checks. An attacker could cause the program to crash when the user opens the Shortcut Mapper, potentially leading to loss of unsaved data.

peter_ Follow

Originally disclosed on HackerOne

  • Triaged in 2 days
  • Fixed in 17 days
  • Paid in 11 days
  • Disclosed after 3 months

Summary: A stack buffer overflow in BabyGrid.cpp can lead to program crashes via a malicious localization file, when opening the Shortcut Mapper sub-menu

Description: Setting a very long name attribute for specific xml tags in the nativeLang.xml will trigger a stack buffer overflow, due to missing bound checks.

The nativeLang.xml file is an optional configuration file, as described in http://docs.notepad-plus-plus.org/index.php/Configuration_Files, http://docs.notepad-plus-plus.org/index.php/Localisation, https://notepad-plus-plus.org/contribute/binary-translation-howto.html. nativeLang.xml lets users change the localization language of Notepad++, by providing alternative translations for every visible string in the GUI.

In the nativeLang.xml file, in the ShortcutMapper tag, the name attribute of any of the following children is vulnerable:

  • ColumnName
  • ColumnShortcut
  • ColumnCategory
  • ColumnPlugin

The overflow is triggered with:

  • a name with more than ~1000 characters on the 32-bit program
  • a name with more than ~2000 characters on the 64-bit program

See the attached proofs of concept as an example.

The cause of the overflow is the usage of the unsafe lstrcat and lstrcpy functions without any bounds checks.

Vulnerability #1

In PowerEditor/src/WinControls/Grid/BabyGrid.cpp, line 1671:

    lstrcat(buffer, (TCHAR*)lParam);

lstrcat introduces an unbounded stack buffer overflow, by overrunning the 1000 bytes long buffer buffer.

lParam can be controlled and can be of arbitrary length, for example when loading localization strings.

Example of an execution trace triggering the vulnerability:

  1. In ShortcutMapper.cpp, ShortcutMapper::run_dlgProc
  2. In ShortcutMapper.cpp, ShortcutMapper::fillOutBabyGrid
    • generic_string nameStr = nativeLangSpeaker->getShortcutMapperLangStr("ColumnName", TEXT("Name"));
    • _babygrid.setText(0, 1, nameStr.c_str());
  3. In BabyGridWrapper.h, setText
    • ::SendMessage(_hSelf, BGM_SETCELLDATA, reinterpret_cast<WPARAM>(&cell), reinterpret_cast<LPARAM>(text));
  4. In BabyGrid.cpp, GridProc
    • lstrcat(buffer, (TCHAR*)lParam); (line 1669)

Vulnerability #2

If vulnerability #1 is fixed, a second vulnerability will still allow a very similar stack buffer overflow.

In PowerEditor/src/WinControls/Grid/BabyGrid.cpp, line 1308:

    lstrcpy(temptext,text);

lstrcpy introduces an unbounded stack buffer overflow, by overrunning the 1000 bytes long buffer temptext.

text can be controlled and can be of arbitrary length, for example when loading localization strings.

Example of an execution trace triggering the vulnerability:

  1. In ShortcutMapper.cpp, ShortcutMapper::run_dlgProc
  2. In ShortcutMapper.cpp, ShortcutMapper::fillOutBabyGrid
    • generic_string nameStr = nativeLangSpeaker->getShortcutMapperLangStr("ColumnName", TEXT("Name"));
    • _babygrid.setText(0, 1, nameStr.c_str());
  3. In BabyGridWrapper.h, setText
    • ::SendMessage(_hSelf, BGM_SETCELLDATA, reinterpret_cast<WPARAM>(&cell), reinterpret_cast<LPARAM>(text));
  4. In BabyGrid.cpp, GridProc
    • longestline=FindLongestLine(hdc,(TCHAR*)lParam,&size); (line 1726)
  5. In BabyGrid.cpp, FindLongestLine
    • lstrcpy(temptext,text); (line 1306)

Steps To Reproduce:

  1. Install the 32-bit version of Notepad++
  2. Copy nativeLang.xml to the %APPDATA%\Notepad++ folder (or to the Notepad++ installation folder)
  3. Run Notepad++
  4. Open the "Settings" > "Shortcut Mapper" menu

Notepad++ will crash.

Alternative steps

The PoC can be reproduced in the same way on the 64-bit version by using one of the provided .xml files ending with -64 (remember to rename them to nativeLang.xml).

All of the attached files, when renamed to nativeLang.xml and moved to the %APPDATA%\Notepad++ folder, will trigger a crash.

The nativeLang-4 version of the PoC needs an additional step: after opening the Shortcut Mapper, move to the "Plugin" tab.

Suggested fix

  • Add strsafe.h as header

  • In PowerEditor/src/WinControls/Grid/BabyGrid.cpp, line 1671

Diff
-    lstrcat(buffer, (TCHAR*)lParam);
+    StringCchCat(buffer, 1000, (TCHAR*)lParam);
  • In PowerEditor/src/WinControls/Grid/BabyGrid.cpp, line 1308
Diff
-    lstrcpy(temptext,text);
+    StringCchCopy(temptext, 1000, text);

strcat and strcpy are fundamentally unsafe, due to the lack of bounds checking. Consider replacing all occurrences with safer alternatives like StringCchCat and StringCchCopy.

Supporting Material/References:

Debug info of tested executables

The executables were downloaded from the nightly build at https://ci.appveyor.com/project/donho/notepad-plus-plus

Notepad++ v7.6.3   (32-bit)
Build time : Feb 16 2019 - 23:07:35
Path : C:\Users\Pietro\Downloads\npp.7.6.3.bin.minimalist\notepad++.exe
Admin mode : OFF
Local Conf mode : ON
OS : Windows 10 (64-bit)
Plugins : none
Notepad++ v7.6.3   (64-bit)
Build time : Feb 17 2019 - 02:47:42
Path : C:\Users\Pietro\Downloads\npp.7.6.3.bin.minimalist64\notepad++.exe
Admin mode : OFF
Local Conf mode : ON
OS : Windows 10 (64-bit)
Plugins : none

Impact

Any user who is using one of these malicious localization files will experience crashes when using the "Shortcut Mapper" menu.

This may cause:

  • Loss of unsaved data when the program crashes (if the interval between automatic file backups is too long or automatic backups are disabled)
  • No access to the Shortcut Mapper, making it impossible to change shortcuts

Users may be persuaded to install a custom localization file, for instance by looking for a translation for a language that is not supported yet, or by believing that a particular translation is better than the official one.

Moreover, a malicious program running with the user's permission may directly write to %APPDATA% and trigger the vulnerability.

Since this exploit is read from a file and therefore not dynamic, exploitation to code execution looks impossible due to the presence of the stack cookie and ASLR.

The original report as published on HackerOne, by peter_. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

Notepad++ is a Windows text editor. It supports localisation through an optional configuration file called nativeLang.xml, which lets users replace the strings shown in the GUI with translations. The file is documented in the Notepad++ configuration and localisation pages, and the project also publishes a binary translation how-to.

One of the GUI areas that reads strings from this file is the Shortcut Mapper, opened from the "Settings" > "Shortcut Mapper" menu. The Shortcut Mapper is built on a grid control implemented in PowerEditor/src/WinControls/Grid/BabyGrid.cpp. The ShortcutMapper section of nativeLang.xml supplies the column labels for that grid through the name attribute of four child tags:

  • ColumnName
  • ColumnShortcut
  • ColumnCategory
  • ColumnPlugin

Because these strings come from a file the user can drop into %APPDATA%\Notepad++ (or the installation folder), they are attacker-influenced input. The report shows that a very long name attribute for any of those four tags overflows a stack buffer and crashes the program.

Setup

The researcher tested against nightly builds of Notepad++ v7.6.3, both architectures, on Windows 10 (64-bit). The debug information of the tested executables is:

Text
Notepad++ v7.6.3   (32-bit)
Build time : Feb 16 2019 - 23:07:35
Path : C:\Users\[redacted]\Downloads\npp.7.6.3.bin.minimalist\notepad++.exe
Admin mode : OFF
Local Conf mode : ON
OS : Windows 10 (64-bit)
Plugins : none
Text
Notepad++ v7.6.3   (64-bit)
Build time : Feb 17 2019 - 02:47:42
Path : C:\Users\[redacted]\Downloads\npp.7.6.3.bin.minimalist64\notepad++.exe
Admin mode : OFF
Local Conf mode : ON
OS : Windows 10 (64-bit)
Plugins : none

No account or special role is needed. The precondition is simply that a nativeLang.xml file with a malicious name attribute is present in %APPDATA%\Notepad++ or in the Notepad++ installation folder, and that the user opens the Shortcut Mapper.

Finding it

The grid code copies those strings into fixed-size stack buffers using the unsafe lstrcat and lstrcpy functions, with no bounds checks. The buffers are 1000 bytes long. The overflow triggers with:

  • a name with more than ~1000 characters on the 32-bit program
  • a name with more than ~2000 characters on the 64-bit program

Two separate code paths are vulnerable. The second one still overflows even if the first is fixed, so both need attention.

Exploitation

Step 1: Prepare the malicious localisation file

Create a nativeLang.xml whose ShortcutMapper tag contains a child such as ColumnName with a name attribute longer than the threshold for the target architecture. The report refers to attached proofs of concept as examples; the exact XML is not reproduced in the text.

Step 2: Install the file

  1. Install the 32-bit version of Notepad++.
  2. Copy nativeLang.xml to the %APPDATA%\Notepad++ folder (or to the Notepad++ installation folder).
  3. Run Notepad++.
  4. Open the "Settings" > "Shortcut Mapper" menu.

Notepad++ will crash.

Step 3: Reproduce on 64-bit

The same procedure works on the 64-bit version using one of the provided .xml files ending with -64, renamed to nativeLang.xml. All of the attached files, when renamed to nativeLang.xml and moved to %APPDATA%\Notepad++, trigger a crash. The nativeLang-4 proof of concept needs one extra step: after opening the Shortcut Mapper, move to the "Plugin" tab.

Vulnerability #1: lstrcat in GridProc

In PowerEditor/src/WinControls/Grid/BabyGrid.cpp, line 1671:

Text
    lstrcat(buffer, (TCHAR*)lParam);

lstrcat appends lParam to buffer without checking the remaining space, overrunning the 1000-byte stack buffer buffer. lParam is attacker-controlled and can be of arbitrary length, for example when localisation strings are loaded.

The execution trace that reaches this line is:

  1. In ShortcutMapper.cpp, ShortcutMapper::run_dlgProc
  2. In ShortcutMapper.cpp, ShortcutMapper::fillOutBabyGrid
    • generic_string nameStr = nativeLangSpeaker->getShortcutMapperLangStr("ColumnName", TEXT("Name"));
    • _babygrid.setText(0, 1, nameStr.c_str());
  3. In BabyGridWrapper.h, setText
    • ::SendMessage(_hSelf, BGM_SETCELLDATA, reinterpret_cast<WPARAM>(&cell), reinterpret_cast<LPARAM>(text));
  4. In BabyGrid.cpp, GridProc
    • lstrcat(buffer, (TCHAR*)lParam); (line 1669)

The localisation string is fetched by getShortcutMapperLangStr, passed to the grid wrapper's setText, sent as lParam in a BGM_SETCELLDATA message, and finally concatenated into the stack buffer in GridProc.

Vulnerability #2: lstrcpy in FindLongestLine

If vulnerability #1 is fixed, a second vulnerability still allows a very similar stack buffer overflow. In PowerEditor/src/WinControls/Grid/BabyGrid.cpp, line 1308:

Text
    lstrcpy(temptext,text);

lstrcpy copies text into temptext without a bounds check, overrunning the 1000-byte stack buffer temptext. text is attacker-controlled and can be of arbitrary length, for example when localisation strings are loaded.

The execution trace is:

* `_babygrid.setText(0, 1, nameStr.c_str());`
  1. In BabyGridWrapper.h, setText
  2. In BabyGrid.cpp, GridProc
    • longestline=FindLongestLine(hdc,(TCHAR*)lParam,&size); (line 1726)
  3. In BabyGrid.cpp, FindLongestLine
    • lstrcpy(temptext,text); (line 1306)

Here the same message reaches FindLongestLine, which copies the string into temptext before measuring it.

Root cause

The grid control uses lstrcat and lstrcpy, which perform no bounds checking, to place localisation strings into fixed 1000-byte stack buffers. The length of those strings is controlled by the contents of nativeLang.xml, so a long name attribute overruns the buffer. The report notes that strcat and strcpy are fundamentally unsafe for the same reason and recommends replacing all occurrences with safer alternatives.

As for exploitation beyond a crash, the report states that because the input is read from a file and is therefore not dynamic, exploitation to code execution looks impossible due to the presence of the stack cookie and ASLR. Those two mitigations are what stand between the overflow and control flow, according to the report.

Impact

Any user who uses one of these malicious localisation files will experience crashes when using the "Shortcut Mapper" menu. This may cause:

  • loss of unsaved data when the program crashes, if the interval between automatic file backups is too long or automatic backups are disabled
  • no access to the Shortcut Mapper, making it impossible to change shortcuts

Users may be persuaded to install a custom localisation file, for instance by looking for a translation for a language that is not supported yet, or by believing that a particular translation is better than the official one. In addition, a malicious program running with the user's permission may directly write to %APPDATA% and trigger the vulnerability.

The report rates the practical ceiling as a crash: code execution looks impossible because the input is static and the stack cookie and ASLR are present.

Fix

The suggested fix is to add strsafe.h as a header and replace the two unsafe calls with bounded versions.

Diff
-    lstrcat(buffer, (TCHAR*)lParam);
+    StringCchCat(buffer, 1000, (TCHAR*)lParam);
Diff
-    lstrcpy(temptext,text);
+    StringCchCopy(temptext, 1000, text);

The report also recommends replacing all occurrences of strcat and strcpy with safer alternatives such as StringCchCat and StringCchCopy, since the originals lack bounds checking.

  • A positive result is a crash when the corresponding tab or column is rendered.
  • Other tabs of the Shortcut Mapper: the nativeLang-4 proof of concept only crashes after switching to the "Plugin" tab, so test each tab separately. A positive result is a crash on tab switch rather than on dialog open.
  • A positive result is a crash when the affected dialog or control is opened.
  • Both architectures: thresholds differ (about 1000 characters on 32-bit, about 2000 on 64-bit), so test each build separately. A positive result is a crash at the architecture-specific length.

Hunting notes

During recon, look for features that load strings from files the user can drop in, and for C or C++ code that uses lstrcat, lstrcpy, strcat or strcpy on those strings. The signal is a fixed-size stack buffer plus an unbounded copy.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 18 min read.

What happened, in plain words

Notepad++ is a free text editor for Windows, a program people use to write code, notes and documents. Like many programs, it can be translated into other languages. Instead of shipping a separate build for every language, Notepad++ reads an optional file called nativeLang.xml that contains the translated words for everything you see on screen: menu names, button labels, column headings and so on.

That file is just a text file sitting in a folder on your computer. Anyone can create one and give it to you, and you can drop it into the right folder to change the language of your editor. The problem the researcher found is that Notepad++ trusts the contents of that file too much. If one of the translated strings is extremely long, the program copies it into a small, fixed-size area of memory without checking whether it fits. The extra characters spill over into neighbouring memory, a condition called a buffer overflow. The result is that Notepad++ crashes when you open a particular menu, the Shortcut Mapper.

This is a beginner-friendly walkthrough of the whole report: what the product does, what the file looks like, which pieces of code are at fault, how to reproduce the crash, why it matters, and how the researcher suggested fixing it.

Context

What Notepad++ and localisation are

Notepad++ is a Windows text editor. Localisation (often shortened to l10n) is the process of adapting a program to a particular language or region, so that its menus and messages appear in, say, Italian or Japanese instead of English. Notepad++ does this through an optional configuration file called nativeLang.xml. The word "optional" matters: the program works fine without it, and only reads it if it is present.

The file is documented on the Notepad++ configuration and localisation pages, and the project also publishes a binary translation how-to. In other words, this is a supported, user-facing feature, not a hidden back door. The project publishes documentation on creating translation files.

The Shortcut Mapper

One of the screens that reads strings from this file is the Shortcut Mapper, which you open from the "Settings" > "Shortcut Mapper" menu. A shortcut is a key combination such as Ctrl+S that triggers a command. The Shortcut Mapper is a window that lists every command and the keys assigned to it, so you can look up or change shortcuts.

The list inside that window is drawn by a reusable on-screen component called a grid, which is a table of rows and columns. In the Notepad++ source code, this grid is implemented in a file called PowerEditor/src/WinControls/Grid/BabyGrid.cpp. The name "BabyGrid" is just the project's nickname for its grid control.

The ShortcutMapper section of nativeLang.xml supplies the column labels for that grid. It does so through the name attribute of four child tags:

  • ColumnName
  • ColumnShortcut
  • ColumnCategory
  • ColumnPlugin

If you have never seen XML, think of it as a way of writing labelled data using angle brackets. A tag is a labelled container, like <ColumnName ...>, and an attribute is a named value attached to a tag, like name="Name". The four tags above each carry a name attribute whose value is the text shown at the top of a column in the Shortcut Mapper.

Why this file is dangerous input

Because these strings come from a file the user can drop into %APPDATA%\Notepad++ (or into the Notepad++ installation folder), they are attacker-influenced input. %APPDATA% is a per-user folder on Windows where programs store their settings; each user has their own, and programs running as that user can usually write to it. Anything a program reads from a location like that should be treated as untrusted, exactly like text typed into a web form.

The report shows that a very long name attribute for any of those four tags overflows a stack buffer and crashes the program.

Setup

What the researcher tested

The researcher tested against nightly builds of Notepad++ v7.6.3, on both 32-bit and 64-bit architectures, running on Windows 10 (64-bit). A nightly build is an automatically produced version of a program built from the latest source code, usually once a day, rather than an official release. 32-bit and 64-bit refer to how much data the processor handles at once and how much memory a program can address; the same source code is compiled into two different executables, and they can behave differently at the memory level.

The debug information of the tested executables is:

Text
Notepad++ v7.6.3   (32-bit)
Build time : Feb 16 2019 - 23:07:35
Path : C:\Users\[redacted]\Downloads\npp.7.6.3.bin.minimalist\notepad++.exe
Admin mode : OFF
Local Conf mode : ON
OS : Windows 10 (64-bit)
Plugins : none
Text
Notepad++ v7.6.3   (64-bit)
Build time : Feb 17 2019 - 02:47:42
Path : C:\Users\[redacted]\Downloads\npp.7.6.3.bin.minimalist64\notepad++.exe
Admin mode : OFF
Local Conf mode : ON
OS : Windows 10 (64-bit)
Plugins : none

Line by line, these blocks say:

  • Notepad++ v7.6.3 (32-bit) and (64-bit): the version and architecture of the build under test.
  • Build time: when that particular executable was compiled.
  • Path: where the executable sat on the researcher's disk. The user folder name has been removed here because it identifies a private person.
  • Admin mode : OFF: Notepad++ was not running with administrator rights, so it had only the normal permissions of a regular user.
  • Local Conf mode : ON: Notepad++ was configured to keep its settings in the per-user %APPDATA% folder rather than next to the executable.
  • OS: the operating system, Windows 10 in its 64-bit edition.
  • Plugins : none: no add-ons were loaded, so the crash comes from the core program.

What you need to reproduce it

No account or special role is needed. The precondition is simply that a nativeLang.xml file with a malicious name attribute is present in %APPDATA%\Notepad++ or in the Notepad++ installation folder, and that the user opens the Shortcut Mapper. That is the whole attack surface: a file plus a menu click.

Finding it

How the bug was spotted

The grid code copies those strings into fixed-size stack buffers using the unsafe lstrcat and lstrcpy functions, with no bounds checks.

A few terms need unpacking here:

  • A stack buffer is a small reserved area of memory that a function uses for temporary data. The stack is the region of memory where a running program keeps track of which function called which, plus short-lived local variables. A buffer on the stack has a size fixed when the program is compiled.
  • lstrcat and lstrcpy are Windows functions for handling text. lstrcpy copies a string into a destination, and lstrcat appends one string to the end of another. Crucially, neither takes a size limit: they keep copying until they reach the end of the source string, regardless of how much room the destination has.
  • A bounds check is a test that the data will fit before it is copied. Without one, the copy simply keeps writing past the end of the buffer, overwriting whatever happens to be next in memory. That is the overflow.

The buffers in question are 1000 bytes long. The overflow triggers with:

  • a name with more than ~1000 characters on the 32-bit program
  • a name with more than ~2000 characters on the 64-bit program

The report gives the approximate figures rather than an exact boundary.

Two separate code paths are vulnerable. The second one still overflows even if the first is fixed, so both need attention. This is a common theme in real code: fixing one unsafe copy does not make the rest of the program safe.

Exploitation

Step 1: Prepare the malicious localisation file

Create a nativeLang.xml whose ShortcutMapper tag contains a child such as ColumnName with a name attribute longer than the threshold for the target architecture. The report refers to attached proofs of concept as examples; the exact XML is not reproduced in the text.

A proof of concept (PoC) is a small, deliberately harmless demonstration that a bug is real, usually the minimum needed to make the program misbehave. The point of this step is to put an over-long string where the program expects a short column label.

Step 2: Install the file

  1. Install the 32-bit version of Notepad++.
  2. Copy nativeLang.xml to the %APPDATA%\Notepad++ folder (or to the Notepad++ installation folder).
  3. Run Notepad++.
  4. Open the "Settings" > "Shortcut Mapper" menu.

Notepad++ will crash.

Why each step:

  1. The file has to be in a place Notepad++ reads at startup. %APPDATA%\Notepad++ is the per-user settings folder; the installation folder is the alternative location the program also checks.
  2. Opening the Shortcut Mapper is what causes the grid to be filled with the column labels, which is when the over-long string is copied into the small buffer.

Step 3: Reproduce on 64-bit

The same procedure works on the 64-bit version using one of the provided .xml files ending with -64, renamed to nativeLang.xml. All of the attached files, when renamed to nativeLang.xml and moved to %APPDATA%\Notepad++, trigger a crash. The nativeLang-4 proof of concept needs one extra step: after opening the Shortcut Mapper, move to the "Plugin" tab.

When testing a bug like this, you have to click around the affected screen, not just open it.

Vulnerability #1: lstrcat in GridProc

In PowerEditor/src/WinControls/Grid/BabyGrid.cpp, line 1671:

Text
    lstrcat(buffer, (TCHAR*)lParam);

Line by line:

  • lstrcat is the Windows string-append function. It finds the end of the first string and starts writing the second string there.
  • buffer is the destination, a 1000-byte stack buffer.
  • (TCHAR*)lParam is the source string. lParam is a parameter that carries a value supplied by whoever sent the message; the (TCHAR*) part tells the compiler to treat that value as a pointer to text. TCHAR is a character type that adapts to the build's character encoding.

lstrcat appends lParam to buffer without checking the remaining space, overrunning the 1000-byte stack buffer buffer. lParam is attacker-controlled and can be of arbitrary length, for example when localisation strings are loaded.

The execution trace that reaches this line is:

  1. In ShortcutMapper.cpp, ShortcutMapper::run_dlgProc
  2. In ShortcutMapper.cpp, ShortcutMapper::fillOutBabyGrid
    • generic_string nameStr = nativeLangSpeaker->getShortcutMapperLangStr("ColumnName", TEXT("Name"));
    • _babygrid.setText(0, 1, nameStr.c_str());
  3. In BabyGridWrapper.h, setText
    • ::SendMessage(_hSelf, BGM_SETCELLDATA, reinterpret_cast<WPARAM>(&cell), reinterpret_cast<LPARAM>(text));
  4. In BabyGrid.cpp, GridProc
    • lstrcat(buffer, (TCHAR*)lParam); (line 1669)

What this trace means, step by step:

  1. run_dlgProc is the function that handles messages for the Shortcut Mapper window. A message in Windows is how the operating system tells a window that something happened, such as a click or a request to redraw. This is the entry point when the window is being set up.
  2. fillOutBabyGrid is the function that populates the grid. It calls getShortcutMapperLangStr("ColumnName", TEXT("Name")), which looks up the translated text for the ColumnName label and falls back to the English word Name if there is no translation. The result is stored in nameStr. Then _babygrid.setText(0, 1, nameStr.c_str()) asks the grid to put that text in the cell at column 0, row 1. c_str() just hands over the raw characters of the string.
  3. setText in BabyGridWrapper.h is a thin wrapper. It packages the text into a message and sends it to the grid with SendMessage. BGM_SETCELLDATA is the message name meaning "set this cell's data". The reinterpret_cast calls are type conversions that let the text pointer travel through the message's generic parameter slots.
  4. GridProc is the grid's message handler. When it receives BGM_SETCELLDATA, it takes the text out of lParam and appends it to buffer with lstrcat.

So the localisation string is fetched by getShortcutMapperLangStr, passed to the grid wrapper's setText, sent as lParam in a BGM_SETCELLDATA message, and finally concatenated into the stack buffer in GridProc. Every step is ordinary program plumbing; the flaw is only at the last one, where the length is never checked.

Vulnerability #2: lstrcpy in FindLongestLine

If vulnerability #1 is fixed, a second vulnerability still allows a very similar stack buffer overflow. In PowerEditor/src/WinControls/Grid/BabyGrid.cpp, line 1308:

Text
    lstrcpy(temptext,text);

Line by line:

  • lstrcpy is the Windows string-copy function. It copies characters from the source to the destination until it hits the end of the source string.
  • temptext is the destination, a 1000-byte stack buffer.
  • text is the source string, again ultimately derived from the localisation file.

lstrcpy copies text into temptext without a bounds check, overrunning the 1000-byte stack buffer temptext. text is attacker-controlled and can be of arbitrary length, for example when localisation strings are loaded.

The execution trace is:

* `_babygrid.setText(0, 1, nameStr.c_str());`
  1. In BabyGridWrapper.h, setText
  2. In BabyGrid.cpp, GridProc
    • longestline=FindLongestLine(hdc,(TCHAR*)lParam,&size); (line 1726)
  3. In BabyGrid.cpp, FindLongestLine
    • lstrcpy(temptext,text); (line 1306)

Steps 1 to 3 are identical to the first vulnerability: the same translated string travels the same way. The difference is at step 4. Instead of appending the text straight away, GridProc calls FindLongestLine(hdc, (TCHAR*)lParam, &size). The name tells you the purpose: the grid needs to know how wide the text is so it can size the column, and to work that out it has to measure the longest line. hdc is a handle to the drawing context used for measuring text, and &size is where the result is written back.

Step 5 is where it goes wrong. FindLongestLine copies the string into temptext with lstrcpy before measuring it. The copy happens before any length check, so the same over-long string overruns a second 1000-byte buffer. This is why fixing only the first call would not be enough: the text passes through two unsafe copies on its way to being displayed.

Root cause

The grid control uses lstrcat and lstrcpy, which perform no bounds checking, to place localisation strings into fixed 1000-byte stack buffers. The length of those strings is controlled by the contents of nativeLang.xml, so a long name attribute overruns the buffer. The report notes that strcat and strcpy are fundamentally unsafe for the same reason and recommends replacing all occurrences with safer alternatives.

A useful comparison: a fixed-size buffer is like a glass that holds exactly one litre. lstrcpy and lstrcat are like a tap with no shut-off: they keep pouring until the source runs dry, and whatever is on the table gets soaked. A safe copy function is a tap that stops at the rim.

As for exploitation beyond a crash, the report states that because the input is read from a file and is therefore not dynamic, exploitation to code execution looks impossible due to the presence of the stack cookie and ASLR. Those two mitigations are what stand between the overflow and control flow, according to the report.

Two terms there:

  • A stack cookie (also called a canary) is a secret value the compiler places next to the stack buffers. Before a function returns, the program checks that the value is unchanged. An overflow that smashes through the buffer will overwrite the cookie, the check fails, and the program is stopped instead of continuing with corrupted memory.
  • ASLR (Address Space Layout Randomisation) is an operating system feature that loads programs and their libraries at unpredictable memory addresses each time they run. An attacker who wants to redirect execution to their own code needs to know where things are; ASLR makes that guesswork.

"Not dynamic" means the malicious string is fixed in a file before the program runs, rather than being delivered and adjusted interactively while the program is running. That makes it harder to shape the overflow precisely.

Impact

Any user who uses one of these malicious localisation files will experience crashes when using the "Shortcut Mapper" menu. This may cause:

  • loss of unsaved data when the program crashes, if the interval between automatic file backups is too long or automatic backups are disabled
  • no access to the Shortcut Mapper, making it impossible to change shortcuts

Users may be persuaded to install a custom localisation file, for instance by looking for a translation for a language that is not supported yet, or by believing that a particular translation is better than the official one. This is a social angle rather than a technical one: people install language files precisely because they want the program in their own language, and a file that looks like a translation is easy to trust.

In addition, a malicious program running with the user's permission may directly write to %APPDATA% and trigger the vulnerability. In other words, the file does not have to arrive by email or download; any program already running as that user can drop it in place.

The report says code execution looks impossible because the input is static and the stack cookie and ASLR are present. Code execution would mean making the program run the attacker's own instructions, which is far more serious than a crash.

Fix

The suggested fix is to add strsafe.h as a header and replace the two unsafe calls with bounded versions. strsafe.h is a Microsoft header that provides string functions which take an explicit size limit.

Diff
-    lstrcat(buffer, (TCHAR*)lParam);
+    StringCchCat(buffer, 1000, (TCHAR*)lParam);

What changed: lstrcat becomes StringCchCat, and the call now passes 1000, the size of the destination buffer. StringCchCat will not write more than that many characters, so the copy stops at the rim of the glass instead of flooding the table. The Cch in the name stands for "count of characters".

Diff
-    lstrcpy(temptext,text);
+    StringCchCopy(temptext, 1000, text);

What changed: lstrcpy becomes StringCchCopy, again with 1000 as the limit. The copy is capped at the size of temptext.

The report also recommends replacing all occurrences of strcat and strcpy with safer alternatives such as StringCchCat and StringCchCopy, since the originals lack bounds checking. The two lines above are the ones that crash, but the same unsafe pattern elsewhere in the code is a latent version of the same bug.

  • A positive result is a crash when the corresponding tab or column is rendered.
  • Other tabs of the Shortcut Mapper: the nativeLang-4 proof of concept only crashes after switching to the "Plugin" tab, so test each tab separately. A positive result is a crash on tab switch rather than on dialog open.
  • A positive result is a crash when the affected dialog or control is opened.
  • Both architectures: thresholds differ (about 1000 characters on 32-bit, about 2000 on 64-bit), so test each build separately. A positive result is a crash at the architecture-specific length.

Hunting notes

During recon (short for reconnaissance, the phase where you map out what a program does before testing it), look for features that load strings from files the user can drop in, and for C or C++ code that uses lstrcat, lstrcpy, strcat or strcpy on those strings. The signal is a fixed-size stack buffer plus an unbounded copy.

Glossary

  • 32-bit / 64-bit: two ways of compiling a program, differing in how much data the processor handles at once and how much memory the program can address; the same source can produce both builds.
  • ASLR (Address Space Layout Randomisation): an operating system feature that places programs and libraries at unpredictable memory addresses each run, making it harder for an attacker to know where to jump.
  • Attribute: in XML, a named value attached to a tag, such as name="Name".
  • Bounds check: a test performed before copying data to confirm it fits in the destination.
  • Buffer: a reserved area of memory used to hold data temporarily.
  • Buffer overflow: writing more data into a buffer than it can hold, so the extra data spills into neighbouring memory.
  • Code execution: a security failure in which an attacker makes a program run instructions of the attacker's choosing; more serious than a crash.
  • Configuration file: a file that changes a program's settings or appearance without changing the program itself.
  • Crash: an abnormal termination of a program, usually because it tried to use memory in a way the operating system does not allow.
  • c_str(): a C++ method that returns the raw character sequence of a string object.
  • FindLongestLine: the grid function that measures the widest line of text so a column can be sized.
  • Grid: an on-screen table of rows and columns, used here to list shortcuts.
  • hdc: a handle to a Windows drawing context, used when measuring or drawing text.
  • lParam: a generic message parameter in Windows that carries a value supplied by the sender; here it carries a pointer to the text.
  • lstrcat / lstrcpy: Windows functions that append or copy text without any size limit.
  • Localisation (l10n): adapting a program to a particular language or region, for example by translating its menus.
  • Message (Windows): the mechanism by which the operating system tells a window that something happened, such as a click or a request to redraw.
  • Mitigation: a defensive feature that makes a class of attack harder, such as a stack cookie or ASLR.
  • nativeLang.xml: the optional Notepad++ file that supplies translated strings for the interface.
  • Nightly build: an automatically produced version of a program built from the latest source code, usually daily.
  • Notepad++: a free text editor for Windows.
  • %APPDATA%: a per-user Windows folder where programs store settings; each user has their own.
  • Proof of concept (PoC): a small demonstration that a bug is real, usually the minimum needed to make the program misbehave.
  • Recon (reconnaissance): the phase of security testing where you map out what a program does and where its inputs come from.
  • reinterpret_cast: a C++ conversion that reinterprets a value as a different type, used here to pass a text pointer through a generic message parameter.
  • SendMessage: the Windows function used to deliver a message to a window.
  • Shortcut: a key combination, such as Ctrl+S, that triggers a command.
  • Shortcut Mapper: the Notepad++ window that lists commands and their shortcuts and lets you change them.
  • Stack: the region of memory where a running program keeps track of function calls and short-lived local variables.
  • Stack buffer: a fixed-size temporary area of memory allocated on the stack for a function's use.
  • Stack cookie (canary): a secret value placed next to stack buffers and checked before a function returns, so that an overflow is detected and the program stopped.
  • strsafe.h: a Microsoft header providing string functions that take an explicit size limit.
  • StringCchCat / StringCchCopy: bounded versions of append and copy that stop at a given character count.
  • Tag: in XML, a labelled container written with angle brackets, such as <ColumnName>.
  • TCHAR: a character type in Windows code that adapts to the build's character encoding.
  • XML: a text format for labelled, structured data using tags and attributes.

More by peter_

View all

1 more disclosed report, best first.

More from Notepad++

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.