summaryrefslogtreecommitdiff
path: root/src/fontfile/fontfile.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2019-08-03 18:19:11 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2019-08-03 19:31:14 -0700
commit2178c7445a3464bd69637ad91a2dd0320a60e0df (patch)
treef8859af93eafcf4e321ab8170567070bcf00c057 /src/fontfile/fontfile.c
parentd4c941ea8b1dc07a14efce656bff58d31a14c985 (diff)
downloadxorg-lib-libXfont-2178c7445a3464bd69637ad91a2dd0320a60e0df.tar.gz
Use bounds checking string functions everywhere
Replace strcpy, strcat, sprintf with strlcpy, strlcat, snprintf everywhere, even where there were already bounds checks in place, to reduce time spent checking static analysis results. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'src/fontfile/fontfile.c')
-rw-r--r--src/fontfile/fontfile.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/fontfile/fontfile.c b/src/fontfile/fontfile.c
index b2f1a6f..d36bbc0 100644
--- a/src/fontfile/fontfile.c
+++ b/src/fontfile/fontfile.c
@@ -37,6 +37,7 @@ in this Software without prior written authorization from The Open Group.
#ifdef WIN32
#include <ctype.h>
#endif
+#include "src/util/replace.h"
static unsigned char
ISOLatin1ToLower(unsigned char source)
@@ -354,7 +355,7 @@ FontFileOpenFont (pointer client, FontPathElementPtr fpe, Mask flags,
entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, &vals);
if (entry)
{
- strcpy(lowerName, entry->name.name);
+ strlcpy(lowerName, entry->name.name, sizeof(lowerName));
tmpName.name = lowerName;
tmpName.length = entry->name.length;
tmpName.ndashes = entry->name.ndashes;
@@ -442,8 +443,8 @@ FontFileOpenFont (pointer client, FontPathElementPtr fpe, Mask flags,
sizeof(fileName)) {
ret = BadFontName;
} else {
- strcpy (fileName, dir->directory);
- strcat (fileName, scalable->fileName);
+ strlcpy (fileName, dir->directory, sizeof(fileName));
+ strlcat (fileName, scalable->fileName, sizeof(fileName));
if (scalable->renderer->OpenScalable) {
ret = (*scalable->renderer->OpenScalable) (fpe, pFont,
flags, entry, fileName, &vals, format, fmask,
@@ -527,8 +528,8 @@ FontFileOpenBitmapNCF (FontPathElementPtr fpe, FontPtr *pFont,
return BadFontName;
if (strlen(dir->directory) + strlen(bitmap->fileName) >= sizeof(fileName))
return BadFontName;
- strcpy (fileName, dir->directory);
- strcat (fileName, bitmap->fileName);
+ strlcpy (fileName, dir->directory, sizeof(fileName));
+ strlcat (fileName, bitmap->fileName, sizeof(fileName));
ret = (*bitmap->renderer->OpenBitmap)
(fpe, pFont, flags, entry, fileName, format, fmask,
non_cachable_font);
@@ -564,8 +565,8 @@ FontFileGetInfoBitmap (FontPathElementPtr fpe, FontInfoPtr pFontInfo,
return BadFontName;
if (strlen(dir->directory) + strlen(bitmap->fileName) >= sizeof(fileName))
return BadFontName;
- strcpy (fileName, dir->directory);
- strcat (fileName, bitmap->fileName);
+ strlcpy (fileName, dir->directory, sizeof(fileName));
+ strlcat (fileName, bitmap->fileName, sizeof(fileName));
ret = (*bitmap->renderer->GetInfoBitmap) (fpe, pFontInfo, entry, fileName);
return ret;
}
@@ -590,7 +591,7 @@ _FontFileAddScalableNames(FontNamesPtr names, FontNamesPtr scaleNames,
{
--*max;
- strcpy (nameChars, scaleNames->names[i]);
+ strlcpy (nameChars, scaleNames->names[i], sizeof(nameChars));
if ((vals->values_supplied & PIXELSIZE_MASK) ||
!(vals->values_supplied & PIXELSIZE_WILDCARD) ||
vals->y == 0)
@@ -713,7 +714,7 @@ _FontFileListFonts (pointer client, FontPathElementPtr fpe,
/* Match XLFD patterns */
- strcpy (zeroChars, lowerChars);
+ strlcpy (zeroChars, lowerChars, sizeof(zeroChars));
if (lowerName.ndashes == 14 &&
FontParseXLFDName (zeroChars, &vals, FONT_XLFD_REPLACE_ZERO))
{
@@ -940,7 +941,7 @@ FontFileListOneFontWithInfo (pointer client, FontPathElementPtr fpe,
entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, &vals);
if (entry)
{
- strcpy(lowerName, entry->name.name);
+ strlcpy(lowerName, entry->name.name, sizeof(lowerName));
tmpName.name = lowerName;
tmpName.length = entry->name.length;
tmpName.ndashes = entry->name.ndashes;
@@ -1008,8 +1009,8 @@ FontFileListOneFontWithInfo (pointer client, FontPathElementPtr fpe,
sizeof(fileName)) {
ret = BadFontName;
} else {
- strcpy (fileName, dir->directory);
- strcat (fileName, scalable->fileName);
+ strlcpy (fileName, dir->directory, sizeof(fileName));
+ strlcat (fileName, scalable->fileName, sizeof(fileName));
if (scalable->renderer->GetInfoScalable)
ret = (*scalable->renderer->GetInfoScalable)
(fpe, *pFontInfo, entry, &tmpName, fileName,