hanigamal / ospy

Automatically exported from code.google.com/p/ospy
0 stars 0 forks source link

Unhandled ConstraintException Exception when "Create softrule from entry ..." #4

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. sniff some packets
2. right click on grid -> "Create softrule from entry ..." a few times
3. delete a softrule from the middle of softrules (for example delete 
Rule2 while you have 3 rules)
4. right click on grid -> "Create softrule from entry ..." again

What is the expected output? What do you see instead?
A new soft rule with proper name is expected. the program crashes istead.

Suggestion:
public void AddRule(string processName, string functionName,
                            uint returnAddress,
                            string localAddress, ushort localPort,
                            string remoteAddress, ushort remotePort)
        {
            DataTable tbl = softwallDataSet.Tables[0];
            DataRow row = tbl.NewRow();

            string name = String.Format("Rule{0:00}", 
ruleListView.Items.Count + 1);                      

            row["Name"] = name;
            row["ProcessName"] = processName;
            row["FunctionName"] = functionName;

            if (returnAddress != 0)
                row["ReturnAddress"] = returnAddress;

            if (localAddress != null)
                row["LocalAddress"] = localAddress;
            if (localPort > 0)
                row["LocalPort"] = localPort;

            if (remoteAddress != null)
                row["RemoteAddress"] = remoteAddress;
            if (remotePort > 0)
                row["RemotePort"] = remotePort;

            row["ReturnValue"] = DEFAULT_RETURN_VALUE;
            row["LastError"] = DEFAULT_LAST_ERROR;

            try
            {
                tbl.Rows.Add(row);
            }
            catch (ConstraintException)
            {                
                for (int i = 1; i <= ruleListView.Items.Count; i++ )
                {
                    string temp = String.Format("Rule{0:00}", i);
                    bool tempExists = false;
                    foreach(DataRow tempRow in tbl.Rows)
                    {
                        if(tempRow["Name"].Equals(temp))
                        {
                            tempExists = true;
                            break;
                        }
                    }
                    if(!tempExists)
                    {
                        name = temp;
                        row["Name"] = name;
                        tbl.Rows.Add(row);                        
                        break;
                    }                    
                }
            }
            ruleListView.Items.Add(name);

            ruleListView.SelectedIndices.Clear();
            ruleListView.SelectedIndices.Add(ruleListView.Items.Count - 1);
        }

Original issue reported on code.google.com by firouzab...@gmail.com on 4 Jan 2007 at 8:21

GoogleCodeExporter commented 8 years ago
Thanks for the report and suggested fix. Unfortunately oSpy1 is unmaintained 
these
days, and I'm trying to spend the little time I've got on oSpy2. Feel free to 
join in
on development, I'm
mostly alone in development these days so I tend to prioritize features that I 
need
the most myself (as my time is very limited).

Original comment by ole...@gmail.com on 4 Aug 2007 at 12:02

GoogleCodeExporter commented 8 years ago
As I commented on the other issue I'm about to release 1.10.0 with lots of 
changes, 
including a fix for this issue -- finally! :)

Please file new bugs if you find any new issues with 1.10.0 -- it should 
hopefully suck 
a lot less than the previous releases. :)

Original comment by ole...@gmail.com on 20 Aug 2009 at 12:05