Use length-bounded string/memory functions (#7709)
Resolves #3949 by replacing all calls to sprintf() and strcpy() in first-party code with calls to snprintf() or some other reasonable alternative.
This commit is contained in:
@@ -4,44 +4,24 @@
|
||||
#include <math.h>
|
||||
#include "base.h"
|
||||
|
||||
int sp_create(sp_data **spp)
|
||||
{
|
||||
*spp = (sp_data *) malloc(sizeof(sp_data));
|
||||
sp_data *sp = *spp;
|
||||
sprintf(sp->filename, "test.wav");
|
||||
sp->nchan = 1;
|
||||
SPFLOAT *out = malloc(sizeof(SPFLOAT) * sp->nchan);
|
||||
*out = 0;
|
||||
sp->out = out;
|
||||
sp->sr = 44100;
|
||||
sp->len = 5 * sp->sr;
|
||||
sp->pos = 0;
|
||||
sp->rand = 0;
|
||||
return 0;
|
||||
}
|
||||
int sp_create(sp_data **spp) { return sp_createn(spp, 1); }
|
||||
|
||||
int sp_createn(sp_data **spp, int nchan)
|
||||
{
|
||||
*spp = (sp_data *) malloc(sizeof(sp_data));
|
||||
sp_data *sp = *spp;
|
||||
sprintf(sp->filename, "test.wav");
|
||||
sp->nchan = nchan;
|
||||
SPFLOAT *out = malloc(sizeof(SPFLOAT) * sp->nchan);
|
||||
*out = 0;
|
||||
sp->out = out;
|
||||
sp->sr = 44100;
|
||||
sp->len = 5 * sp->sr;
|
||||
sp->pos = 0;
|
||||
sp->rand = 0;
|
||||
return 0;
|
||||
const uint32_t sr = 44100; // TODO C23: constexpr auto
|
||||
const unsigned long len_seconds = 5; // TODO C23: constexpr auto
|
||||
*spp = malloc(sizeof(sp_data));
|
||||
**spp = (sp_data){ .out = calloc(nchan, sizeof(float)), .sr = sr,
|
||||
.nchan = nchan, .len = len_seconds * sr, .pos = 0,
|
||||
.filename = "test.wav", .rand = 0 };
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sp_destroy(sp_data **spp)
|
||||
{
|
||||
sp_data *sp = *spp;
|
||||
free(sp->out);
|
||||
free(*spp);
|
||||
return 0;
|
||||
free((*spp)->out);
|
||||
free(*spp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef NO_LIBSNDFILE
|
||||
@@ -61,7 +41,7 @@ int sp_process(sp_data *sp, void *ud, void (*callback)(sp_data *, void *))
|
||||
sf[0] = sf_open(sp->filename, SFM_WRITE, &info);
|
||||
} else {
|
||||
for(chan = 0; chan < sp->nchan; chan++) {
|
||||
sprintf(tmp, "%02d_%s", chan, sp->filename);
|
||||
snprintf(tmp, sizeof(tmp), "%02d_%s", chan, sp->filename);
|
||||
sf[chan] = sf_open(tmp, SFM_WRITE, &info);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "lmmsconfig.h"
|
||||
|
||||
@@ -1010,13 +1011,14 @@ bool RemoteVstPlugin::load( const std::string & _plugin_file )
|
||||
return false;
|
||||
}
|
||||
|
||||
const char id[5] = {
|
||||
static_cast<char>(m_plugin->uniqueID >> 24),
|
||||
static_cast<char>(m_plugin->uniqueID >> 16),
|
||||
static_cast<char>(m_plugin->uniqueID >> 8),
|
||||
static_cast<char>(m_plugin->uniqueID ),
|
||||
0
|
||||
};
|
||||
|
||||
char id[5];
|
||||
sprintf( id, "%c%c%c%c", ((char *)&m_plugin->uniqueID)[3],
|
||||
((char *)&m_plugin->uniqueID)[2],
|
||||
((char *)&m_plugin->uniqueID)[1],
|
||||
((char *)&m_plugin->uniqueID)[0] );
|
||||
id[4] = 0;
|
||||
sendMessage( message( IdVstPluginUniqueID ).addString( id ) );
|
||||
|
||||
pluginDispatch( effOpen );
|
||||
@@ -1244,10 +1246,14 @@ void RemoteVstPlugin::getParameterLabels()
|
||||
|
||||
void RemoteVstPlugin::sendCurrentProgramName()
|
||||
{
|
||||
char presName[64];
|
||||
sprintf( presName, "%d/%d: %s", pluginDispatch( effGetProgram ) + 1, m_plugin->numPrograms, programName() );
|
||||
|
||||
sendMessage( message( IdVstCurrentProgramName ).addString( presName ) );
|
||||
char presName[64] = {};
|
||||
std::snprintf(presName, sizeof(presName),
|
||||
"%d/%d: %s",
|
||||
pluginDispatch(effGetProgram) + 1,
|
||||
m_plugin->numPrograms,
|
||||
programName()
|
||||
);
|
||||
sendMessage(message(IdVstCurrentProgramName).addString(presName));
|
||||
}
|
||||
|
||||
|
||||
@@ -1372,36 +1378,46 @@ void RemoteVstPlugin::rotateProgram( int offset )
|
||||
|
||||
void RemoteVstPlugin::getProgramNames()
|
||||
{
|
||||
char presName[1024+256*30];
|
||||
char curProgName[30];
|
||||
if (isInitialized() == false) return;
|
||||
bool progNameIndexed = pluginDispatch(effGetProgramNameIndexed, 0, -1, curProgName) == 1;
|
||||
char presName[1024 + 256 * 30] = {};
|
||||
char curProgName[30] = {};
|
||||
if (!isInitialized()) { return; }
|
||||
const bool progNameIndexed = pluginDispatch(effGetProgramNameIndexed, 0, -1, curProgName) == 1;
|
||||
|
||||
if (m_plugin->numPrograms > 1) {
|
||||
if (progNameIndexed) {
|
||||
for (int i = 0; i< (m_plugin->numPrograms >= 256?256:m_plugin->numPrograms); i++)
|
||||
if (m_plugin->numPrograms > 1)
|
||||
{
|
||||
const auto maxPrograms = std::min(m_plugin->numPrograms, 256);
|
||||
if (progNameIndexed)
|
||||
{
|
||||
for (int i = 0; i < maxPrograms; i++)
|
||||
{
|
||||
pluginDispatch(effGetProgramNameIndexed, i, -1, curProgName);
|
||||
if (i == 0) sprintf( presName, "%s", curProgName );
|
||||
else sprintf( presName + strlen(presName), "|%s", curProgName );
|
||||
if (i == 0) { std::snprintf(presName, sizeof(presName), "%s", curProgName); }
|
||||
else
|
||||
{
|
||||
const auto len = std::strlen(presName);
|
||||
std::snprintf(presName + len, sizeof(presName) - len, "|%s", curProgName);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int currProgram = pluginDispatch( effGetProgram );
|
||||
for (int i = 0; i< (m_plugin->numPrograms >= 256?256:m_plugin->numPrograms); i++)
|
||||
const int currProgram = pluginDispatch(effGetProgram);
|
||||
for (int i = 0; i < maxPrograms; i++)
|
||||
{
|
||||
pluginDispatch( effSetProgram, 0, i );
|
||||
if (i == 0) sprintf( presName, "%s", programName() );
|
||||
else sprintf( presName + strlen(presName), "|%s", programName() );
|
||||
pluginDispatch(effSetProgram, 0, i);
|
||||
if (i == 0) { std::snprintf(presName, sizeof(presName), "%s", programName()); }
|
||||
else
|
||||
{
|
||||
const auto len = std::strlen(presName);
|
||||
std::snprintf(presName + len, sizeof(presName) - len, "|%s", programName());
|
||||
}
|
||||
}
|
||||
pluginDispatch( effSetProgram, 0, currProgram );
|
||||
pluginDispatch(effSetProgram, 0, currProgram);
|
||||
}
|
||||
} else sprintf( presName, "%s", programName() );
|
||||
}
|
||||
else { std::snprintf(presName, sizeof(presName), "%s", programName()); }
|
||||
|
||||
presName[sizeof(presName)-1] = 0;
|
||||
|
||||
sendMessage( message( IdVstProgramNames ).addString( presName ) );
|
||||
sendMessage(message(IdVstProgramNames).addString(presName));
|
||||
}
|
||||
|
||||
|
||||
@@ -1725,19 +1741,12 @@ int RemoteVstPlugin::updateInOutCount()
|
||||
|
||||
setInputOutputCount( inputCount(), outputCount() );
|
||||
|
||||
char buf[64];
|
||||
sprintf( buf, "inputs: %d output: %d\n", inputCount(), outputCount() );
|
||||
debugMessage( buf );
|
||||
char buf[64] = {};
|
||||
std::snprintf(buf, sizeof(buf), "inputs: %d; outputs: %d\n", inputCount(), outputCount());
|
||||
debugMessage(buf);
|
||||
|
||||
if( inputCount() > 0 )
|
||||
{
|
||||
m_inputs = new float * [inputCount()];
|
||||
}
|
||||
|
||||
if( outputCount() > 0 )
|
||||
{
|
||||
m_outputs = new float * [outputCount()];
|
||||
}
|
||||
if (inputCount() > 0) { m_inputs = new float*[inputCount()]; }
|
||||
if (outputCount() > 0) { m_outputs = new float*[outputCount()]; }
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1765,9 +1774,9 @@ intptr_t RemoteVstPlugin::hostCallback( AEffect * _effect, int32_t _opcode,
|
||||
{
|
||||
static VstTimeInfo _timeInfo;
|
||||
#ifdef DEBUG_CALLBACKS
|
||||
char buf[64];
|
||||
sprintf( buf, "host-callback, opcode = %d\n", (int) _opcode );
|
||||
SHOW_CALLBACK( buf );
|
||||
char buf[64] = {};
|
||||
std::snprintf(buf, sizeof(buf), "host-callback, opcode = %d\n", static_cast<int>(_opcode));
|
||||
SHOW_CALLBACK(buf);
|
||||
#endif
|
||||
|
||||
// workaround for early callbacks by some plugins
|
||||
@@ -1776,6 +1785,7 @@ intptr_t RemoteVstPlugin::hostCallback( AEffect * _effect, int32_t _opcode,
|
||||
__plugin->m_plugin = _effect;
|
||||
}
|
||||
|
||||
const auto p = static_cast<char*>(_ptr);
|
||||
switch( _opcode )
|
||||
{
|
||||
case audioMasterAutomate:
|
||||
@@ -2070,15 +2080,14 @@ intptr_t RemoteVstPlugin::hostCallback( AEffect * _effect, int32_t _opcode,
|
||||
SHOW_CALLBACK( "amc: audioMasterGetVendorString\n" );
|
||||
// fills <ptr> with a string identifying the vendor
|
||||
// (max 64 char)
|
||||
strcpy( (char *) _ptr, "Tobias Doerffel" );
|
||||
std::strcpy(p, "Tobias Doerffel");
|
||||
return 1;
|
||||
|
||||
case audioMasterGetProductString:
|
||||
SHOW_CALLBACK( "amc: audioMasterGetProductString\n" );
|
||||
// fills <ptr> with a string with product name
|
||||
// (max 64 char)
|
||||
strcpy( (char *) _ptr,
|
||||
"LMMS VST Support Layer (LVSL)" );
|
||||
std::strcpy(p, "LMMS VST Support Layer (LVSL)");
|
||||
return 1;
|
||||
|
||||
case audioMasterGetVendorVersion:
|
||||
@@ -2092,12 +2101,12 @@ intptr_t RemoteVstPlugin::hostCallback( AEffect * _effect, int32_t _opcode,
|
||||
return 0;
|
||||
|
||||
case audioMasterCanDo:
|
||||
SHOW_CALLBACK( "amc: audioMasterCanDo\n" );
|
||||
return !strcmp( (char *) _ptr, "sendVstEvents" ) ||
|
||||
!strcmp( (char *) _ptr, "sendVstMidiEvent" ) ||
|
||||
!strcmp( (char *) _ptr, "sendVstTimeInfo" ) ||
|
||||
!strcmp( (char *) _ptr, "sizeWindow" ) ||
|
||||
!strcmp( (char *) _ptr, "supplyIdle" );
|
||||
SHOW_CALLBACK("amc: audioMasterCanDo\n");
|
||||
return !(std::strcmp(p, "sendVstEvents")
|
||||
&& std::strcmp(p, "sendVstMidiEvent")
|
||||
&& std::strcmp(p, "sendVstTimeInfo")
|
||||
&& std::strcmp(p, "sizeWindow")
|
||||
&& std::strcmp(p, "supplyIdle"));
|
||||
|
||||
case audioMasterGetLanguage:
|
||||
SHOW_CALLBACK( "amc: audioMasterGetLanguage\n" );
|
||||
|
||||
Reference in New Issue
Block a user