Thu, Nov 12, 2009 at 01:23:50PM -0500, Matt Richards wrote:
> However, on RedHat it core dumps. The problem lies in IsCf3VarString
> (vars.c ~line 485):
> 
> int IsCf3VarString(char *str)
> 
> { char *sp;
>   char left = 'x', right = 'x';
>   int dollar = false;
>   int bracks = 0, vars = 0;
> 
> Debug1("IsCf3VarString(%s) - syntax verify\n",str);
> 
> for (sp = str; *sp != '\0' ; sp++)       /* check for varitems */
> 
> When RedHat core dumps, str is NULL. Other OS'es can deal with sp =
> str,

Pardon me?  I think that all OSes can deal with "sp = str", but on only
a small subset [1] the program will survive "*sp" when sp is NULL.  And
this small subset tries to be polite to the programmers who don't bother
checking for NULL pointers.

May be I am missing something?

> but RedHat does not. In a layman's attempt to patch, I just did:
> 
> int IsCf3VarString(char *str)
> 
> { char *sp;
>   char left = 'x', right = 'x';
>   int dollar = false;
>   int bracks = 0, vars = 0;
> 
> Debug1("IsCf3VarString(%s) - syntax verify\n",str);
> 
> if ( str == NULL ) {
>    Debug("Found %d variables in (%s)\n",vars,str);
>    return vars;
> }
> 
> for (sp = str; *sp != '\0' ; sp++)       /* check for varitems */
> 
> 
> It appears to work. I am not sure if this is the right way to do it,
> but you get the idea.

I would say that if something passes NULL to the IsCf3VarString(),
then we should nail down the caller and fix it -- it is obvious that
NULL can't be VarString, so, possibly, there is a bug in the caller
code.

[1] HP-UX and System V comes to my mind.
-- 
Eygene Ryabinkin, Russian Research Centre "Kurchatov Institute"
_______________________________________________
Bug-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/bug-cfengine

Reply via email to