fix: strncpy limits

This commit is contained in:
Tobias Reisinger 2019-07-30 13:22:19 +02:00
parent 831291cdac
commit fc0e0b660a
3 changed files with 9 additions and 9 deletions

View file

@ -77,8 +77,8 @@ controllers::put_one_by_id(const HttpRequestPtr &req, std::function<void(const H
if(controllers[0]) if(controllers[0])
{ {
strncpy(controllers[0]->name, body["name"].asCString(), 128); strncpy(controllers[0]->name, body["name"].asCString(), 127);
strncpy(controllers[0]->ip, body["ip"].asCString(), 17); strncpy(controllers[0]->ip, body["ip"].asCString(), 16);
controllers[0]->name[127] = '\0'; controllers[0]->name[127] = '\0';
controllers[0]->ip[16] = '\0'; controllers[0]->ip[16] = '\0';

View file

@ -71,8 +71,8 @@ controllers::put_relays_one_by_id_and_num(const HttpRequestPtr &req,
if(relay) if(relay)
{ {
strncpy(relay->name, body["name"].asCString(), 128); strncpy(relay->name, body["name"].asCString(), 127);
strncpy(relay->active_schedule_id, body["active_schedule"].asCString(), 33); strncpy(relay->active_schedule_id, body["active_schedule"].asCString(), 32);
db_action_result = relay->update(); db_action_result = relay->update();
} }
@ -80,9 +80,9 @@ controllers::put_relays_one_by_id_and_num(const HttpRequestPtr &req,
{ {
relay = new relay_dbo(); relay = new relay_dbo();
relay->number = relay_num; relay->number = relay_num;
strncpy(relay->name, body["name"].asCString(), 128); strncpy(relay->name, body["name"].asCString(), 127);
strncpy(relay->active_schedule_id, body["active_schedule"].asCString(), 33); strncpy(relay->active_schedule_id, body["active_schedule"].asCString(), 32);
strncpy(relay->controller_id, controller_id.c_str(), 33); strncpy(relay->controller_id, controller_id.c_str(), 32);
db_action_result = relay->insert(); db_action_result = relay->insert();
} }

View file

@ -40,10 +40,10 @@ relay_db_select_mapper(sqlite3_stmt *stmt)
switch(name[0]) switch(name[0])
{ {
case 'a': // active_schedule_id case 'a': // active_schedule_id
strncpy(new_relay->active_schedule_id, (const char*)sqlite3_column_text(stmt, i), 33); strncpy(new_relay->active_schedule_id, (const char*)sqlite3_column_text(stmt, i), 32);
break; break;
case 'c': // controller_id case 'c': // controller_id
strncpy(new_relay->controller_id, (const char*)sqlite3_column_text(stmt, i), 33); strncpy(new_relay->controller_id, (const char*)sqlite3_column_text(stmt, i), 32);
break; break;
case 'i': case 'i':
new_relay->id = sqlite3_column_int(stmt, i); new_relay->id = sqlite3_column_int(stmt, i);