DSblizzard
DSblizzard

Reputation: 4149

Do I need to copy command line arguments in assembly

I work with fasm but maybe this question doesn't rely on assembly language version. Where is command line arguments string stored? Do I need to copy this string at program start or it is guaranteed to persist indefinitely? Can buffer overflows etc from my program overwrite original?

Upvotes: 2

Views: 141

Answers (1)

tenfour
tenfour

Reputation: 36896

Command line arguments are part of the process environment block (PEB) and do not change after the process starts. You can access the command line via GetCommandLineW, and you can parse the arguments yourself. There also exists CommandLineToArgvW which does some parsing for you.

The string data is in writable memory, so yes if you have buggy / insecure code that modifies one arg, an overflow in it could modify another one.

Upvotes: 7

Related Questions