summaryrefslogtreecommitdiff
path: root/src/fontfile
diff options
context:
space:
mode:
Diffstat (limited to 'src/fontfile')
-rw-r--r--src/fontfile/dirfile.c29
-rw-r--r--src/fontfile/fontdir.c9
-rw-r--r--src/fontfile/fontfile.c25
3 files changed, 33 insertions, 30 deletions
diff --git a/src/fontfile/dirfile.c b/src/fontfile/dirfile.c
index 2802980..58ca491 100644
--- a/src/fontfile/dirfile.c
+++ b/src/fontfile/dirfile.c
@@ -45,6 +45,7 @@ in this Software without prior written authorization from The Open Group.
#include <fcntl.h>
#include <errno.h>
#include <limits.h>
+#include "src/util/replace.h"
static Bool AddFileNameAliases ( FontDirectoryPtr dir );
static int ReadFontAlias ( char *directory, Bool isFile,
@@ -88,12 +89,12 @@ FontFileReadDirectory (const char *directory, FontDirectoryPtr *pdir)
strncpy(dir_path, directory, ptr - directory);
dir_path[ptr - directory] = '\0';
} else {
- strcpy(dir_path, directory);
+ strlcpy(dir_path, directory, sizeof(dir_path));
}
- strcpy(dir_file, dir_path);
+ strlcpy(dir_file, dir_path, sizeof(dir_file));
if (dir_file[strlen(dir_file) - 1] != '/')
- strcat(dir_file, "/");
- strcat(dir_file, FontDirFile);
+ strlcat(dir_file, "/", sizeof(dir_file));
+ strlcat(dir_file, FontDirFile, sizeof(dir_file));
#ifndef WIN32
file_fd = open(dir_file, O_RDONLY | O_NOFOLLOW);
if (file_fd >= 0) {
@@ -124,8 +125,8 @@ FontFileReadDirectory (const char *directory, FontDirectoryPtr *pdir)
}
dir->dir_mtime = statb.st_mtime;
if (format[0] == '\0')
- sprintf(format, "%%%ds %%%d[^\n]\n",
- MAXFONTFILENAMELEN-1, MAXFONTNAMELEN-1);
+ snprintf(format, sizeof(format), "%%%ds %%%d[^\n]\n",
+ MAXFONTFILENAMELEN-1, MAXFONTNAMELEN-1);
while ((count = fscanf(file, format, file_name, font_name)) != EOF) {
#if defined(WIN32)
@@ -176,8 +177,8 @@ FontFileDirectoryChanged(FontDirectoryPtr dir)
if (strlen(dir->directory) + sizeof(FontDirFile) > sizeof(dir_file))
return FALSE;
- strcpy (dir_file, dir->directory);
- strcat (dir_file, FontDirFile);
+ strlcpy (dir_file, dir->directory, sizeof(dir_file));
+ strlcat (dir_file, FontDirFile, sizeof(dir_file));
if (stat (dir_file, &statb) == -1)
{
if (errno != ENOENT || dir->dir_mtime != 0)
@@ -189,8 +190,8 @@ FontFileDirectoryChanged(FontDirectoryPtr dir)
if ((strlen(dir->directory) + sizeof(FontAliasFile)) > sizeof(dir_file))
return FALSE;
- strcpy (dir_file, dir->directory);
- strcat (dir_file, FontAliasFile);
+ strlcpy (dir_file, dir->directory, sizeof(dir_file));
+ strlcat (dir_file, FontAliasFile, sizeof(dir_file));
if (stat (dir_file, &statb) == -1)
{
if (errno != ENOENT || dir->alias_mtime != 0)
@@ -282,13 +283,13 @@ ReadFontAlias(char *directory, Bool isFile, FontDirectoryPtr *pdir)
if (strlen(directory) >= sizeof(alias_file))
return BadFontPath;
dir = *pdir;
- strcpy(alias_file, directory);
+ strlcpy(alias_file, directory, sizeof(alias_file));
if (!isFile) {
if (strlen(directory) + 1 + sizeof(FontAliasFile) > sizeof(alias_file))
return BadFontPath;
if (directory[strlen(directory) - 1] != '/')
- strcat(alias_file, "/");
- strcat(alias_file, FontAliasFile);
+ strlcat(alias_file, "/", sizeof(alias_file));
+ strlcat(alias_file, FontAliasFile, sizeof(alias_file));
}
#ifndef WIN32
@@ -335,7 +336,7 @@ ReadFontAlias(char *directory, Bool isFile, FontDirectoryPtr *pdir)
status = BadFontPath;
break;
}
- strcpy(alias, lexToken);
+ strlcpy(alias, lexToken, sizeof(alias));
token = lexAlias(file, &lexToken);
switch (token) {
case NEWLINE:
diff --git a/src/fontfile/fontdir.c b/src/fontfile/fontdir.c
index 996b7d1..2cc97b4 100644
--- a/src/fontfile/fontdir.c
+++ b/src/fontfile/fontdir.c
@@ -34,6 +34,7 @@ in this Software without prior written authorization from The Open Group.
#include "libxfontint.h"
#include <X11/fonts/fntfilst.h>
#include <X11/keysym.h>
+#include "src/util/replace.h"
#if HAVE_STDINT_H
#include <stdint.h>
@@ -152,11 +153,11 @@ FontFileMakeDir(const char *dirName, int size)
else
dir->attributes = NULL;
strncpy(dir->directory, dirName, dirlen);
- dir->directory[dirlen] = '\0';
- if (dir->attributes)
- strcpy(dir->attributes, attrib);
if (needslash)
- strcat(dir->directory, "/");
+ dir->directory[dirlen] = '/';
+ dir->directory[dirlen + needslash] = '\0';
+ if (dir->attributes)
+ strlcpy(dir->attributes, attrib, attriblen + 1);
return dir;
}
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,