From 8bf58c3b531bfa32b00165ea04c6254f0da247e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 27 Feb 2009 21:11:05 +0000 Subject: [PATCH] Specify the maximum signature buffer size to prevent unwanted overflow. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29338 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/FontCache.cpp | 5 +++-- src/servers/app/FontCacheEntry.cpp | 5 +++-- src/servers/app/FontCacheEntry.h | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/servers/app/FontCache.cpp b/src/servers/app/FontCache.cpp index 2ca56a2ff1..c27b153a47 100644 --- a/src/servers/app/FontCache.cpp +++ b/src/servers/app/FontCache.cpp @@ -52,8 +52,9 @@ FontCache::Default() FontCacheEntry* FontCache::FontCacheEntryFor(const ServerFont& font) { - char signature[512]; - FontCacheEntry::GenerateSignature(signature, font); + static const size_t signatureSize = 512; + char signature[signatureSize]; + FontCacheEntry::GenerateSignature(signature, signatureSize, font); AutoReadLocker readLocker(this); diff --git a/src/servers/app/FontCacheEntry.cpp b/src/servers/app/FontCacheEntry.cpp index 935e5e27cf..f796875be1 100644 --- a/src/servers/app/FontCacheEntry.cpp +++ b/src/servers/app/FontCacheEntry.cpp @@ -217,7 +217,8 @@ FontCacheEntry::GetKerning(uint16 glyphCode1, uint16 glyphCode2, // GenerateSignature /*static*/ void -FontCacheEntry::GenerateSignature(char* signature, const ServerFont& font) +FontCacheEntry::GenerateSignature(char* signature, size_t signatureSize, + const ServerFont& font) { glyph_rendering renderingType = _RenderTypeFor(font); @@ -226,7 +227,7 @@ FontCacheEntry::GenerateSignature(char* signature, const ServerFont& font) bool hinting = font.Hinting(); uint8 averageWeight = gSubpixelAverageWeight; - sprintf(signature, "%ld,%u,%d,%d,%.1f,%d,%d", + snprintf(signature, signatureSize, "%ld,%u,%d,%d,%.1f,%d,%d", font.GetFamilyAndStyle(), charMap, font.Face(), int(renderingType), font.Size(), hinting, averageWeight); } diff --git a/src/servers/app/FontCacheEntry.h b/src/servers/app/FontCacheEntry.h index 1d0e936148..954fe481ec 100644 --- a/src/servers/app/FontCacheEntry.h +++ b/src/servers/app/FontCacheEntry.h @@ -93,6 +93,7 @@ class FontCacheEntry : public MultiLocker, public Referenceable { uint16 glyphCode2, double* x, double* y); static void GenerateSignature(char* signature, + size_t signatureSize, const ServerFont& font); // private to FontCache class: