ElkArte Community

Title: Undefined offset: 1
Post by: radu81 on July 15, 2015, 05:39:17 am
In a month a I got about 170 pages of errors in my Error Log.
Code: [Select]
Guest 
Type of error: Not specified
8: Undefined offset: 1
http://www.skodaclub.it/index.php?type=rss;action=.xml
File: /.../sources/QueryString.php
Row: 225

How could I solve this? Thank you.

I am using Elkarte 1.0.4 and PHP 5.6.
Title: Re: Undefined offset: 1
Post by: emanuele on July 15, 2015, 06:50:18 am
Would you mind do some test? O:-)

In QueryString.php, find:
Code: [Select]
		// Looks like this is an IPv4 address
if (strpos($part[1][1], '.') !== false)
{
and replace it with:
Code: [Select]
		if (!isset($part[1][1]))
log_error('Original address: ' . $addr);

// Looks like this is an IPv4 address
if (!isset($part[1][1]) || strpos($part[1][1], '.') !== false)
{

Then cleanup the error log and keep a eye on it to see if any error that looks like:
Code: [Select]
Original address: 123.123.123
appears. :D
Title: Re: Undefined offset: 1
Post by: radu81 on July 15, 2015, 12:06:28 pm
Thanks for your help. I did, but here is what I get now:
Title: Re: Undefined offset: 1
Post by: emanuele on July 15, 2015, 02:45:45 pm
Ops, wrong logic... O:-)
Sorry! :-[

Now, let's revert to something that should work, so:
Code: [Select]
		if (!isset($part[1][1]))
log_error('Original address: ' . $addr);

// Looks like this is an IPv4 address
if (!isset($part[1][1]) || strpos($part[1][1], '.') !== false)
{
becomes:
Code: [Select]
		// Looks like this is an IPv4 address
if (isset($part[1][1]) && strpos($part[1][1], '.') !== false)
{
Title: Re: Undefined offset: 1
Post by: radu81 on July 16, 2015, 05:19:27 am
It seems to work for now, no errors in the last 40 minutes. Thank you Emanuele!
Title: Re: Undefined offset: 1
Post by: emanuele on July 16, 2015, 05:24:16 am
YAY! :D

Note: yes, it is a bug, in particular IPv6 addresses may not have anything after the "::" like in:
Code: [Select]
2001:41d0:2:e494::
present in the log posted by radu.
In this case,
Code: [Select]
$part[1]
is an empty array, and so it should not do anything about IPv4, but go straight to the "expand missing pieces" just after that.

/me moves the topic
Title: Re: Undefined offset: 1
Post by: radu81 on July 16, 2015, 08:05:31 am
After a few hours my error log is still empty ;) Thanks again!
Title: Re: Undefined offset: 1
Post by: Spuds on July 16, 2015, 05:22:26 pm
Did this get tracked for 1.0.5 ?
Title: Re: Undefined offset: 1
Post by: emanuele on July 16, 2015, 07:12:42 pm
I guess not... O:-)
Title: Re: Undefined offset: 1
Post by: Spuds on July 16, 2015, 09:28:40 pm
Tracked ... https://github.com/elkarte/Elkarte/issues/2125
Title: Re: Undefined offset: 1
Post by: emanuele on July 18, 2015, 04:05:42 am
And fixed in 1.0.5