News for hackers. Stuff that matters.
Re:Remote code execution vulnerability in SQLite by yladiz on Friday December 14, 2018 @06:22PM (#18685844)
Isn't that the definition of branch testing, to test all possible branches within code and also testing the logic in all of those branches?
Re:Remote code execution vulnerability in SQLite by gregmac on Friday December 14, 2018 @06:24PM (#18685857)
Consider a line like:

    value = 1 / input;
You can get "100% coverage" if you test that with `input = 1`, but unless you check with `input = 0` you're missing a quite important logical check.
Re:Remote code execution vulnerability in SQLite by breckuh on Friday December 14, 2018 @08:47PM (#18686517)
Can't you just have a NonZeroInt type?
Re:Remote code execution vulnerability in SQLite by whyonearth on Friday December 14, 2018 @08:58PM (#18686553)
Only if your language supports dependent types.
Re:Remote code execution vulnerability in SQLite by tonyg on Saturday December 15, 2018 @10:47AM (#18688778)
It's perfectly possible in languages with ordinary ADTs.

  data Nat = Z | S Nat
  data NonZeroNat = OnePlus Nat
  data NonZeroInt = Negative NonZeroNat | Positive NonZeroNat
Re:Remote code execution vulnerability in SQLite by jwatte on Sunday December 16, 2018 @12:46PM (#18694109)
C isn't one of those languages, though.
Re:Remote code execution vulnerability in SQLite by tonyg on Monday December 17, 2018 @03:47PM (#18702049)
The analogous would be the Go-style represent-a-sum-badly-as-a-product,

  struct nonzero_t {
    int is_negative;
    unsigned int one_less_than_the_absolute_value;
  };
which, under interpretation, ranges from -(2^32) to -1 and +1 to +(2^32).
Re:Remote code execution vulnerability in SQLite by krylon on Saturday December 15, 2018 @08:25AM (#18688292)
In Ada, you can define integer types that only accept a given range of values.
Re:Remote code execution vulnerability in SQLite by akvadrako on Friday December 14, 2018 @06:52PM (#18685997)
Not really - internally inputs 0 and 1 use different branches.
Re:Remote code execution vulnerability in SQLite by RussianCow on Friday December 14, 2018 @06:59PM (#18686028)
That's not a branch; otherwise you would have an infinite (or impossibly large) number of branches for just that one line of code. A branch is when you execute one set of code upon a given condition, and another if that condition is not met.
Re:Remote code execution vulnerability in SQLite by akvadrako on Friday December 14, 2018 @08:04PM (#18686340)
I didn't say every number is a different branch. But on many processors, divide by zero triggers an interrupt. That's semantically the same as a branch.
Re:Remote code execution vulnerability in SQLite by qznc on Friday December 14, 2018 @07:26PM (#18686164)
It depends on the language. In C it is not a branch because division by zero is undefined and not a path you consider. In Java you can argue that there are two branches. One branch that throws an exception and one that does not.
Re:Remote code execution vulnerability in SQLite by zaphar on Friday December 14, 2018 @08:03PM (#18686335)
No coverage reporting library will attempt to tell you that kind of coverage. You are essentially in violent agreement with the op but turning it into an argument by using different words for the same concept.
Re:Remote code execution vulnerability in SQLite by thaumasiotes on Saturday December 15, 2018 @04:26AM (#18687742)
Testing all possible branches (each considered individually) won't get you very far in terms of testing all possible logic flows.

Consider a function which checks 5 simple if-statements in a row, always in the same order. Getting each branch means you tested 10 things.

But there are 32 ways for 5 if-statements to jointly evaluate. If there is a logical dependency between the state checked by one if-statement and the state checked by another one, your perfect coverage may not pick up on that.

If the if-statements might be checked in an arbitrary order... there are 120 ways to order 5 things. But you'll still get perfect branch coverage by checking 10 of them.

Re:Remote code execution vulnerability in SQLite by archgoon on Saturday December 15, 2018 @06:36PM (#18690957)

  int returns_less_than_twelve(int input1, int input2) {
    int sum = 0;
    if (input >= 5) {
       sum += 5;
    } 
    if (input2 >= 5) {
      sum += 8;
    }
    return sum;
  }
The following test cases will pass and achieve 100% branch coverage.

  int x = returns_less_than_twelve(5,0);
  test_assert(x < 12);
  int y = returns_less_than_twelve(0,5);
  test_assert(x < 12);
However, this does not cover the entire input space so

  returns_less_than_twelve(5,5);
  test_assert(x < 12);
Will fail. However, branch coverage won't tell you that there's a hole in your test coverage.

Generally however, writing full branch coverage will find a lot of issues, and also cause you to really think through how your code works; but still, it doesn't guarantee correctness. If you want that you need to start bringing tools that either exhaust your input space (a function which takes 5 booleans can be exhaustively tested for correctness in trivial amounts of time), or you start modeling your chosen language well enough that you can use a mathematical prover to demonstrate that your program or function is safe on all inputs.

This of course requires you to come up with a definition of 'correct' or 'safe'. For the above program, it's clear how to define correctness. For things like "Don't let an unauthorized individual access this data or data that is derived from it in a way contrary to the desires of the owner of said data" it gets 'tricky' ;).

Re:Remote code execution vulnerability in SQLite by gcc_programmer on Friday December 14, 2018 @06:25PM (#18685859)
You test all possible executions of your program when you test with all possible data inputs, which is infinite.
Re:Remote code execution vulnerability in SQLite by seanwilson on Friday December 14, 2018 @07:35PM (#18686213)
You can do this with machine verified programs. It's like proving a maths theorem; you don't check it for all values but you create a robust argument that it must be true for all values.
Re:Remote code execution vulnerability in SQLite by paulie_a on Friday December 14, 2018 @06:40PM (#18685920)
That is why I like using random data generators for tests. You can input some static data and then the rest is random. Every once in a while a bug pops out when you see a test fail that was previously passing.
Re:Remote code execution vulnerability in SQLite by regecks on Friday December 14, 2018 @06:43PM (#18685945)
SQLite is heavily subjected to fuzzing already ... maybe this vulnerability was discovered that way.
Re:Remote code execution vulnerability in SQLite by snaky on Friday December 14, 2018 @07:26PM (#18686165)
And the probability to find the corner case ('input = 0') for the simplest expression ('value = 1 / input') this way is not quite astounding.
Re:Remote code execution vulnerability in SQLite by jcden on Friday December 14, 2018 @07:03PM (#18686039)
None of the above methods are used for testing. You use boundary testing, branch testing, equivalence partitioning etc. Random data is not a good method of testing.
Re:Remote code execution vulnerability in SQLite by jakevn on Friday December 14, 2018 @07:15PM (#18686097)
Except for the fact that it is exactly the method that has been used to discover a large number of critical bugs in the most popular OSS projects (including SQLite): http://lcamtuf.coredump.cx/afl/
Re:Remote code execution vulnerability in SQLite by Frizi on Friday December 14, 2018 @08:27PM (#18686429)
Fuzzing isn't really practical if all you do is just generate a totally random bit stream for input. There are many much more clever and robust strategies to hit as many edge cases as possible. Check AFL[1] for some details on generating smart random input files. You can also combine that with pretty advanced dynamic execution analysis to fuzz against unknown processor instruction sets, like in sandsifter[2].

[1]: http://lcamtuf.coredump.cx/afl/

[2]: https://github.com/xoreaxeaxeax/sandsifter

Re:Remote code execution vulnerability in SQLite by tptacek on Friday December 14, 2018 @08:31PM (#18686448)
On the contrary, for years, the most prolific fuzzers basically did just generate random bitstreams, and that technique will still find vulnerabilities in all the memory-unsafe software that hasn't been fished out by those same dumb fuzzers.
Re:Remote code execution vulnerability in SQLite by paulie_a on Monday December 17, 2018 @09:12AM (#18698991)
Sorry, I strongly disagree. Random data with a few static arguments is an incredibly great way to test. Adding in some chaos finds bugs. "why did that test fail after 100 times...ohhhh"

I try to only use random data when possible, less and smaller tests to write with a proper setup. End result: more bugs found.

Random data is a great method of testing.