noob C++ arrays/subscipt operator question

Discussion in 'Computer Programming, Emulation, and Game Modding' started by Nyap, May 24, 2016.

  1. Nyap
    OP

    Nyap HTML Noob

    Banned
    973
    344
    Jan 13, 2016
    That Chaos Site
    if you put a number thats out of the range of an array, could you mess with other programs memory? and if so, could I write a virus that makes itself start on boot and c̶o̶m̶p̶l̶e̶t̶e̶l̶y̶ to a certain extent ruin the host computer?
     
  2. FAST6191

    FAST6191 Techromancer

    pip Reporter
    23,355
    9,148
    Nov 21, 2005
    Depends what operating system. Modern security tends to get a bit touchy about executables touching others, most operating systems are designed to virtualise memory in some way, even if you manage it then a lot of programs use ASLR or a similar technology that randomises memory locations for outside reads. This also assumes your compiler does not catch it (though I suppose you could force it if so).
    This also does not account for permissions level security (adding things to boot/startup tending to be a restricted activity).

    There are things you can do by what is almost a buffer overflow you programmed yourself but in the scenario you describe you would already have arbitrary code execution so there is no point in really considering it from that angle.
     
    codeluca likes this.
  3. Frederica Bernkastel

    Frederica Bernkastel WebPerf and PWA advocate; @antoligy on Twitter

    Member
    GBAtemp Patron
    Frederica Bernkastel is a Patron of GBAtemp and is helping us stay independent!

    Our Patreon
    3,154
    765
    Jan 31, 2008
    United Kingdom
    Hinamizawa
    What FAST said, but just to tack onto the point about the compiler... In case the compiler doesn't catch it, you run into a wonderful world of pain and unpredictable behaviour. Most likely, as arrays and by extension vectors have no bounds checking (too unperformant), you'd run into memory leakage as the trend for OSes now is to isolate memory space on a per-application basis. Your program would probably just crash.
     
  4. FAST6191

    FAST6191 Techromancer

    pip Reporter
    23,355
    9,148
    Nov 21, 2005
    Didn't they say the same about "random" jumps/branches? And then we got return oriented programming.
     
  5. evandixon

    evandixon PMD Researcher

    Member
    1,666
    787
    May 29, 2009
    United States
    For small out of bounds access, you'd just get whatever garbage is after your array in memory. If you escape your application's allocated memory, you'll likely get an exception of some sort.
     
  6. Nyap
    OP

    Nyap HTML Noob

    Banned
    973
    344
    Jan 13, 2016
    That Chaos Site
    would it be correct to say that the programs are "sandboxed in memory"
     
  7. FAST6191

    FAST6191 Techromancer

    pip Reporter
    23,355
    9,148
    Nov 21, 2005
    A sandbox is usually a specific way things are run and thus it would not quite qualify, or at least risk confusion as asking someone to run something in a sandbox means something. It is possible for programs to fiddle with the contents of other programs (it is how your debugger works, your hex editor might well have the functionality and so forth) but it is not normal for them to do it in end user machines -- it is why you have DLL/library calls, terminal/command line stuff and a bunch of other APIs depending upon the programming style. In X86 at least there is also the concept of rings (you might have heard of things like ring 0 root kits or ring 0 drivers or ring 0 DRM) that theoretically protect things from other programs running at higher rings but let us not go there.
    If you want to get a bit more complex then http://www.plantation-productions.c...indows/HTML/MemoryArchitecturea3.html#1023797 and http://www.plantation-productions.c...m/Windows/HTML/MemoryAccessandOrg.html#999687 has some stuff.
     
    Frederica Bernkastel likes this.