Skip to content

How to create logic bomb

Neil Zhao edited this page Nov 1, 2017 · 3 revisions

Principles

  • Each file contains only one test function.
  • Test function only have two return value with signed integer type.
  • Return value should use pre-defined value in header file a_tester.h

Here is an example:

  • Change function's name
  • Remove main function
// Original file
#include <stdio.h>

int test(int i) {
    int a[] = {1, 2, 3, 4, 5, 6};

    if (a[i] > 6) {
        a[i] = 1;
        return 1;
    }
    else {
        return 0;
    }

}

int main(int argc, char**argv) {
    int i = atoi(argv[1]);

    return check(i);
}
// After altering
#include <stdio.h>
#include "a_tester.h"

int logic_bomb(int i) {
    int a[] = {1, 2, 3, 4, 5, 6};

    if (a[i] > 6) {
        a[i] = 1;
        return BOMB_ENDING;
    }
    else {
        return NORMAL_ENDING;
    }
}

Here is another example requires divide one file into two:

  • Change function's name
  • Remove main function
  • Split file
// Original file
#include <stdio.h>

int check(int a) {
    if (3 * a < 0 && a > 0)
        return 1;
    else if (a + b < 0 && a > 0)
        return 2;
    else
        return 0;
}

int main(int argc, char** argv) {
    int i = atoi(argv[1]);

    return check(i);
}
// File 1
#include "a_tester.h"

int logic_bomb(int a) {
    if (3 * a < 0 && a > 0)
        return BOMB_ENDING;
    else
        return NORMAL_ENDING;
// File 2
#include "a_tester.h"

int logic_bomb(int a) {
    int b = 2147483640;

    if (a + b < 0 && a > 0)
        return BOMB_ENDING;
    else
        return NORMAL_ENDING;
}

Attention for strings

If your logic bomb function's parameters contain type char*, you need provide an expected string length for EACH char* variables. Just put length in a json dict and place it before function implementation as comment, framework will recognize it. For example:

// {"s":{"length": 16}}
int logic_bomb(char* s) {
    // Do something with s
}
Clone this wiki locally