[PATCH setup] Don't write garbage into the "extrakeys" user setting

Ken Brown kbrown@cornell.edu
Mon Nov 27 21:36:00 GMT 2017


The ExtraKeysSetting destructor called UserSettings::set() on a string
that was terminated by LF instead of NUL.  This led to garbage at the
end of the "extrakeys" setting that was written into setup.rc.  Fix
this by replacing the final LF by NUL before calling set().
---
 KeysSetting.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/KeysSetting.cc b/KeysSetting.cc
index a21c3c4..19c6df3 100644
--- a/KeysSetting.cc
+++ b/KeysSetting.cc
@@ -46,7 +46,11 @@ ExtraKeysSetting::ExtraKeysSetting ():
 ExtraKeysSetting::~ExtraKeysSetting ()
 {
   if (keybuffer)
-    UserSettings::instance().set ("extrakeys", keybuffer);
+    {
+      // Replace final LF with NUL.
+      keybuffer[bufsize - 1] = '\0';
+      UserSettings::instance().set ("extrakeys", keybuffer);
+    }
 }
 
 void
-- 
2.15.0



More information about the Cygwin-apps mailing list