noob C++ arrays/subscipt operator question

Nyap

HTML Noob
OP
Banned
Joined
Jan 13, 2016
Messages
971
Trophies
0
Age
55
Location
That Chaos Site
XP
483
Country
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?
 

FAST6191

Techromancer
Editorial Team
Joined
Nov 21, 2005
Messages
36,798
Trophies
3
XP
28,284
Country
United Kingdom
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.
 
  • Like
Reactions: codeluca

Frederica Bernkastel

Well-Known Member
Member
GBAtemp Patron
Joined
Jan 31, 2008
Messages
3,169
Trophies
2
Age
28
Location
Hinamizawa
XP
989
Country
Japan
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.
 

evandixon

PMD Researcher
Developer
Joined
May 29, 2009
Messages
1,725
Trophies
0
Website
projectpokemon.org
XP
2,313
Country
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.
 

FAST6191

Techromancer
Editorial Team
Joined
Nov 21, 2005
Messages
36,798
Trophies
3
XP
28,284
Country
United Kingdom
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.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
  • Sicklyboy @ Sicklyboy:
    maaaaan that's so awesome but I also don't want to fork over a hundo for it
  • Veho @ Veho:
    The fuuuuu---
  • Veho @ Veho:
    I thought it was an actual xBox at that price.
  • Sicklyboy @ Sicklyboy:
    I wanna grab a 360 Slim and a 360 E one of these days. Missed the boat of getting them at their lowest though, once they were discontinued. Could've got them for cheap back when I was a broke 20 something working at Target, but then again, I was a broke 20 something working at Target
  • Veho @ Veho:
    Being broke is no fun.
  • K3Nv2 @ K3Nv2:
    @Sicklyboy, $150 isn't that bad for a jtag slim on ebay
  • Veho @ Veho:
    I only wish it was actually playable.
  • Veho @ Veho:
    There's a guy on the Tube of You that makes playable mechanical arcade games out of Lego. This could work on the same principle.
  • Veho @ Veho:
    Just a couple of guys taking their manatee out for some fresh air, why you have to molest them?
  • Veho @ Veho:
    Stupid Chinese shop switched their shipping company and this one is slooooooow.
  • LeoTCK @ LeoTCK:
    STOP BUYING CHINESE CRAP THEN
  • LeoTCK @ LeoTCK:
    SUPPORT LOCAL PRODUCTS, MAKE REVOLUTION
  • LeoTCK @ LeoTCK:
    THEY KEEP REMOVING LOCAL SHIt AND REPLACING WItH INFERIOR CHINESE CRAP
  • LeoTCK @ LeoTCK:
    THATS WHY MY PARTNER CANT GET A GOOTWEAR HIS SIZE ANYMORE
  • LeoTCK @ LeoTCK:
    HE HAS BIG FOOT AND BIG DUCK
  • LeoTCK @ LeoTCK:
    d*ck i mean*
  • LeoTCK @ LeoTCK:
    lol
  • Veho @ Veho:
    Mkay.
  • Veho @ Veho:
    I just ordered another package from China just to spite you.
  • SylverReZ @ SylverReZ:
    Leo could not withstand communism.
  • SylverReZ @ SylverReZ:
    Its OUR products to begin with lol.
    SylverReZ @ SylverReZ: Its OUR products to begin with lol.