[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

gEDA-cvs: pcb.git: branch: master updated (dbf835c02cda1d16157a83f8c1b9b1da2a05400a)



The branch, master has been updated
       via  dbf835c02cda1d16157a83f8c1b9b1da2a05400a (commit)
      from  02fa7cf6646ad4f16383c91e53784986f4d8d15d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


=========
 Summary
=========

 src/rats.c |   56 +++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 35 insertions(+), 21 deletions(-)


=================
 Commit Messages
=================

commit dbf835c02cda1d16157a83f8c1b9b1da2a05400a
Author: Seb James <seb@xxxxxxxxxxxx>
Commit: DJ Delorie <dj@xxxxxxxxxxx>

    SF patch 1674895:
    
    This crash occurs in rats.c, around line 610 in the function
    DrawShortestRats() where CreateNewRat() is called with some arguments
    which don't exist.
    
    It occurred for me when I tried to "optimize rats nest" on an invalid
    design.
    
    There's no check in DrawShortestRats() that the firstposition and
    secondposition pointers are not NULL.
    firstposition->X (and Y) and secondposition->X (and Y) are passed as
    arguments to CreateNewRat(). It is possible in some cases that
    firstposition and secondposition are not reset from 0 in the code
    preceding the call to CreateNewRat(). In these cases a segfault will
    occur.

:100644 100644 3c5ede1... 8dc513c... M	src/rats.c

=========
 Changes
=========

commit dbf835c02cda1d16157a83f8c1b9b1da2a05400a
Author: Seb James <seb@xxxxxxxxxxxx>
Commit: DJ Delorie <dj@xxxxxxxxxxx>

    SF patch 1674895:
    
    This crash occurs in rats.c, around line 610 in the function
    DrawShortestRats() where CreateNewRat() is called with some arguments
    which don't exist.
    
    It occurred for me when I tried to "optimize rats nest" on an invalid
    design.
    
    There's no check in DrawShortestRats() that the firstposition and
    secondposition pointers are not NULL.
    firstposition->X (and Y) and secondposition->X (and Y) are passed as
    arguments to CreateNewRat(). It is possible in some cases that
    firstposition and secondposition are not reset from 0 in the code
    preceding the call to CreateNewRat(). In these cases a segfault will
    occur.

diff --git a/src/rats.c b/src/rats.c
index 3c5ede1..8dc513c 100644
--- a/src/rats.c
+++ b/src/rats.c
@@ -341,6 +341,7 @@ TransferNet (NetListTypePtr Netl, NetTypePtr SourceNet, NetTypePtr DestNet)
 {
   ConnectionTypePtr conn;
 
+  /* It would be worth checking if SourceNet is NULL here to avoid a segfault. Seb James. */
   CONNECTION_LOOP (SourceNet);
   {
     conn = GetConnectionMemory (DestNet);
@@ -562,9 +563,13 @@ DrawShortestRats (NetListTypePtr Netl, void (*funcp) ())
   register ConnectionTypePtr conn1, conn2, firstpoint, secondpoint;
   PolygonTypePtr polygon;
   bool changed = false;
+  bool havepoints = false;
   Cardinal n, m, j;
   NetTypePtr next, subnet, theSubnet = NULL;
 
+  if (Netl->NetN < 2)
+    return false;
+
   /*
    * Everything inside the NetList Netl should be connected together.
    * Each Net in Netl is a group of Connections which are already
@@ -575,9 +580,10 @@ DrawShortestRats (NetListTypePtr Netl, void (*funcp) ())
    * one big blob.
    */
   distance = 0.0;
-  while (Netl->NetN > 1)
+  do
     {
       firstpoint = secondpoint = NULL;
+      havepoints = false;
       subnet = &Netl->Net[0];
       for (j = 1; j < Netl->NetN; j++)
 	{
@@ -604,6 +610,7 @@ DrawShortestRats (NetListTypePtr Netl, void (*funcp) ())
 		      firstpoint = conn2;
 		      secondpoint = conn1;
 		      theSubnet = next;
+		      havepoints = true;
 		    }
 		  else if (conn2->type == POLYGON_TYPE &&
 		      (polygon = (PolygonTypePtr)conn2->ptr2) &&
@@ -615,6 +622,7 @@ DrawShortestRats (NetListTypePtr Netl, void (*funcp) ())
 		      firstpoint = conn1;
 		      secondpoint = conn2;
 		      theSubnet = next;
+		      havepoints = true;
 		    }
 		  else if ((temp = SQUARE (conn1->X - conn2->X) +
 		       SQUARE (conn1->Y - conn2->Y)) < distance || !firstpoint)
@@ -623,35 +631,41 @@ DrawShortestRats (NetListTypePtr Netl, void (*funcp) ())
 		      firstpoint = conn1;
 		      secondpoint = conn2;
 		      theSubnet = next;
+		      havepoints = true;
 		    }
 		}
 	    }
 	}
-      if (funcp)
-	{
-	  (*funcp) (firstpoint, secondpoint, subnet->Style);
-	}
-      else
+
+      if (havepoints)
 	{
-	  /* found the shortest distance subnet, draw the rat */
-	  if ((line = CreateNewRat (PCB->Data,
-				    firstpoint->X, firstpoint->Y,
-				    secondpoint->X, secondpoint->Y,
-				    firstpoint->group, secondpoint->group,
-				    Settings.RatThickness,
-				    NoFlags ())) != NULL)
+	  if (funcp)
+	    {
+	      (*funcp) (firstpoint, secondpoint, subnet->Style);
+	    }
+	  else
 	    {
-	      if (distance == 0)
-		SET_FLAG (VIAFLAG, line);
-	      AddObjectToCreateUndoList (RATLINE_TYPE, line, line, line);
-	      DrawRat (line, 0);
-	      changed = true;
+	      /* found the shortest distance subnet, draw the rat */
+	      if ((line = CreateNewRat (PCB->Data,
+					firstpoint->X, firstpoint->Y,
+					secondpoint->X, secondpoint->Y,
+					firstpoint->group, secondpoint->group,
+					Settings.RatThickness,
+					NoFlags ())) != NULL)
+		{
+		  if (distance == 0)
+		    SET_FLAG (VIAFLAG, line);
+		  AddObjectToCreateUndoList (RATLINE_TYPE, line, line, line);
+		  DrawRat (line, 0);
+		  changed = true;
+		}
 	    }
+
+	  /* copy theSubnet into the current subnet */
+	  TransferNet (Netl, theSubnet, subnet);
 	}
+    } while (Netl->NetN > 1 && havepoints);
 
-      /* copy theSubnet into the current subnet */
-      TransferNet (Netl, theSubnet, subnet);
-    }
   /* presently nothing to do with the new subnet */
   /* so we throw it away and free the space */
   FreeNetMemory (&Netl->Net[--(Netl->NetN)]);




_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs