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,373
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
29
Location
Hinamizawa
XP
999
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
1
Website
projectpokemon.org
XP
2,342
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,373
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.
  • K3Nv2 @ K3Nv2:
    13,600 MB/s though
  • DinohScene @ DinohScene:
    I got a 980 pro iirc
  • K3Nv2 @ K3Nv2:
    Soldigms been pretty solid
  • DinohScene @ DinohScene:
    yeh 980 pro
  • DinohScene @ DinohScene:
    good enough tbf
  • K3Nv2 @ K3Nv2:
    https://a.co/d/gMNhZNI never heard about them but reviews are good
  • SylverReZ @ SylverReZ:
    @DinohScene, Crucial SSDs work fine. I have one installed in my Xbox.
  • SylverReZ @ SylverReZ:
    Reviews seem positive.
  • DinohScene @ DinohScene:
    I believe I had some Patriot RAM running in a computer somewhere
  • K3Nv2 @ K3Nv2:
    $250 is pretty solid considering
  • K3Nv2 @ K3Nv2:
    With the refund it'll be about $150
  • K3Nv2 @ K3Nv2:
    6tb nvme pc ftw
  • DinohScene @ DinohScene:
    500 GB NVMe, 750 GB
    SATA SSD 1 TB HDD
  • DinohScene @ DinohScene:
    honestly I don't play pc games
  • K3Nv2 @ K3Nv2:
    I don't game
  • K3Nv2 @ K3Nv2:
    Once I buy this I'll be around 20tb worth of storage tho if we're talking all my drives
  • K3Nv2 @ K3Nv2:
    All this crap I got and all I do is pick up the GabeDick to fiddle with his happy stick
  • DinohScene @ DinohScene:
    idk the total storage cap I have
  • DinohScene @ DinohScene:
    50 TB orso
  • SylverReZ @ SylverReZ:
    @DinohScene, I don't play PC games often. Mostly its all 90s-00s games.
  • K3Nv2 @ K3Nv2:
    Hm doing research quite possible my issue with this drive is bios related not detecting it fully
  • DinohScene @ DinohScene:
    run crystaldisk?
  • K3Nv2 @ K3Nv2:
    Don't think it would do much if gnome live even sees it as 2mb
  • K3Nv2 @ K3Nv2:
    Vmd issue possibly
    K3Nv2 @ K3Nv2: Vmd issue possibly