Re: Potential bug in Mork.cs



On Thursday 14 September 2006 19:41, Joe Shaw wrote:
> The patch is obviously right from a functionality standpoint, but is
> there a possibility that content [position + 1] will go out of bounds
> and cause an exception (ie, a single / at the end of the buffer)?
Thanks for noting, the "bugfix" was a quicky, I didn't check the surrounding 
code, and assumed it's fine as the author accessed content[position+2] a few 
lines below. But the code as it currently is potentially causes several C# 
equivalents of segfaults (Index out of bounds exception?). A bugfix is 
attached (neither tested nor compiled, but it looks good ;-) ). A review of 
the whole Mork code is probably a good idea, because as everybody knows more 
bugs are to be found in code you have already found bugs in.

Regards,
	Florian
-- 
Florian Hackenberger
student @
University of Technology
Graz, Austria
florian hackenberger at
www.hackenberger.at
--- Util.old/Mork.cs	2006-09-16 18:14:52.000000000 +0200
+++ Util/Mork.cs	2006-09-16 18:16:09.000000000 +0200
@@ -95,24 +95,25 @@
 
 			while (++position != content.Length) {
 				
-				if (content [position].Equals ('/') && content [position].Equals ('/'))
+				if (content[position].Equals ('/') && position+1 < content.Length && content[position+1].Equals ('/')) {
 					// Ignore comments
 					position = content.IndexOf ('\n', position);
-				else if (content [position].Equals ('<') && content [position+2].Equals ('<'))
+				}else if (content[position].Equals ('<') && position+2 < content.Length && content[position+2].Equals ('<')) {
 					// Parse metadict information
 					ParseMetaDict (Read (content, ref position, "<(", ")>"));
-				else if (content [position].Equals ('<'))
+				}else if (content[position].Equals ('<')) {
 					// Parse dict information
 					ParseDict (Read (content, ref position, "<(", ")>"));
-				else if (content [position].Equals ('{')) {
+				}else if (content[position].Equals ('{')) {
 					// Parse table information
 					ParseTable (Read (content, ref position, "{", "}"));
-				 }else if (content [position].Equals ('[')) 
+				}else if (content[position].Equals ('[')) {
 					// Parse rows
 					ParseRows (Read (content, ref position, "[", "]"), null, null);
-				else if (content [position].Equals ('@') && content [position+1].Equals ('$'))
+				}else if (content[position].Equals ('@') && position+1 < content.Length && content[position+1].Equals ('$')) {
 					// Parse groups
 					ParseGroups (Read (content, ref position, "@$${", "@$$}"));
+				}
 			}
 		}
 		


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