Skip to content
Open
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
30 changes: 27 additions & 3 deletions settings/settings.tbs
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,7 @@ public function stg_sg_internal(byref stg_name_or_num as string,index as byte,by
stg_str=mid(stg_str,index*stg_sdr(num).member_size+1,stg_sdr(num).member_size)

'make sure this member has a valid value
dim skip_bounds_check as byte=0
select case stg_sdr(num).stype
case EN_STG_TYPE_BYTE: 'byte- convert into value
i=asc(stg_str)
Expand Down Expand Up @@ -1426,17 +1427,20 @@ public function stg_sg_internal(byref stg_name_or_num as string,index as byte,by
dim tmp_t as dword=0
strtobin(tmp_t,stg_str,4)
stg_value=lstr(tmp_t)
skip_bounds_check=1
goto lb1

case else: 'dot-decimal string- take length
stg_value=ddstr(mid(stg_str,2,asc(left(stg_str,1))))
i=asc(left(stg_str,1))
lb1: if i<stg_sdr(num).p1 or i>stg_sdr(num).p2 then
lb1: if skip_bounds_check=0 then
if i<stg_sdr(num).p1 or i>stg_sdr(num).p2 then
stg_sg_internal=EN_STG_STATUS_INVALID 'invalid checksum
#if STG_DEBUG_PRINT
stg_debug_print_error(debug_str,stg_sg_internal)
#endif
exit function
end if
end if
end select

Expand Down Expand Up @@ -1464,6 +1468,7 @@ lb1: if i<stg_sdr(num).p1 or i>stg_sdr(num).p2 then
#endif

'Branch according to the setting type and verify new value
dim skip_bounds_check as byte=0
select case stg_sdr(num).stype
case EN_STG_TYPE_BYTE: 'byte- convert into value
i=val(stg_value)
Expand All @@ -1488,20 +1493,39 @@ lb1: if i<stg_sdr(num).p1 or i>stg_sdr(num).p2 then
goto lb2

case EN_STG_TYPE_TIMESTAMP: 'DateTime
dim dt as dword=stg_value
dim dt as dword=0
dim b1 as byte
dim k as byte
for k=1 to len(stg_value)
b1=asc(mid(stg_value,k,1))
if b1>=48 and b1<=57 then
dt=dt*10+(b1-48)
else if b1=32 then
'ignore spaces
else
stg_sg_internal=EN_STG_STATUS_INVALID
#if STG_DEBUG_PRINT
stg_debug_print_error(debug_str,stg_sg_internal)
#endif
exit function
end if
next k
bintostr(new_member_str,dt,4)
skip_bounds_check=1
goto lb2

case EN_STG_TYPE_DOTDECIMAL: 'dot-decimal string- take length
new_member_str=ddval(stg_value)
new_member_str=chr(len(new_member_str))+new_member_str
i=len(new_member_str)-1
lb2: if i<stg_sdr(num).p1 or i>stg_sdr(num).p2 then
lb2: if skip_bounds_check=0 then
if i<stg_sdr(num).p1 or i>stg_sdr(num).p2 then
stg_sg_internal=EN_STG_STATUS_INVALID 'invalid checksum
#if STG_DEBUG_PRINT
stg_debug_print_error(debug_str,stg_sg_internal)
#endif
exit function
end if
end if

end select
Expand Down
23 changes: 10 additions & 13 deletions tables/tables.tbs
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,10 @@ public function tbl_start() as en_tbl_status_codes
exit function
end if
case EN_TBL_FIELD_TIMESTAMP: ' Timestamp
if p1>2147483647 then
dim dword_p1 as dword=p1
if dword_p1>4294967295 then
#if TBL_DEBUG_PRINT
tbl_debugprint("ERROR (table '"+tbl_item.table_name+"'/field '"+field_item.field_name+"'): minimum value (P1 param) can't exceed 2147483647 for datetime type. It is now "+s)
tbl_debugprint("ERROR (table '"+tbl_item.table_name+"'/field '"+field_item.field_name+"'): minimum value (P1 param) can't exceed 4294967295 for datetime type. It is now "+s)
#endif
tbl_info_index=0
tbl_start=EN_TBL_STATUS_WRONG_DESCRIPTOR
Expand Down Expand Up @@ -556,7 +557,7 @@ public function tbl_start() as en_tbl_status_codes
end select
field_item.p2=p2

if field_item.p2<field_item.p1 and field_item.field_type<>EN_TBL_FIELD_TIMESTRING then
if field_item.p2<field_item.p1 and field_item.field_type<>EN_TBL_FIELD_TIMESTAMP then
#if TBL_DEBUG_PRINT
tbl_debugprint("ERROR (table '"+tbl_item.table_name+"'/field '"+field_item.field_name+"'): P2 parameter (now "+lstr(field_item.p2)+") cannot be smaller than P1 parameter (now "+lstr(field_item.p1)+").")
#endif
Expand Down Expand Up @@ -2273,12 +2274,10 @@ public function tbl_field_sg(byref field_name as string,byref field_value as str
w3=asc(mid(s,3,1))*256+asc(mid(s,4,1))
d=w2*65536+w3
field_value =lstr(d)
if tbl_field_info(field_index).field_type=EN_TBL_FIELD_TIMESTAMP then
p1=0
p2=2147483647
if tbl_field_info(field_index).field_type<>EN_TBL_FIELD_TIMESTAMP then
if lval(field_value)<p1 then goto tbl_invalid
if lval(field_value)>p2 then goto tbl_invalid
end if
if lval(field_value)<p1 then goto tbl_invalid
if lval(field_value)>p2 then goto tbl_invalid
case EN_TBL_FIELD_TIME,EN_TBL_FIELD_FLOAT:
dim tmp_f as float=0
strtobin(tmp_f,s,4)
Expand Down Expand Up @@ -2331,12 +2330,10 @@ public function tbl_field_sg(byref field_name as string,byref field_value as str
if len(field_value) > p2 then goto tbl_invalid
s=chr(len(field_value))+field_value+strgen(fld_sz-len(field_value)-1,chr(TBL_NULL))
case EN_TBL_FIELD_DWORD,EN_TBL_FIELD_TIMESTAMP:
if tbl_field_info(field_index).field_type=EN_TBL_FIELD_TIMESTAMP then
p1=0
p2=2147483647
if tbl_field_info(field_index).field_type<>EN_TBL_FIELD_TIMESTAMP then
if lval(field_value) < p1 then goto tbl_invalid
if lval(field_value) > p2 then goto tbl_invalid
end if
if lval(field_value) < p1 then goto tbl_invalid
if lval(field_value) > p2 then goto tbl_invalid
w2=lval(field_value)/65536
w3=lval(field_value) mod 65536
s=chr(w2/256)+chr(w2 mod 256)+chr(w3/256)+chr(w3 mod 256)
Expand Down