On Wednesday 15 of December 2010 15:18:55 L. Alberto Giménez wrote:
> On 14/12/2010 20:30, Brane F. Gračnar wrote:
> > Hello :)
> 
> Hi Brane,
> 
> I haven't had time to test your patch, but after a "visual" review made
> some doubts to come up.

It also applies to 1.4.10.


> @@ -5343,6 +5440,40 @@ int readcfgfile(const char *file)
>                       err_code |= ERR_ALERT | ERR_FATAL;
>               }
> 
> [...]
> +                     memset(file_dir, '\0', buf_len);
> +                     strcpy(file_dir, file);
> +                     strcpy(file_dir, dirname(file_dir));
> 
> The first strcpy would be useless here?

I experienced crashes without first strcpy. dirname(3) may change input 
buffer. From dirname(3):

--- snip ---
Both dirname() and basename() may modify the contents of path, so it may be 
desirable to pass a copy when calling one of these functions.
--- snip ---

> 
> @@ -5193,6 +5195,99 @@ out:
>       return err_code;
>   }
> [...]
> +     /** we want to support relative to include file glob patterns */
> +     int buf_len = 3;
> +     if (dir != NULL)
> +             buf_len += strlen(dir);
> 
> Could you please clarify where does that "magic" 3 coming from?. As I
> said, I couldn't test the patch, and I can't figure it out for myself.

Initial buffer length should be 2 (To hold at least '/' and '\0' characters). 
I want to concatenate <directory>, "/", <glob pattern> into variable 
real_pattern. Complete buffer length is: strlen(dir) + strlen(pattern) + 1 
(slash character) + 1 (string termination byte).

I set it to 3 becouse of "just in case" :) I think that this shouldn't be a 
problem becouse configuration parsing is done only at haproxy startup and 
real_pattern is always freed after usage.

Best regards, Brane

Reply via email to