From 21e9bfc83ef5e3f8fcbc77efa3578daec4d408c4 Mon Sep 17 00:00:00 2001 From: Sergey Bylokhov Date: Tue, 18 Mar 2014 18:11:41 +0400 Subject: [PATCH] 8008114: [parfait] False positive buffer overrun in jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_LinuxOS_ALSA_MidiUtils.c Reviewed-by: anthony, prr --- .../com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiUtils.c | 5 +++-- .../com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_PCMUtils.c | 5 +++-- .../sun/media/sound/PLATFORM_API_LinuxOS_ALSA_MidiUtils.c | 5 +++-- .../com/sun/media/sound/PLATFORM_API_LinuxOS_ALSA_PCMUtils.c | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiUtils.c b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiUtils.c index c12bed9260c..086b37487f7 100644 --- a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiUtils.c +++ b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_MidiUtils.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -229,8 +229,9 @@ static int deviceInfoIterator(UINT32 deviceID, snd_rawmidi_info_t *rawmidi_info, desc->deviceID = deviceID; buffer[0]=' '; buffer[1]='['; + // buffer[300] is enough to store the actual device string w/o overrun getDeviceStringFromDeviceID(&buffer[2], deviceID, usePlugHw, ALSA_RAWMIDI); - strcat(buffer, "]"); + strncat(buffer, "]", sizeof(buffer) - strlen(buffer) - 1); strncpy(desc->name, (cardinfo != NULL) ? snd_ctl_card_info_get_id(cardinfo) diff --git a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_PCMUtils.c b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_PCMUtils.c index 9abd53a0f8e..6660047e4e3 100644 --- a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_PCMUtils.c +++ b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_BsdOS_ALSA_PCMUtils.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -184,8 +184,9 @@ int deviceInfoIterator(UINT32 deviceID, snd_pcm_info_t* pcminfo, 1 : snd_pcm_info_get_subdevices_count(pcminfo); *desc->deviceID = deviceID; buffer[0]=' '; buffer[1]='['; + // buffer[300] is enough to store the actual device string w/o overrun getDeviceStringFromDeviceID(&buffer[2], deviceID, usePlugHw, ALSA_PCM); - strcat(buffer, "]"); + strncat(buffer, "]", sizeof(buffer) - strlen(buffer) - 1); strncpy(desc->name, (cardinfo != NULL) ? snd_ctl_card_info_get_id(cardinfo) diff --git a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_LinuxOS_ALSA_MidiUtils.c b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_LinuxOS_ALSA_MidiUtils.c index 7d2ac119234..14475413f1c 100644 --- a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_LinuxOS_ALSA_MidiUtils.c +++ b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_LinuxOS_ALSA_MidiUtils.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -229,8 +229,9 @@ static int deviceInfoIterator(UINT32 deviceID, snd_rawmidi_info_t *rawmidi_info, desc->deviceID = deviceID; buffer[0]=' '; buffer[1]='['; + // buffer[300] is enough to store the actual device string w/o overrun getDeviceStringFromDeviceID(&buffer[2], deviceID, usePlugHw, ALSA_RAWMIDI); - strcat(buffer, "]"); + strncat(buffer, "]", sizeof(buffer) - strlen(buffer) - 1); strncpy(desc->name, (cardinfo != NULL) ? snd_ctl_card_info_get_id(cardinfo) diff --git a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_LinuxOS_ALSA_PCMUtils.c b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_LinuxOS_ALSA_PCMUtils.c index c9f12176d86..da7b9a84745 100644 --- a/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_LinuxOS_ALSA_PCMUtils.c +++ b/jdk/src/solaris/native/com/sun/media/sound/PLATFORM_API_LinuxOS_ALSA_PCMUtils.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -184,8 +184,9 @@ int deviceInfoIterator(UINT32 deviceID, snd_pcm_info_t* pcminfo, 1 : snd_pcm_info_get_subdevices_count(pcminfo); *desc->deviceID = deviceID; buffer[0]=' '; buffer[1]='['; + // buffer[300] is enough to store the actual device string w/o overrun getDeviceStringFromDeviceID(&buffer[2], deviceID, usePlugHw, ALSA_PCM); - strcat(buffer, "]"); + strncat(buffer, "]", sizeof(buffer) - strlen(buffer) - 1); strncpy(desc->name, (cardinfo != NULL) ? snd_ctl_card_info_get_id(cardinfo)