Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: SPF: Devel

pypolicyd-spf crashing with IndexError exception

 

 

SPF devel RSS feed   Index | Next | Previous | View Threaded


mle+tools at mega-nerd

Oct 19, 2009, 8:54 PM

Post #1 of 4 (2753 views)
Permalink
pypolicyd-spf crashing with IndexError exception

Hi,

I raised the following bug in the Ubuntu bug tracker:

https://bugs.launchpad.net/ubuntu/+source/pypolicyd-spf/+bug/455991

The problem is code like:

sender_domain = string.split(sender, '@', 1)
if spf.domainmatch(reject_domain_list, sender_domain[1]):

If sender has no '@' character, sender_domain ends up as a single
element list and trying to index it by [1] results in an IndexError
exception.

A robust solution to this (available for python >= 2.5) is:

sender_domain = sender.partition ('@')[2]
if spf.domainmatch(reject_domain_list, sender_domain):

The parition method applied to the sender string is guaranteed to return
a 3 element tuple of which the [2] indexing grabs the last element.

Cheers,
Erik
--
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/


-------------------------------------------
Sender Policy Framework: http://www.openspf.org [http://www.openspf.org]
Modify Your Subscription: http://www.listbox.com/member/ [http://www.listbox.com/member/]

Archives: https://www.listbox.com/member/archive/1007/=now
RSS Feed: https://www.listbox.com/member/archive/rss/1007/
Powered by Listbox: http://www.listbox.com


clements at brinckerhoff

Oct 20, 2009, 10:18 AM

Post #2 of 4 (2644 views)
Permalink
Re: pypolicyd-spf crashing with IndexError exception [In reply to]

On Oct 19, 2009, at 8:54 PM, Erik de Castro Lopo wrote:

> Hi,
>
> I raised the following bug in the Ubuntu bug tracker:
>
> https://bugs.launchpad.net/ubuntu/+source/pypolicyd-spf/+bug/455991
>
> The problem is code like:
>
> sender_domain = string.split(sender, '@', 1)
> if spf.domainmatch(reject_domain_list, sender_domain[1]):
>
> If sender has no '@' character, sender_domain ends up as a single
> element list and trying to index it by [1] results in an IndexError
> exception.
>
> A robust solution to this (available for python >= 2.5) is:
>
> sender_domain = sender.partition ('@')[2]
> if spf.domainmatch(reject_domain_list, sender_domain):
>
> The parition method applied to the sender string is guaranteed to
> return
> a 3 element tuple of which the [2] indexing grabs the last element.

Yep; I reported this problem back in April:

http://snurl.com/sm6pr

My solution was just to grab the last element of the list. This will
differ only when there are multiple '@'s; I'm guessing this isn't a
problem.

John Clements









-------------------------------------------
Sender Policy Framework: http://www.openspf.org [http://www.openspf.org]
Modify Your Subscription: http://www.listbox.com/member/ [http://www.listbox.com/member/]

Archives: https://www.listbox.com/member/archive/1007/=now
RSS Feed: https://www.listbox.com/member/archive/rss/1007/
Powered by Listbox: http://www.listbox.com
Attachments: smime.p7s (2.43 KB)


scott at kitterman

Oct 20, 2009, 10:39 AM

Post #3 of 4 (2659 views)
Permalink
Re: pypolicyd-spf crashing with IndexError exception [In reply to]

On Tue, 20 Oct 2009 10:18:24 -0700 John Clements
<clements [at] brinckerhoff> wrote:
>
>On Oct 19, 2009, at 8:54 PM, Erik de Castro Lopo wrote:
>
>> Hi,
>>
>> I raised the following bug in the Ubuntu bug tracker:
>>
>> https://bugs.launchpad.net/ubuntu/+source/pypolicyd-spf/+bug/455991
>>
>> The problem is code like:
>>
>> sender_domain = string.split(sender, '@', 1)
>> if spf.domainmatch(reject_domain_list, sender_domain[1]):
>>
>> If sender has no '@' character, sender_domain ends up as a single
>> element list and trying to index it by [1] results in an IndexError
>> exception.
>>
>> A robust solution to this (available for python >= 2.5) is:
>>
>> sender_domain = sender.partition ('@')[2]
>> if spf.domainmatch(reject_domain_list, sender_domain):
>>
>> The parition method applied to the sender string is guaranteed to
>> return
>> a 3 element tuple of which the [2] indexing grabs the last element.
>
>Yep; I reported this problem back in April:
>
>http://snurl.com/sm6pr
>
>My solution was just to grab the last element of the list. This will
>differ only when there are multiple '@'s; I'm guessing this isn't a
>problem.

In practice, it shouldn't be. Sorry for the delay. This is still on my
TODO.

Scott K


-------------------------------------------
Sender Policy Framework: http://www.openspf.org [http://www.openspf.org]
Modify Your Subscription: http://www.listbox.com/member/ [http://www.listbox.com/member/]

Archives: https://www.listbox.com/member/archive/1007/=now
RSS Feed: https://www.listbox.com/member/archive/rss/1007/
Powered by Listbox: http://www.listbox.com


scott at kitterman

Nov 2, 2009, 9:11 PM

Post #4 of 4 (2642 views)
Permalink
Re: pypolicyd-spf crashing with IndexError exception [In reply to]

I released 0.7.2 with this fixed. It is also fixed in a patch in the most
recend Ubuntu release. It'll be uploaded to Debian shortly.

Thanks for the patches,

Scott K


-------------------------------------------
Sender Policy Framework: http://www.openspf.org [http://www.openspf.org]
Modify Your Subscription: http://www.listbox.com/member/ [http://www.listbox.com/member/]

Archives: https://www.listbox.com/member/archive/1007/=now
RSS Feed: https://www.listbox.com/member/archive/rss/1007/
Powered by Listbox: http://www.listbox.com

SPF devel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.