[PATCH:setxkbmap] Use snprintf instead of trying to pre-measure sprintf result sizes.

Alan Coopersmith alan.coopersmith at oracle.com
Mon Feb 14 17:11:03 PST 2011


On 02/14/11 04:48 PM, 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");
>>          if ((verbose > 7) || ((!fp) && (verbose > 5)))
>>              MSG2("%s file %s\n", (fp ? "Found" : "Didn't find"), buf);
>> @@ -845,13 +844,13 @@ applyRules(void)
>>               * we succeed with */
>>              for (i = 0; (i < numInclPath) && (!rules); i++)
>>              {
>> -                if ((strlen(inclPath[i]) + strlen(rfName) + 8) > PATH_MAX)
>> +                if (snprintf(buf, PATH_MAX, "%s/rules/%s", inclPath[i],
>> +                             svValue[RULES_NDX]) >= PATH_MAX)
>>                  {
>>                      VMSG2(0, "Path too long (%s/rules/%s). Ignored.\n",
>>                            inclPath[i], rfName);
>>                      continue;
>>                  }
>> -                sprintf(buf, "%s/rules/%s", inclPath[i], svValue[RULES_NDX]);
>>                  rules = XkbRF_Load(buf, svValue[LOCALE_NDX], True, True);
>>              }
>>          }
>> -- 
>> 1.7.3.2
> 
> I can't seem to find the rev this patch was based on, it gives me conflicts
> with and without Van's patches (just pushed those to master).

I already pushed it, before Van's patches came in:

http://cgit.freedesktop.org/xorg/app/setxkbmap/commit/?id=ae3cfee9bd393d28159072a67360de57e64f48cd


-- 
	-Alan Coopersmith-        alan.coopersmith at oracle.com
	 Oracle Solaris Platform Engineering: X Window System



More information about the xorg-devel mailing list