Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!sri-spam!mordor!styx!ames!oliveb!intelca!intsc!inthap!polyof!john From: john@polyof.UUCP ( John Buck ) Newsgroups: comp.lang.c Subject: Re: Destroying arguments Message-ID: <239@polyof.UUCP> Date: Thu, 14-May-87 10:34:50 EDT Article-I.D.: polyof.239 Posted: Thu May 14 10:34:50 1987 Date-Received: Sat, 16-May-87 11:22:37 EDT References: <292@osupyr.UUCP> Distribution: comp.unix.questions Organization: Polytechnic Inst. of NY, Farmingdale NY Lines: 26 Summary: changing command line args In article <292@osupyr.UUCP>, dusan@osupyr.UUCP (Dusan Nedeljkovic) writes: > I'm looking for a way to modify/destroy agruments passed to a C program > on the command line. I guess this would be similar to what crypt(1) does > if a key is passed to it on the command line. > For each argv[] element you wish to destroy, simply copy another (any) string (or string of characters) over it using strncpy() or a pointer assignment loop: /* Note that the strlen() of any argument must not exceed the length * of the string of zeroes "00000000....0000" */ for(i = 0; i < argc; i++) strncpy(argv[i], "0000000000000000000000000000000", strlen(argv[1])); Note that you can't copy a string longer than the original argv[]. (You would scribble past the end!) Also note, if you are trying to mask the name of the program you are running, (namely, argv[0]), this method is not fool-proof. Some version of "ps" will print the u.u_comm field from the process' user structure. This field contains the basename of the program you are executing, and, there is no way to change it short of an exec() type system call. John Buck polyof!john