8c41b40
From 15ed31a1ed2f3ef45a620917dd97f828e4fd33be Mon Sep 17 00:00:00 2001
bacecff
From: Fabrice Bellet <fabrice@bellet.info>
4115109
Date: Sun, 22 Sep 2013 11:56:12 +0200
8c41b40
Subject: [PATCH] check to be sure that %n is not being set as format type
bacecff
 (CVE-2012-2090)
bacecff
bacecff
---
bacecff
 simgear/scene/model/SGText.cxx | 10 ++++++++++
bacecff
 1 file changed, 10 insertions(+)
bacecff
bacecff
diff --git a/simgear/scene/model/SGText.cxx b/simgear/scene/model/SGText.cxx
8c41b40
index 1da6c57..3093d82 100644
bacecff
--- a/simgear/scene/model/SGText.cxx
bacecff
+++ b/simgear/scene/model/SGText.cxx
8c41b40
@@ -68,6 +68,16 @@ void SGText::UpdateCallback::operator()(osg::Node * node, osg::NodeVisitor *nv )
17ef0f6
   // FIXME:
17ef0f6
   // hopefully the users never specifies bad formats here
17ef0f6
   // this should better be something more robust
17ef0f6
+  // It is never safe for format.c_str to be %n.
17ef0f6
+  string unsafe ("%n");
17ef0f6
+  size_t found;
17ef0f6
+
17ef0f6
+  found=format.find(unsafe);
17ef0f6
+  if (found!=string::npos) {
17ef0f6
+     SG_LOG(SG_GENERAL, SG_ALERT, "format type contained %n, but this is unsafe, reverting to %s");
17ef0f6
+     format = "%s";
17ef0f6
+  }
17ef0f6
+
17ef0f6
   char buf[256];
17ef0f6
   if( numeric ) {
17ef0f6
     double d = property->getDoubleValue() * scale + offset;
bacecff
-- 
8c41b40
1.9.3
bacecff