https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d69d40132555772a1f229…
commit d69d40132555772a1f229bb3cb9f066e4890d3a3
Author: Serge Gautherie <32623169+SergeGautherie(a)users.noreply.github.com>
AuthorDate: Fri Jul 27 21:53:50 2018 +0200
Commit: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito(a)reactos.org>
CommitDate: Fri Jul 27 21:53:50 2018 +0200
[MAN] AnalyzeArgv(): Fix 2 overruns related to element (#703)
- Also use _countof().
- Also add braces.
- Also enforce consistent "no spaces" style.
Thanks to "devpao" for pointing to this function.
ROSAPPS-344
---
modules/rosapps/applications/sysutils/man/man.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/modules/rosapps/applications/sysutils/man/man.c
b/modules/rosapps/applications/sysutils/man/man.c
index edc12d2365..3c54eb346a 100644
--- a/modules/rosapps/applications/sysutils/man/man.c
+++ b/modules/rosapps/applications/sysutils/man/man.c
@@ -88,7 +88,7 @@ Usage()
int
AnalyzeArgv(char *argument)
{
- int element=0;
+ int element;
char HelpFlag=0;
char *keys[]={"--help","/h","/?","-h"};
char
*sections[]={".1",".2",".3",".4",".5",".6",".7",".8",".9"};
@@ -96,25 +96,32 @@ AnalyzeArgv(char *argument)
strcpy(filename,argument); //save argument value
- for(element=0; element < 5;element++)
+ for(element=0;element<_countof(keys);element++)
+ {
if(!strcmp(keys[element],argument))
{
Usage();
HelpFlag=1;
}
+ }
element = 0;
if(!HelpFlag)
+ {
if(OpenF(filename))
- while(OpenF(strcat(filename,sections[element])) && (element<9))
+ {
+
while(element<_countof(sections)&&OpenF(strcat(filename,sections[element])))
{
strcpy(filename,argument);
element++;
}
- if(element>8) printf("No manual for %s\n",argument);
+ if(element>=_countof(sections)) printf("No manual for %s\n",argument);
+ }
+
+ }
return element;
}