Results 1 to 10 of 10

Thread: Code snippet meaning?

  1. #1
    Join Date
    Mar 2010
    Beans
    25

    Question Code snippet meaning?

    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    int main(int argc, char **argv)
    {
    char buf[40];
    FILE *badfile;
    badfile = fopen("./badfile", "w");

    *(long *) &buf[0] = bffffea2;
    (long *) &buf[1] = some address ;
    *
    *(long *) &buf[2] = some address ;
    fwrite(buf, sizeof(buf), 1, badfile);
    fclose(badfile);
    }

    What does *(long *) &buf[0]=some address mean?????

    While compiling it gives error msg like bffffea2 undeclared.........
    What type does *(long *) &buf[0] mean and what type it stores??
    Am newbie to c programming.Do help.

    Thanks,
    Yasokrish

  2. #2
    Join Date
    Feb 2010
    Location
    Silicon Valley
    Beans
    1,898
    Distro
    Xubuntu 12.04 Precise Pangolin

    Re: Code snippet meaning?

    You have to do your own homework.

  3. #3
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: Code snippet meaning?

    Ugh... I don't get how this could work in a regular architecture even after the syntax is corrected. Why is there a hardcoded address? Who told you something will be stored there?

    EDIT: Ok, the code is *that* awful that I misread it completely. Heck, the whole *(long *)&buf[0] is totally unnecessary!!
    Last edited by nvteighen; April 4th, 2010 at 06:17 PM.

  4. #4
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Code snippet meaning?

    Well char buf[40] means that you are allocating 40 bytes address which is continuous.

    *(long*) &buf[0] means that at address buf[0] you are writing something that can hold 8 bytes. Assuming you are writing something else with *(long*) &buf[1] it means that buf[0] (one byte) will not change but the other 7 bytes if *(long*) &buf[0] will be overridden by the new write.

    Basically when you invoke a *(long*) &buf[i] you write from buf[i:i+7]

  5. #5
    Join Date
    Jun 2007
    Location
    Porirua, New Zealand
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Code snippet meaning?

    Nothing much to add, beyond asking if bffffea2 meant to be a hard-coded address. The way it is coded at the moment, the compiler is likely to interpret it as the name of a variable, which would explain the error message about it being undefined.

    A suggestion for future: use the [code] and [/code] tags around code snippets you post, it will help preserve the formatting. One way of inserting the proper [code] tag(s) is to highlight the code snippiet and click on the "#" button
    Forum DOs and DON'Ts
    Never assume that information you find using a search engine is up-to-date.

  6. #6
    Join Date
    Sep 2007
    Location
    Cambridge, MA
    Beans
    635

    Re: Code snippet meaning?

    Folks.

    The OP has been posting a stream of threads asking for help with programs that exploit security holes.

    I think this has been going on long enough and you need to put your BS sensors a notch higher now.

    Thank you.

    Sorry but enough is enough.

  7. #7
    Join Date
    Aug 2006
    Location
    60°27'48"N 24°48'18"E
    Beans
    3,453

    Re: Code snippet meaning?

    Oh, I believe people's bs sensors are high up enough, but I also wouldn't be too concerned regarding the threat level posed by this particular h4x0r in training
    LambdaGrok. | #ubuntu-programming on FreeNode

  8. #8
    Join Date
    Sep 2007
    Location
    Cambridge, MA
    Beans
    635

    Re: Code snippet meaning?

    Quote Originally Posted by CptPicard View Post
    Oh, I believe people's bs sensors are high up enough, but I also wouldn't be too concerned regarding the threat level posed by this particular h4x0r in training
    Yeah but he also hacks up his maybe compiling code until it's not usable at all anymore for "help".

    That would be fine if he wasn't starting as many threads as he does.

  9. #9
    Join Date
    Jun 2007
    Location
    Porirua, New Zealand
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Code snippet meaning?

    Concerns noted. I'm inclined to agree with CptPicard at the moment about the level of threat.

    There's also the "report" feature if things seem to be getting out of hand.
    Last edited by lisati; April 5th, 2010 at 02:58 AM. Reason: Fix typo
    Forum DOs and DON'Ts
    Never assume that information you find using a search engine is up-to-date.

  10. #10
    Join Date
    Mar 2010
    Beans
    25

    Re: Code snippet meaning?

    Hi,
    Sorry for inconvenience caused.Nothing intentional.Extremely sorry.Since am new to linux,i posted threads.No illegal intentions.

    Thank You,
    Yasokrish

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •