From 3dd3cd4ceb4666e3e1030c45e0ccd94f810a797b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 8 Feb 2008 15:33:26 -0800 Subject: Prevent overflow of the device lists --- Alc/ALc.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'Alc') diff --git a/Alc/ALc.c b/Alc/ALc.c index 714a142f..c8060f49 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -262,25 +262,40 @@ static void InitAL(void) ALCchar *AppendDeviceList(char *name) { - static int pos; + static size_t pos; ALCchar *ret = alcDeviceList+pos; - pos += snprintf(alcDeviceList+pos, sizeof(alcDeviceList)-pos, "%s", name) + 1; + if(pos >= sizeof(alcDeviceList)) + { + AL_PRINT("Not enough room to add %s!\n", name); + return alcDeviceList + sizeof(alcDeviceList) - 1; + } + pos += snprintf(alcDeviceList+pos, sizeof(alcDeviceList)-pos-1, "%s", name) + 1; return ret; } ALCchar *AppendAllDeviceList(char *name) { - static int pos; + static size_t pos; ALCchar *ret = alcAllDeviceList+pos; - pos += snprintf(alcAllDeviceList+pos, sizeof(alcAllDeviceList)-pos, "%s", name) + 1; + if(pos >= sizeof(alcAllDeviceList)) + { + AL_PRINT("Not enough room to add %s!\n", name); + return alcAllDeviceList + sizeof(alcAllDeviceList) - 1; + } + pos += snprintf(alcAllDeviceList+pos, sizeof(alcAllDeviceList)-pos-1, "%s", name) + 1; return ret; } ALCchar *AppendCaptureDeviceList(char *name) { - static int pos; + static size_t pos; ALCchar *ret = alcCaptureDeviceList+pos; - pos += snprintf(alcCaptureDeviceList+pos, sizeof(alcCaptureDeviceList)-pos, "%s", name) + 1; + if(pos >= sizeof(alcCaptureDeviceList)) + { + AL_PRINT("Not enough room to add %s!\n", name); + return alcCaptureDeviceList + sizeof(alcCaptureDeviceList) - 1; + } + pos += snprintf(alcCaptureDeviceList+pos, sizeof(alcCaptureDeviceList)-pos-1, "%s", name) + 1; return ret; } -- cgit v1.2.3