Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Fix sprintf vulnerabilities #1195

Merged
merged 22 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion converters/autotest/test_table2glm.glm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module climate;
object assert {
parent "weather";
target "wind_speed";
value 4 m/s;
value "+4 m/s";
}

object assert {
Expand Down
2 changes: 1 addition & 1 deletion converters/autotest/test_table2glm_noclass.glm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module climate;
object assert {
parent "weather";
target "wind_speed";
value 4 m/s;
value "+4 m/s";
}

object assert {
Expand Down
3 changes: 2 additions & 1 deletion module/assert/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ g_assert::g_assert(MODULE *module)
PT_DESCRIPTION, "a duration over which the assertion must be violated before failing",
NULL)<1){
char msg[256];
sprintf(msg, "unable to publish properties in %s",__FILE__);
snprintf(msg,sizeof(msg)-1, "unable to publish properties in %s",__FILE__);
throw msg;
}
}
Expand All @@ -87,6 +87,7 @@ int g_assert::create(void)
{
target_list = NULL;
started = TS_NEVER;
set_value2("0");
return 1; /* return 1 on success, 0 on failure */
}

Expand Down
2 changes: 1 addition & 1 deletion module/assert/int_assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int_assert::int_assert(MODULE *module)
PT_char1024, "target", get_target_offset(),
NULL)<1){
char msg[256];
sprintf(msg, "unable to publish properties in %s",__FILE__);
snprintf(msg,sizeof(msg)-1, "unable to publish properties in %s",__FILE__);
throw msg;
}
}
Expand Down
4 changes: 2 additions & 2 deletions module/climate/climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ climate::climate(MODULE *module) : gld_object()
PT_double,"solar_zenith[rad]",PADDR(solar_zenith),
PT_OUTPUT,
PT_DESCRIPTION,"solar zenith angle in radians",
PT_char32, "city", PADDR(city),
PT_char256, "city", PADDR(city),
PT_DESCRIPTION,"weather data city name",
PT_char1024,"tmyfile",PADDR(tmyfile),
PT_REQUIRED,
Expand Down Expand Up @@ -1927,7 +1927,7 @@ void climate::write_out_cloud_pattern( char pattern )
ofstream out_file;

char buffer [100];
sprintf (buffer, "cloud_pattern_%010lld.csv", prev_NTime);
snprintf (buffer,sizeof(buffer)-1, "cloud_pattern_%010lld.csv", prev_NTime);
std::string file_string = buffer;
out_file.open(file_string.c_str(), ios::out);

Expand Down
2 changes: 1 addition & 1 deletion module/climate/climate.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class climate : public gld_object
{

// get_/set_ accessors for classes in this module only (non-atomic data need locks on access)
GL_STRING(char32,city); ///< the city
GL_STRING(char256,city); ///< the city
GL_ATOMIC(double,temperature); ///< the temperature (degF)
GL_ATOMIC(double,humidity); ///< the relative humidity (%)
GL_ATOMIC(double,wind_speed); ///< wind speed (m/s)
Expand Down
2 changes: 1 addition & 1 deletion module/commercial/ceus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ ceus::ceus(MODULE *module)
NULL)<1)
{
char msg[256];
sprintf(msg, "unable to publish properties in %s",__FILE__);
snprintf(msg,sizeof(msg)-1, "unable to publish properties in %s",__FILE__);
throw msg;
}
gl_global_create("commercial::default_nominal_voltage_A",PT_complex,&default_nominal_voltage_A,NULL);
Expand Down
2 changes: 1 addition & 1 deletion module/commercial/parking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ parking::parking(MODULE *module)
PT_complex,"total_power[VA]",get_total_power_offset(),PT_DEFAULT,"0 VA",PT_DESCRIPTION,"power total demand for parking structure",
NULL)<1){
char msg[256];
sprintf(msg, "unable to publish properties in %s",__FILE__);
snprintf(msg,sizeof(msg)-1, "unable to publish properties in %s",__FILE__);
throw msg;
}
gl_global_create("commercial::nightlight_threshold[W/m^2]",PT_double,&default_nightlight_threshold,NULL);
Expand Down
177 changes: 0 additions & 177 deletions module/connection/connection.vcproj.PNL.fish334.user

This file was deleted.

2 changes: 1 addition & 1 deletion module/connection/fncs_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ extern "C" void outgoing_fncs_function(char *from, char *to, char *funcName, cha
//TODO: deliver message to fncs
stringstream payload;
char buffer[sizeof(len)];
sprintf(buffer, "%d", len);
snprintf(buffer,sizeof(buffer)-1, "%d", len);
payload << "\"{\"from\":\"" << from << "\", " << "\"to\":\"" << to << "\", " << "\"function\":\"" << funcName << "\", " << "\"data\":\"" << message << "\", " << "\"data length\":\"" << buffer <<"\"}\"";
string key = string(relay->remotename);
if( relay->ctype == CT_PUBSUB){
Expand Down
Loading