[PATCH:setxkbmap] Use snprintf instead of trying to pre-measure sprintf result sizes.
Alan Coopersmith
alan.coopersmith at oracle.com
Tue Feb 15 13:41:24 PST 2011
On 02/15/11 12:48 PM, Van de Bugger wrote:
> On Tue, 2011-02-15 at 10:48 +1000, Peter Hutterer wrote:
>> On Thu, Feb 10, 2011 at 12:00:11AM -0800, Alan Coopersmith wrote:
>>> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
>>> ---
>>> setxkbmap.c | 7 +++----
>>> 1 files changed, 3 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/setxkbmap.c b/setxkbmap.c
>>> index 868b727..9593ba4 100644
>>> --- a/setxkbmap.c
>>> +++ b/setxkbmap.c
>>> @@ -626,14 +626,13 @@ findFileInPath(char *name, char *subdir)
>>> }
>>> for (i = 0; (i < numInclPath); i++)
>>> {
>>> - if ((strlen(inclPath[i]) + strlen(subdir) + strlen(name) + 2) >
>>> + if (snprintf(buf, PATH_MAX, "%s/%s%s", inclPath[i], subdir, name) >=
>>> PATH_MAX)
>>> {
>>> VMSG3(0, "Path too long (%s/%s%s). Ignored.\n", inclPath[i],
>>> subdir, name);
>>> continue;
>>> }
>>> - sprintf(buf, "%s/%s%s", inclPath[i], subdir, name);
>>> fp = fopen(name, "r");
>
> ##### I guess it is a bug. We do printing to `buf', checking lentgh, but
> open file named by `name'. See for my next patch.
Good point, I don't know why the code creates the buf string and doesn't use it.
--
-Alan Coopersmith- alan.coopersmith at oracle.com
Oracle Solaris Platform Engineering: X Window System
More information about the xorg-devel
mailing list