After investigating bug 38870 [1], I came up with some possible solutions to this problem.
1. Duplicate argv. 2. Copy the filename argument into a dynamically allocated array. 3. Copy the filename's iteration number (the 'n' of argv[n]) into a dynamically allocated array. 4. Use NULL pointers after processing to determine whether an argument is a flag or a filename.
Of these answers, option four is the lightest and easiest to implement. It is also efficient. The idea is to assign argv[i] = NULL after we have processed an argument that is a flag.
So, I'm proposing something like this pseudo-code (there is an actual diff below):
for (i = 1; i < argc; i++) { if (is a flag) { do something; argv[i] = NULL; } } for (i = 1; i < argc; i++) { if (argv[i]) /* only filenames are valid */ do something; }
diff --git a/programs/regsvr32/regsvr32.c b/programs/regsvr32/regsvr32.c index 449124f..ef895e0 100644 --- a/programs/regsvr32/regsvr32.c +++ b/programs/regsvr32/regsvr32.c @@ -270,8 +270,13 @@ int wmain(int argc, WCHAR* argv[]) output_write(STRING_USAGE); return 1; } + argv[i] = NULL; } - else + } + + for (i = 1; i < argc; i++) + { + if (argv[i]) { WCHAR *DllName = argv[i]; int res = 0;
The proposed changes work correctly, both with a test DLL and also MediaInfo program from the bug.
Any comments and suggestions are welcome.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hi,
I haven't really looked into the details, but I am curious if your change works ok if the user passes a Unix path to regsvr32?
Cheers, Stefan
Am 2015-07-14 um 13:37 schrieb Hugh McMaster:
After investigating bug 38870 [1], I came up with some possible solutions to this problem.
- Duplicate argv. 2. Copy the filename argument into a dynamically
allocated array. 3. Copy the filename's iteration number (the 'n' of argv[n]) into a dynamically allocated array. 4. Use NULL pointers after processing to determine whether an argument is a flag or a filename.
Of these answers, option four is the lightest and easiest to implement. It is also efficient. The idea is to assign argv[i] = NULL after we have processed an argument that is a flag.
So, I'm proposing something like this pseudo-code (there is an actual diff below):
for (i = 1; i < argc; i++) { if (is a flag) { do something; argv[i] = NULL; } } for (i = 1; i < argc; i++) { if (argv[i]) /* only filenames are valid */ do something; }
diff --git a/programs/regsvr32/regsvr32.c b/programs/regsvr32/regsvr32.c index 449124f..ef895e0 100644 --- a/programs/regsvr32/regsvr32.c +++ b/programs/regsvr32/regsvr32.c @@ -270,8 +270,13 @@ int wmain(int argc, WCHAR* argv[]) output_write(STRING_USAGE); return 1; } + argv[i] = NULL; } - else + } + + for (i = 1; i < argc; i++) + { + if (argv[i]) { WCHAR *DllName = argv[i]; int res = 0;
The proposed changes work correctly, both with a test DLL and also MediaInfo program from the bug.
Any comments and suggestions are welcome.
On Wednesday, 15 July 2015 13:05:15 +0200, Stefan Dösinger wrote:
I haven't really looked into the details, but I am curious if your change works ok if the user passes a Unix path to regsvr32?
Hi Stefan,
Users can still pass Unix paths to regsvr32.
A comparison of regsvr32 functionality in Windows, Wine and with the proposed patch can be found at link [1].
[1] https://www.dropbox.com/s/ezu04poan99bf6t/regsvr32-comparison.pdf?dl=0