|
| 1 | +Description: Fix CVE-2025-60751: stack-based buffer overflow in DMS.cpp |
| 2 | + Fix buffer overflow in DMS::InternalDecode function by adding bounds checking |
| 3 | + for the number of components in DMS (degrees/minutes/seconds) string parsing. |
| 4 | + . |
| 5 | + The vulnerability existed because the code used a fixed-size array (3 elements) |
| 6 | + for ipieces and fpieces but didn't properly validate that the input string |
| 7 | + didn't contain more than 3 components, potentially leading to a buffer overflow. |
| 8 | +Author: Charles Karney <karney@alum.mit.edu> |
| 9 | +Origin: upstream, https://github.com/geographiclib/geographiclib/commit/aec521dff5ec0757cdefa018b152fffcfbca3eac |
| 10 | +Bug: https://security-tracker.debian.org/tracker/CVE-2025-60751 |
| 11 | +Forwarded: not-needed |
| 12 | +--- |
| 13 | + src/DMS.cpp | 14 ++++++++++---- |
| 14 | + 1 file changed, 10 insertions(+), 4 deletions(-) |
| 15 | + |
| 16 | +diff --git a/src/DMS.cpp b/src/DMS.cpp |
| 17 | +index 8a30340f..d9c552a1 100644 |
| 18 | +--- a/src/DMS.cpp |
| 19 | ++++ b/src/DMS.cpp |
| 20 | +@@ -190,6 +190,7 @@ namespace GeographicLib { |
| 21 | + } |
| 22 | + |
| 23 | + Math::real DMS::InternalDecode(const string& dmsa, flag& ind) { |
| 24 | ++ const int maxcomponents = 3; |
| 25 | + string errormsg; |
| 26 | + do { // Executed once (provides the ability to break) |
| 27 | + int sign = 1; |
| 28 | +@@ -232,8 +233,8 @@ namespace GeographicLib { |
| 29 | + errormsg = "Empty or incomplete DMS string " + dmsa; |
| 30 | + break; |
| 31 | + } |
| 32 | +- real ipieces[] = {0, 0, 0}; |
| 33 | +- real fpieces[] = {0, 0, 0}; |
| 34 | ++ real ipieces[maxcomponents] = {0, 0, 0}; |
| 35 | ++ real fpieces[maxcomponents] = {0, 0, 0}; |
| 36 | + unsigned npiece = 0; |
| 37 | + real icurrent = 0; |
| 38 | + real fcurrent = 0; |
| 39 | +@@ -259,7 +260,7 @@ namespace GeographicLib { |
| 40 | + pointseen = true; |
| 41 | + digcount = 1; |
| 42 | + } else if ((k = Utility::lookup(dmsindicators_, x)) >= 0) { |
| 43 | +- if (k >= 3) { |
| 44 | ++ if (k >= maxcomponents) { |
| 45 | + if (p == end) { |
| 46 | + errormsg = "Illegal for : to appear at the end of " + |
| 47 | + dmsa.substr(beg, end - beg); |
| 48 | +@@ -292,6 +293,11 @@ namespace GeographicLib { |
| 49 | + fpieces[k] = icurrent + fcurrent; |
| 50 | + if (p < end) { |
| 51 | + npiece = k + 1; |
| 52 | ++ if (npiece >= maxcomponents) { |
| 53 | ++ errormsg = "More than 3 DMS components in " |
| 54 | ++ + dmsa.substr(beg, end - beg); |
| 55 | ++ break; |
| 56 | ++ } |
| 57 | + icurrent = fcurrent = 0; |
| 58 | + ncurrent = digcount = intcount = 0; |
| 59 | + } |
| 60 | +@@ -308,7 +314,7 @@ namespace GeographicLib { |
| 61 | + if (!errormsg.empty()) |
| 62 | + break; |
| 63 | + if (Utility::lookup(dmsindicators_, dmsa[p - 1]) < 0) { |
| 64 | +- if (npiece >= 3) { |
| 65 | ++ if (npiece >= maxcomponents) { |
| 66 | + errormsg = "Extra text following seconds in DMS string " |
| 67 | + + dmsa.substr(beg, end - beg); |
| 68 | + break; |
0 commit comments