From 6e664f49b1aa60edf2e328b0df4d7e67e594184c Mon Sep 17 00:00:00 2001 From: Frank Gevaerts Date: Sun, 27 Nov 2011 15:36:03 +0000 Subject: [PATCH] Guard font functions against invalid font ids. These arguably should never be passed, but this prevents freezes. Fixes FS#12400 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31075 a1c6a512-1295-4272-9138-f99709370657 --- firmware/font.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/firmware/font.c b/firmware/font.c index d8f8c59e0d..2b86d338db 100644 --- a/firmware/font.c +++ b/firmware/font.c @@ -135,7 +135,7 @@ static void lock_font_handle(int handle, bool lock) void font_lock(int font_id, bool lock) { - if( font_id == FONT_SYSFIXED ) + if( font_id < 0 || font_id >= MAXFONTS ) return; if( buflib_allocations[font_id] >= 0 ) lock_font_handle(buflib_allocations[font_id], lock); @@ -340,6 +340,8 @@ static int find_font_index(const char* path) const char* font_filename(int font_id) { + if ( font_id < 0 || font_id >= MAXFONTS ) + return NULL; int handle = buflib_allocations[font_id]; if (handle > 0) return core_get_name(handle); @@ -582,7 +584,7 @@ int font_load(const char *path) void font_unload(int font_id) { - if ( font_id == FONT_SYSFIXED ) + if ( font_id < 0 || font_id >= MAXFONTS ) return; int handle = buflib_allocations[font_id]; if ( handle < 0 )