#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    49
    Rep Power
    14

    (should be trivial) GCC skipping arg vector conditions?


    I have a simple program that is supposed to either do its thing or, given the correct arguments, return a flag so that the parent process (a much, much more complex and advanced program...) can decide whether this process (called a cell) is safe to run, or if it's been flagged as unsafe because a proprietary virus (part of this complex process) has infected this cell and marked it with the flag 0xBADF. Btw, I say virus because precisely what it does is act as a lytic or lysogenic process which either infects a "cell," giving it the flag that says the cell could be harmful/shouldn't be loaded or executed, or injects a copy of itself into a cell process so that the cell process could itself become one of these cell checker viruses. It's confusing, but I assure you that it does not even work without this framework I've developed. Anyway, my test cell file that I want to try to change the flag on won't even correctly work anyway.

    The source is:
    [CODE=C]
    /*
    * cf1.c
    * cell flag to test labeling for use in VAIS and other NOXIS classes
    */

    #include<stdio.h>

    int main(int argc, char** argv){
    if(argv[1] == "?"){
    if(argv[2] == "CELL_FLAG"){
    return 0x5afe; // 5AFE is safe
    }
    }else{
    printf("The default CELL_FLAG for this cell is 0x5AFE.\n");
    return 0;
    }
    }
    [/CODE]

    The command line is:
    Code:
    $ gcc -o cf1 cf1.c
    $ ./cf1 ? CELL_FLAG
    The process should return 0x5AFE, as denoted by the mac os x (I don't know if other unix systems use $?).

    But instead, it ignores the input and does it's thing.

    What's goin' on here?

    EDIT: Just to clarify and ease your mind, I say "virus" but it's only a modified version of Jingle Bell, from this article:
    http://www.kernelthread.com/publications/security/vunix.html
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    49
    Rep Power
    14
    On another note, the same thing is happening to other processes with the argv conditions.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    49
    Rep Power
    14
    Sorry, it was extremely trivial. I need to use strcmp()...I'm switching between languages constantly and these things are always confused. Anyway, the fixed (and more proper) source code is:

    [CODE=c]
    #include<stdio.h>
    #include<string.h>

    int main(int argc, char** argv){
    while(argc > 1){
    if(strcmp(argv[1], "?") == 0){
    if(strcmp(argv[1], "CELL_FLAG") == 0){
    return 0x5afe; // 0x5AFE is safe
    }
    }
    break;
    }

    printf("The default CELL_FLAG for this cell is 0x5AFE.\n");
    return 0;
    }
    [/CODE]

IMN logo majestic logo threadwatch logo seochat tools logo