Skip to content

Commit

Permalink
Merge pull request #237 from ppetru/divzero
Browse files Browse the repository at this point in the history
Prevent saving programs that cause the controller the crash with a division by zero.
  • Loading branch information
arfrie22 authored Jul 24, 2024
2 parents d2d7828 + 46391a8 commit 9282327
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions opensprinkler_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,15 @@ void server_change_program(OTF_PARAMS_DEF) {
*(char*)(&prog) = parse_listdata(&pv);
prog.days[0]= parse_listdata(&pv);
prog.days[1]= parse_listdata(&pv);

if (prog.type == PROGRAM_TYPE_INTERVAL) {
if (prog.days[1] == 0) handle_return(HTML_DATA_OUTOFBOUND)
else if (prog.days[1] >= 1) {
// process interval day remainder (relative-> absolute)
pd.drem_to_absolute(prog.days);
}
}

// parse start times
pv++; // this should be a '['
for (i=0;i<MAX_NUM_STARTTIMES;i++) {
Expand All @@ -930,11 +939,6 @@ void server_change_program(OTF_PARAMS_DEF) {
prog.durations[i] = 0; // clear unused field
}

// process interval day remainder (relative-> absolute)
if (prog.type == PROGRAM_TYPE_INTERVAL && prog.days[1] >= 1) {
pd.drem_to_absolute(prog.days);
}

if (pid==-1) {
if(!pd.add(&prog)) handle_return(HTML_DATA_OUTOFBOUND);
} else {
Expand Down
2 changes: 1 addition & 1 deletion program.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ProgramStruct {
// weekly: days[0][0..6] correspond to Monday till Sunday
// bi-weekly:days[0][0..6] and [1][0..6] store two weeks
// monthly: days[0][0..5] stores the day of the month (32 means last day of month)
// interval: days[0] stores the interval (0 to 255), days[1] stores the starting day remainder (0 to 254)
// interval: days[1] stores the interval (0 to 255), days[0] stores the starting day remainder (0 to 254)
unsigned char days[2];

// When the program is a fixed start time type:
Expand Down

0 comments on commit 9282327

Please sign in to comment.