[PLUG] problem encountered with argv[] change when a local file named "1" is inserted into the file system

American Citizen website.reader3 at gmail.com
Sat Dec 16 19:26:07 UTC 2023


Hello:

I bumped into a curious problem with the argv variables changing, when a 
certain file named "1" is added into the local directory of the executable.

Here is the test file, a simple program named test.c

> #include <stdio.h>
> #include <string.h>
>
> int main(int argc, char **argv) {
>
>   int i=1;
>   //int STDIN = 1;
>
>   char INCURV[1024] = {'\0'};
>
>   while(i<argc) {
>     if (!strcmp(argv[i],"-curve")) {
>       printf("we are here \n");
>       //strcpy(INCURV,argv[i+1]); STDIN=0; i+=2;
>     }
>     i+=1;
>   }
>   return 0;
> }
>
I compile this file as

% gcc -o wack test.c -ggdb

(it is too easy to wipe out the source file if the object name almost 
matches)

gcc is gcc version 7.5.0 (SUSE Linux)

I have the gdb debugger stop on line 13 "printf("we are here\n");"

Using input to the command:

% wack -arderivs -curve [0,0,0,-1156,0]

when no file named "1" exists in the directory  then argv looks okay

argv[0] = "/../../wack"

argv[1] = "-arderivs"

argv[2] = "-curve"

argv[3] = "[0,0,0,-1156,0]"

argv[4] = 0x0

which is all fine and well.

I used the touch command to create file "1" in the local directory

% touch 1

and restart the gdb debugger.

argc count = 4 as expected

but argv[3] = "1"

Is this a bug in c?

Why is argv[3] changed?

Randall




More information about the PLUG mailing list