mirror of
https://github.com/fwbuilder/fwbuilder
synced 2026-09-14 17:09:11 +02:00
Fixes #2182.
Convert use of sprintf to snprintf (hopefully in a way that also works on windows).
This commit is contained in:
@@ -462,9 +462,8 @@ void CompilerDriver::commonChecks2(Cluster *cluster, Firewall *fw)
|
|||||||
|
|
||||||
if (!iface->isDyn())
|
if (!iface->isDyn())
|
||||||
{
|
{
|
||||||
char errstr[256];
|
QString errstr;
|
||||||
sprintf(errstr,
|
errstr.sprintf(_("Wildcard interface '%s' must be dynamic."),
|
||||||
_("Wildcard interface '%s' must be dynamic."),
|
|
||||||
iface->getName().c_str() );
|
iface->getName().c_str() );
|
||||||
throw FWException(errstr);
|
throw FWException(errstr);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ using namespace libfwbuilder;
|
|||||||
int id_seed = 1000;
|
int id_seed = 1000;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static int cached_pid = _getpid();
|
static int cached_pid = _getpid();
|
||||||
|
#define snprintf sprintf_s
|
||||||
#else
|
#else
|
||||||
static int cached_pid = getpid();
|
static int cached_pid = getpid();
|
||||||
#endif
|
#endif
|
||||||
@@ -211,7 +212,7 @@ string FWObjectDatabase::getStringId(int i_id)
|
|||||||
|
|
||||||
// TODO: Use proper GUID algorithm here
|
// TODO: Use proper GUID algorithm here
|
||||||
char id_buf[64];
|
char id_buf[64];
|
||||||
sprintf(id_buf, "id%dX%d", i_id, cached_pid);
|
snprintf(id_buf, sizeof(id_buf), "id%dX%d", i_id, cached_pid);
|
||||||
id_dict[i_id] = string(id_buf);
|
id_dict[i_id] = string(id_buf);
|
||||||
id_dict_reverse[string(id_buf)] = i_id;
|
id_dict_reverse[string(id_buf)] = i_id;
|
||||||
return id_dict[i_id];
|
return id_dict[i_id];
|
||||||
|
|||||||
@@ -48,6 +48,9 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace libfwbuilder;
|
using namespace libfwbuilder;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define snprintf sprintf_s
|
||||||
|
#endif
|
||||||
|
|
||||||
class FWObjectTreeScanner {
|
class FWObjectTreeScanner {
|
||||||
|
|
||||||
@@ -492,7 +495,7 @@ FWObject* FWObjectDatabase::recursivelyCopySubtree(FWObject *target,
|
|||||||
std::map<int,int> &id_map)
|
std::map<int,int> &id_map)
|
||||||
{
|
{
|
||||||
char s[64];
|
char s[64];
|
||||||
sprintf(s, ".copy_of_%p", source->getRoot());
|
snprintf(s, sizeof(s), ".copy_of_%p", source->getRoot());
|
||||||
string dedup_attribute = s;
|
string dedup_attribute = s;
|
||||||
|
|
||||||
FWObject *nobj = _recursively_copy_subtree(target, source, id_map,
|
FWObject *nobj = _recursively_copy_subtree(target, source, id_map,
|
||||||
@@ -599,7 +602,7 @@ FWObject* FWObjectDatabase::_recursively_copy_subtree(
|
|||||||
|
|
||||||
// Check if we have already copied the same object before
|
// Check if we have already copied the same object before
|
||||||
char s[64];
|
char s[64];
|
||||||
sprintf(s, "%d", old_ptr_obj->getId());
|
snprintf(s, sizeof(s), "%d", old_ptr_obj->getId());
|
||||||
n_ptr_obj = findObjectByAttribute(dedup_attribute, s);
|
n_ptr_obj = findObjectByAttribute(dedup_attribute, s);
|
||||||
if (n_ptr_obj)
|
if (n_ptr_obj)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,6 +33,10 @@
|
|||||||
using namespace libfwbuilder;
|
using namespace libfwbuilder;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define snprintf sprintf_s
|
||||||
|
#endif
|
||||||
|
|
||||||
const char *TCPUDPService::TYPENAME={"TCPUDPService"};
|
const char *TCPUDPService::TYPENAME={"TCPUDPService"};
|
||||||
|
|
||||||
TCPUDPService::TCPUDPService()
|
TCPUDPService::TCPUDPService()
|
||||||
@@ -93,14 +97,14 @@ xmlNodePtr TCPUDPService::toXML(xmlNodePtr xml_parent_node) throw(FWException)
|
|||||||
|
|
||||||
char str[128];
|
char str[128];
|
||||||
|
|
||||||
sprintf(str,"%d",src_range_start);
|
snprintf(str, sizeof(str), "%d", src_range_start);
|
||||||
xmlNewProp(me, TOXMLCAST("src_range_start"), TOXMLCAST(str));
|
xmlNewProp(me, TOXMLCAST("src_range_start"), TOXMLCAST(str));
|
||||||
sprintf(str,"%d",src_range_end);
|
snprintf(str, sizeof(str), "%d", src_range_end);
|
||||||
xmlNewProp(me, TOXMLCAST("src_range_end"), TOXMLCAST(str));
|
xmlNewProp(me, TOXMLCAST("src_range_end"), TOXMLCAST(str));
|
||||||
|
|
||||||
sprintf(str,"%d",dst_range_start);
|
snprintf(str, sizeof(str), "%d", dst_range_start);
|
||||||
xmlNewProp(me, TOXMLCAST("dst_range_start"), TOXMLCAST(str));
|
xmlNewProp(me, TOXMLCAST("dst_range_start"), TOXMLCAST(str));
|
||||||
sprintf(str,"%d",dst_range_end);
|
snprintf(str, sizeof(str), "%d", dst_range_end);
|
||||||
xmlNewProp(me, TOXMLCAST("dst_range_end"), TOXMLCAST(str));
|
xmlNewProp(me, TOXMLCAST("dst_range_end"), TOXMLCAST(str));
|
||||||
|
|
||||||
return me;
|
return me;
|
||||||
|
|||||||
@@ -60,6 +60,10 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define snprintf sprintf_s
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define this if you need extra debug output.
|
* Define this if you need extra debug output.
|
||||||
*/
|
*/
|
||||||
@@ -69,18 +73,19 @@ using namespace std;
|
|||||||
using namespace libfwbuilder;
|
using namespace libfwbuilder;
|
||||||
|
|
||||||
/* Compiled OIDs */
|
/* Compiled OIDs */
|
||||||
const char *SNMPQuery::SNMP_INTERFACE_ASTATUS= ".1.3.6.1.2.1.2.2.1.7";
|
/* We use #define so the compiler can do string concatenation for snprintf */
|
||||||
const char *SNMPQuery::SNMP_INTERFACE_OSTATUS= ".1.3.6.1.2.1.2.2.1.8";
|
#define SNMP_INTERFACE_ASTATUS ".1.3.6.1.2.1.2.2.1.7"
|
||||||
const char *SNMPQuery::SNMP_INTERFACE_INDEX = ".1.3.6.1.2.1.2.2.1.1";
|
#define SNMP_INTERFACE_OSTATUS ".1.3.6.1.2.1.2.2.1.8"
|
||||||
const char *SNMPQuery::SNMP_INTERFACES_DESCR = ".1.3.6.1.2.1.2.2.1.2";
|
#define SNMP_INTERFACE_INDEX ".1.3.6.1.2.1.2.2.1.1"
|
||||||
const char *SNMPQuery::SNMP_INTERFACES_PHYSA = ".1.3.6.1.2.1.2.2.1.6";
|
#define SNMP_INTERFACES_DESCR ".1.3.6.1.2.1.2.2.1.2"
|
||||||
const char *SNMPQuery::SNMP_INTERFACES_TYPE = ".1.3.6.1.2.1.2.2.1.3";
|
#define SNMP_INTERFACES_PHYSA ".1.3.6.1.2.1.2.2.1.6"
|
||||||
const char *SNMPQuery::SNMP_ADDR_INDEX_TABLE = ".1.3.6.1.2.1.4.20.1.2";
|
#define SNMP_INTERFACES_TYPE ".1.3.6.1.2.1.2.2.1.3"
|
||||||
const char *SNMPQuery::SNMP_NMASK_TABLE = ".1.3.6.1.2.1.4.20.1.3";
|
#define SNMP_ADDR_INDEX_TABLE ".1.3.6.1.2.1.4.20.1.2"
|
||||||
const char *SNMPQuery::SNMP_ADDR_TABLE = ".1.3.6.1.2.1.4.20.1.1";
|
#define SNMP_NMASK_TABLE ".1.3.6.1.2.1.4.20.1.3"
|
||||||
const char *SNMPQuery::SNMP_BCAST_TABLE = ".1.3.6.1.2.1.4.20.1.4";
|
#define SNMP_ADDR_TABLE ".1.3.6.1.2.1.4.20.1.1"
|
||||||
const char *SNMPQuery::SNMP_AT_TABLE_NET = ".1.3.6.1.2.1.3.1.1.3";
|
#define SNMP_BCAST_TABLE ".1.3.6.1.2.1.4.20.1.4"
|
||||||
const char *SNMPQuery::SNMP_AT_TABLE_PHYS = ".1.3.6.1.2.1.3.1.1.2";
|
#define SNMP_AT_TABLE_NET ".1.3.6.1.2.1.3.1.1.3"
|
||||||
|
#define SNMP_AT_TABLE_PHYS ".1.3.6.1.2.1.3.1.1.2"
|
||||||
|
|
||||||
const char *SNMPQuery::SNMP_SYSNAME = ".1.3.6.1.2.1.1.5.0";
|
const char *SNMPQuery::SNMP_SYSNAME = ".1.3.6.1.2.1.1.5.0";
|
||||||
const char *SNMPQuery::SNMP_SYSDESCR = ".1.3.6.1.2.1.1.1.0";
|
const char *SNMPQuery::SNMP_SYSDESCR = ".1.3.6.1.2.1.1.1.0";
|
||||||
@@ -648,7 +653,7 @@ void SNMPQuery::fetchInterfaces(Logger *logger, SyncFlag *stop_program,
|
|||||||
char oid[1024];
|
char oid[1024];
|
||||||
|
|
||||||
// Get admin status
|
// Get admin status
|
||||||
sprintf(oid, "%s.%ld", SNMP_INTERFACE_ASTATUS , ifindex);
|
snprintf(oid, sizeof(oid), SNMP_INTERFACE_ASTATUS ".%ld", ifindex);
|
||||||
v=c->get(oid);
|
v=c->get(oid);
|
||||||
if(v.size()!=1)
|
if(v.size()!=1)
|
||||||
throw FWException(
|
throw FWException(
|
||||||
@@ -667,7 +672,7 @@ void SNMPQuery::fetchInterfaces(Logger *logger, SyncFlag *stop_program,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get operational status
|
// Get operational status
|
||||||
sprintf(oid, "%s.%ld", SNMP_INTERFACE_OSTATUS , ifindex);
|
snprintf(oid, sizeof(oid), SNMP_INTERFACE_OSTATUS ".%ld", ifindex);
|
||||||
v=c->get(oid);
|
v=c->get(oid);
|
||||||
if(v.size()!=1)
|
if(v.size()!=1)
|
||||||
throw FWException(
|
throw FWException(
|
||||||
@@ -679,7 +684,7 @@ void SNMPQuery::fetchInterfaces(Logger *logger, SyncFlag *stop_program,
|
|||||||
/* gather all information for interface ifindex and create Interface object */
|
/* gather all information for interface ifindex and create Interface object */
|
||||||
|
|
||||||
// Get desriptions
|
// Get desriptions
|
||||||
sprintf(oid,"%s.%ld", SNMP_INTERFACES_DESCR , ifindex);
|
snprintf(oid, sizeof(oid), SNMP_INTERFACES_DESCR ".%ld", ifindex);
|
||||||
v=c->get(oid);
|
v=c->get(oid);
|
||||||
string descr = SNMPVariable::varList2String(v);
|
string descr = SNMPVariable::varList2String(v);
|
||||||
SNMPVariable::freeVarList(v);
|
SNMPVariable::freeVarList(v);
|
||||||
@@ -687,7 +692,7 @@ void SNMPQuery::fetchInterfaces(Logger *logger, SyncFlag *stop_program,
|
|||||||
list<string> &addlist = addr[ifindex];
|
list<string> &addlist = addr[ifindex];
|
||||||
|
|
||||||
// Get physical address
|
// Get physical address
|
||||||
sprintf(oid, "%s.%ld", SNMP_INTERFACES_PHYSA , ifindex);
|
snprintf(oid, sizeof(oid), SNMP_INTERFACES_PHYSA ".%ld", ifindex);
|
||||||
v=c->get(oid);
|
v=c->get(oid);
|
||||||
if(v.size()!=1)
|
if(v.size()!=1)
|
||||||
throw FWException(string("Unexpected response length for OID: ")+oid);
|
throw FWException(string("Unexpected response length for OID: ")+oid);
|
||||||
@@ -697,7 +702,7 @@ void SNMPQuery::fetchInterfaces(Logger *logger, SyncFlag *stop_program,
|
|||||||
SNMPVariable::freeVarList(v);
|
SNMPVariable::freeVarList(v);
|
||||||
|
|
||||||
// Get type
|
// Get type
|
||||||
sprintf(oid,"%s.%ld", SNMP_INTERFACES_TYPE , ifindex);
|
snprintf(oid, sizeof(oid), SNMP_INTERFACES_TYPE ".%ld", ifindex);
|
||||||
v=c->get(oid);
|
v=c->get(oid);
|
||||||
if(v.size()!=1)
|
if(v.size()!=1)
|
||||||
throw FWException(string("Unexpected response length for OID: ")+oid);
|
throw FWException(string("Unexpected response length for OID: ")+oid);
|
||||||
@@ -1124,7 +1129,7 @@ SNMPVariable *SNMPVariable::create(struct variable_list *vars) throw(FWException
|
|||||||
return new SNMPVariable_IPaddr(vars->val.string, vars->val_len);
|
return new SNMPVariable_IPaddr(vars->val.string, vars->val_len);
|
||||||
default:
|
default:
|
||||||
char x[32];
|
char x[32];
|
||||||
sprintf(x, "%d", (int)vars->type);
|
snprintf(x, sizeof(x), "%d", (int)vars->type);
|
||||||
throw FWException(string("Unknown SNMP variable type: ") + x);
|
throw FWException(string("Unknown SNMP variable type: ") + x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1132,7 +1137,7 @@ SNMPVariable *SNMPVariable::create(struct variable_list *vars) throw(FWException
|
|||||||
string SNMPVariable_Int::toString()
|
string SNMPVariable_Int::toString()
|
||||||
{
|
{
|
||||||
char x[32];
|
char x[32];
|
||||||
sprintf(x, "%ld", value);
|
snprintf(x, sizeof(x), "%ld", value);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1143,10 +1148,10 @@ string SNMPVariable_Bits::toString()
|
|||||||
{
|
{
|
||||||
res += ".";
|
res += ".";
|
||||||
|
|
||||||
char x[8];
|
char x[12];
|
||||||
//TODO: now we print it in hex
|
//TODO: now we print it in hex
|
||||||
// we should print it in binary.
|
// we should print it in binary.
|
||||||
sprintf(x, "%d", (uint32_t)value[i]);
|
snprintf(x, sizeof(x), "%d", (uint32_t)value[i]);
|
||||||
//i += 4;
|
//i += 4;
|
||||||
res += x;
|
res += x;
|
||||||
}
|
}
|
||||||
@@ -1160,8 +1165,8 @@ string SNMPVariable_IPaddr::toString()
|
|||||||
{
|
{
|
||||||
if(i)
|
if(i)
|
||||||
res+=".";
|
res+=".";
|
||||||
char x[8];
|
char x[12];
|
||||||
sprintf(x,"%d", (unsigned int)value[i]);
|
snprintf(x, sizeof(x), "%d", (unsigned int)value[i]);
|
||||||
res+=x;
|
res+=x;
|
||||||
}
|
}
|
||||||
res+="]";
|
res+="]";
|
||||||
@@ -1205,7 +1210,7 @@ const string SNMPVariable_String::toHexString()
|
|||||||
res+=':';
|
res+=':';
|
||||||
u_char c=value[i];
|
u_char c=value[i];
|
||||||
char buf[16];
|
char buf[16];
|
||||||
sprintf(buf,"%02X",(unsigned int)c);
|
snprintf(buf, sizeof(buf), "%02X", (unsigned int)c);
|
||||||
res+=buf;
|
res+=buf;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
@@ -1214,14 +1219,14 @@ const string SNMPVariable_String::toHexString()
|
|||||||
string SNMPVariable_Counter64::toString()
|
string SNMPVariable_Counter64::toString()
|
||||||
{
|
{
|
||||||
char x[70];
|
char x[70];
|
||||||
sprintf(x,"[%ld:%ld]", (long)low, (long)high);
|
snprintf(x, sizeof(x), "[%ld:%ld]", (long)low, (long)high);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
string SNMPVariable_OID::toString()
|
string SNMPVariable_OID::toString()
|
||||||
{
|
{
|
||||||
char x[32];
|
char x[32];
|
||||||
sprintf(x,"%ld", (long)value);
|
snprintf(x, sizeof(x), "%ld", (long)value);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -231,13 +231,15 @@ void ObjectManipulator::pasteObj()
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Check if we have already copied the same object before
|
// Check if we have already copied the same object before
|
||||||
char s[64];
|
QString buff;
|
||||||
sprintf(s, ".copy_of_%p", co->getRoot());
|
buff.sprintf(".copy_of_%p", co->getRoot());
|
||||||
string dedup_attribute = s;
|
string dedup_attribute = buff.toAscii().constData();
|
||||||
|
|
||||||
sprintf(s, "%d", co->getId());
|
buff.sprintf("%d", co->getId());
|
||||||
|
QByteArray bytes = buff.toAscii();
|
||||||
FWObject *n_obj =
|
FWObject *n_obj =
|
||||||
target_object->getRoot()->findObjectByAttribute(dedup_attribute, s);
|
target_object->getRoot()->findObjectByAttribute(dedup_attribute,
|
||||||
|
bytes.constData());
|
||||||
if (n_obj) continue;
|
if (n_obj) continue;
|
||||||
|
|
||||||
last_object = actuallyPasteTo(target_object, co, map_ids);
|
last_object = actuallyPasteTo(target_object, co, map_ids);
|
||||||
|
|||||||
@@ -84,9 +84,8 @@ StartTipDialog::StartTipDialog(QWidget *parent): QDialog(parent)
|
|||||||
int tip_no = 1;
|
int tip_no = 1;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
char buf[64];
|
QString tip_file;
|
||||||
sprintf(buf, "tip%02d.html", tip_no);
|
tip_file.sprintf("tip%02d.html", tip_no);
|
||||||
QString tip_file = QString(buf);
|
|
||||||
QString contents;
|
QString contents;
|
||||||
if (fwbdebug)
|
if (fwbdebug)
|
||||||
qDebug("Trying tip file %s", tip_file.toAscii().constData());
|
qDebug("Trying tip file %s", tip_file.toAscii().constData());
|
||||||
|
|||||||
Reference in New Issue
Block a user