-1

Is this a known problem?

select * from 'tablename' where INET_ATON('any valid ip');

Shows the entire db. I accidentally forget to add ipaddress = INET_ATON('ip'); and cganged the entire db.

Sirko
  • 72,589
  • 19
  • 149
  • 183
  • 1
    You "changed the entire db" with a different query afterwards though, right? Or as if this was part of a subquery that ended up selecting everything? – Wesley Murch Jul 08 '13 at 15:52
  • 3
    `WHERE INET_ATON('any valid ip')`. MySQL will try to convert this to a boolean. Since it's greater than `0`, it's like if you did `WHERE TRUE` or (`WHERE 1`). That's why it selected all rows. This query alone won't update anything. Did you run an `UPDATE` query? – gen_Eric Jul 08 '13 at 15:54
  • update 'tablename' set field1 = '0', field2 = '0', field3 = '0' where INET_ATON('any ip'); – user2561395 Jul 08 '13 at 15:55
  • 1
    @user2561395: Yep. There ya go. `where INET_ATON('any ip')` selected all rows, since it's converted to a boolean, and therefore `TRUE` :-) – gen_Eric Jul 08 '13 at 15:56
  • Maybe important to note, the ip must be valid or `INET_ATON();` will return null, which would select nothing in that case. – Wesley Murch Jul 08 '13 at 15:57
  • Thank you. I guess I have just learned a lesson the hard way. – user2561395 Jul 08 '13 at 15:57
  • That is correct. It just needs to be in the format of x.x.x.x – user2561395 Jul 08 '13 at 15:58
  • As a small aside, `INET_ATON('0.0.0.0')` is zero and thus boolean false. So, not every valid dotted quad specification would have yielded true for the OP. – pilcrow Jul 08 '13 at 16:19

2 Answers2

1

What you query with is basically equivalent to:

select * from 'tablename' 
where 1

The WHERE clause is always true, so all table rows are returned.

Ryan
  • 26,884
  • 9
  • 56
  • 83
1

I don't see anything wrong with all rows returned. INET_ATON will return number > 0 if IP is valid OR NULL if IP is invalid. Which means, it's like issuing query

SELECT * FROM `tablename` WHERE 1

(or any other positive number) which will return all rows.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Parag
  • 51
  • 1