From bf95753d6533a66f45cc779db8d78f3d46e3a1fa Mon Sep 17 00:00:00 2001 From: Rob Taylor Date: Sat, 26 Aug 2023 15:07:13 +0100 Subject: [PATCH] Fix def error handling for buffer overflow --- lefdef/src/def/def/defiNet.cpp | 100 ++++++++++++++++----------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/lefdef/src/def/def/defiNet.cpp b/lefdef/src/def/def/defiNet.cpp index d50c6b05..4402b4d1 100644 --- a/lefdef/src/def/def/defiNet.cpp +++ b/lefdef/src/def/def/defiNet.cpp @@ -1213,10 +1213,10 @@ void defiNet::changeNetName(const char* name) { void defiNet::changeInstance(const char* instance, int index) { int len; - char errMsg[128]; + char errMsg[256]; if ((index < 0) || (index > numPins_)) { - sprintf (errMsg, "ERROR (DEFPARS-6083): The index number %d specified for the NET INSTANCE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6083): The index number %d specified for the NET INSTANCE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numPins_); defiError(0, 6083, errMsg, defData); } @@ -1231,10 +1231,10 @@ void defiNet::changeInstance(const char* instance, int index) { void defiNet::changePin(const char* pin, int index) { int len; - char errMsg[128]; + char errMsg[256]; if ((index < 0) || (index > numPins_)) { - sprintf (errMsg, "ERROR (DEFPARS-6084): The index number %d specified for the NET PIN is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6084): The index number %d specified for the NET PIN is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numPins_); defiError(0, 6084, errMsg, defData); } @@ -2517,9 +2517,9 @@ int defiNet::numPolygons() const { // 5.6 const char* defiNet::polygonName(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numPolys_) { - sprintf (errMsg, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numPolys_); defiError(0, 6085, errMsg, defData); return 0; @@ -2528,9 +2528,9 @@ const char* defiNet::polygonName(int index) const { } const char* defiNet::polyRouteStatus(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numPolys_) { - sprintf (errMsg, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numPolys_); defiError(0, 6085, errMsg, defData); return 0; @@ -2539,9 +2539,9 @@ const char* defiNet::polyRouteStatus(int index) const { } const char* defiNet::polyRouteStatusShieldName(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numPolys_) { - sprintf (errMsg, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numPolys_); defiError(0, 6085, errMsg, defData); return 0; @@ -2550,9 +2550,9 @@ const char* defiNet::polyRouteStatusShieldName(int index) const { } const char* defiNet::polyShapeType(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numPolys_) { - sprintf (errMsg, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numPolys_); defiError(0, 6085, errMsg, defData); return 0; @@ -2561,9 +2561,9 @@ const char* defiNet::polyShapeType(int index) const { } int defiNet::polyMask(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numPolys_) { - sprintf (errMsg, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numPolys_); defiError(0, 6085, errMsg, defData); return 0; @@ -2667,9 +2667,9 @@ int defiNet::numRectangles() const { // 5.6 const char* defiNet::rectName(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numRects_) { - sprintf (errMsg, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numRects_); defiError(0, 6086, errMsg, defData); return 0; @@ -2678,9 +2678,9 @@ const char* defiNet::rectName(int index) const { } const char* defiNet::rectRouteStatus(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numRects_) { - sprintf (errMsg, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numRects_); defiError(0, 6086, errMsg, defData); return 0; @@ -2689,9 +2689,9 @@ const char* defiNet::rectRouteStatus(int index) const { } const char* defiNet::rectRouteStatusShieldName(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numRects_) { - sprintf (errMsg, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numRects_); defiError(0, 6086, errMsg, defData); return 0; @@ -2700,9 +2700,9 @@ const char* defiNet::rectRouteStatusShieldName(int index) const { } const char* defiNet::rectShapeType(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numRects_) { - sprintf (errMsg, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numRects_); defiError(0, 6086, errMsg, defData); return 0; @@ -2712,9 +2712,9 @@ const char* defiNet::rectShapeType(int index) const { // 5.6 int defiNet::xl(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index >= numRects_) { - sprintf (errMsg, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numRects_); defiError(0, 6086, errMsg, defData); return 0; @@ -2724,9 +2724,9 @@ int defiNet::xl(int index) const { // 5.6 int defiNet::yl(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index >= numRects_) { - sprintf (errMsg, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numRects_); defiError(0, 6086, errMsg, defData); return 0; @@ -2736,9 +2736,9 @@ int defiNet::yl(int index) const { // 5.6 int defiNet::xh(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index >= numRects_) { - sprintf (errMsg, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numRects_); defiError(0, 6086, errMsg, defData); return 0; @@ -2748,9 +2748,9 @@ int defiNet::xh(int index) const { // 5.6 int defiNet::yh(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index >= numRects_) { - sprintf (errMsg, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numRects_); defiError(0, 6086, errMsg, defData); return 0; @@ -2759,9 +2759,9 @@ int defiNet::yh(int index) const { } int defiNet::rectMask(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index >= numRects_) { - sprintf (errMsg, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6086): The index number %d specified for the NET RECTANGLE is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numRects_); defiError(0, 6086, errMsg, defData); return 0; @@ -2857,9 +2857,9 @@ int defiNet::numViaSpecs() const { } const char* defiNet::viaName(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numPts_) { - sprintf (errMsg, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numPts_); defiError(0, 6085, errMsg, defData); return 0; @@ -2868,9 +2868,9 @@ const char* defiNet::viaName(int index) const { } const char* defiNet::viaRouteStatus(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numPts_) { - sprintf (errMsg, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numPts_); defiError(0, 6085, errMsg, defData); return 0; @@ -2879,9 +2879,9 @@ const char* defiNet::viaRouteStatus(int index) const { } const char* defiNet::viaRouteStatusShieldName(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numPts_) { - sprintf (errMsg, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numPts_); defiError(0, 6085, errMsg, defData); return 0; @@ -2890,9 +2890,9 @@ const char* defiNet::viaRouteStatusShieldName(int index) const { } const char* defiNet::viaShapeType(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numPts_) { - sprintf (errMsg, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numPts_); defiError(0, 6085, errMsg, defData); return 0; @@ -2901,9 +2901,9 @@ const char* defiNet::viaShapeType(int index) const { } const int defiNet::viaOrient(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numPts_) { - sprintf (errMsg, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numPts_); defiError(0, 6085, errMsg, defData); return 0; @@ -2912,10 +2912,10 @@ const int defiNet::viaOrient(int index) const { } const char* defiNet::viaOrientStr(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numPts_) { - sprintf (errMsg, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numPts_); defiError(0, 6085, errMsg, defData); return 0; @@ -2924,9 +2924,9 @@ const char* defiNet::viaOrientStr(int index) const { } const int defiNet::topMaskNum(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numPts_) { - sprintf (errMsg, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numPts_); defiError(0, 6085, errMsg, defData); return 0; @@ -2936,9 +2936,9 @@ const int defiNet::topMaskNum(int index) const { } const int defiNet::cutMaskNum(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numPts_) { - sprintf (errMsg, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numPts_); defiError(0, 6085, errMsg, defData); return 0; @@ -2948,9 +2948,9 @@ const int defiNet::cutMaskNum(int index) const { } const int defiNet::bottomMaskNum(int index) const { - char errMsg[128]; + char errMsg[256]; if (index < 0 || index > numPts_) { - sprintf (errMsg, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", + snprintf (errMsg, 256, "ERROR (DEFPARS-6085): The index number %d specified for the NET POLYGON is invalid.\nValid index is from 0 to %d. Specify a valid index number and then try again.", index, numPts_); defiError(0, 6085, errMsg, defData); return 0;