Skip to content

Commit e61629c

Browse files
authored
Prevent accessing LRTS with PRTS ID on store/retrieve (CWMS-2378) (#100)
Fixes #95 Fixes CWMS-2378
1 parent 677dec6 commit e61629c

File tree

2 files changed

+520
-42
lines changed

2 files changed

+520
-42
lines changed

schema/src/cwms/cwms_ts_pkg_body.sql

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ AS
4141
'Session requires new LRTS ID format. Invalid ID: '||p_cwms_ts_id);
4242
end new_lrts_id_required_error;
4343

44+
procedure old_lrts_id_required_error(
45+
p_cwms_ts_id in varchar2)
46+
is
47+
begin
48+
cwms_err.raise(
49+
'ERROR',
50+
'Session requires old LRTS ID format. Invalid ID: '||p_cwms_ts_id);
51+
end old_lrts_id_required_error;
52+
53+
procedure not_lrts_error(
54+
p_cwms_ts_id in varchar2)
55+
is
56+
begin
57+
cwms_err.raise(
58+
'ERROR',
59+
'Invalid ID for PRTS: '||p_cwms_ts_id);
60+
end not_lrts_error;
61+
4462
procedure clear_all_caches
4563
is
4664
begin
@@ -3026,7 +3044,7 @@ AS
30263044
clear_all_caches;
30273045
end set_require_new_lrts_format_on_input;
30283046
--------------------------------------------------------------------------------
3029-
-- function function require_new_lrts_format_on_input
3047+
-- function require_new_lrts_format_on_input
30303048
--------------------------------------------------------------------------------
30313049
function require_new_lrts_format_on_input
30323050
return varchar2
@@ -3038,7 +3056,7 @@ AS
30383056
end;
30393057
end require_new_lrts_format_on_input;
30403058
--------------------------------------------------------------------------------
3041-
-- function retrieve_ts_raw
3059+
-- procedure retrieve_ts_raw
30423060
--------------------------------------------------------------------------------
30433061
procedure retrieve_ts_raw(
30443062
p_ts_retrieved in out nocopy ztsv_entry_array,
@@ -3229,9 +3247,11 @@ AS
32293247
l_ts_code at_cwms_ts_id.ts_code%type;
32303248
l_office_id cwms_office.office_id%type;
32313249
l_cwms_ts_id at_cwms_ts_id.cwms_ts_id%type;
3250+
l_parts str_tab_t;
32323251
l_location_id av_loc.location_id%type;
32333252
l_location_code at_physical_location.location_code%type;
32343253
l_parameter_id at_cwms_ts_id.parameter_id%type;
3254+
l_interval_id at_cwms_ts_id.interval_id%type;
32353255
l_unit_id at_cwms_ts_id.unit_id%type;
32363256
l_time_zone_in cwms_time_zone.time_zone_name%type;
32373257
l_time_zone_out cwms_time_zone.time_zone_name%type;
@@ -3276,21 +3296,38 @@ AS
32763296
l_office_id := cwms_util.get_db_office_id(p_office_id);
32773297
l_cwms_ts_id := get_ts_id(p_cwms_ts_id, l_office_id);
32783298
l_retrieve_data_entry := cwms_util.return_true_or_false(p_retrieve_data_entry);
3299+
l_interval_id := cwms_util.split_text(p_cwms_ts_id, 4, '.');
32793300
if l_cwms_ts_id is null then
32803301
cwms_err.raise('TS_ID_NOT_FOUND', p_cwms_ts_id, l_office_id);
32813302
elsif use_new_lrts_format_on_output = 'T'
3282-
and substr(cwms_util.split_text(p_cwms_ts_id, 4, '.'), 1, 1) = '~'
3303+
and substr(l_interval_id, 1, 1) = '~'
32833304
and upper(substr(cwms_util.split_text(l_cwms_ts_id, 4, '.'), -5)) = 'LOCAL'
32843305
then
32853306
----------------------------------
32863307
-- convert back to input format --
32873308
----------------------------------
32883309
l_cwms_ts_id := regexp_replace(l_cwms_ts_id, '\.([[:digit:]]+[[:alpha:]]+)Local\.', '.~\1.', 1, 1, 'i');
32893310
end if;
3311+
l_ts_code := get_ts_code(p_cwms_ts_id, l_office_id);
3312+
----------------------------------------------
3313+
-- verify correct TSID format for actual TS --
3314+
----------------------------------------------
3315+
if is_lrts(l_ts_code) = 'T' then
3316+
if require_new_lrts_format_on_input = 'T' then
3317+
if substr(l_interval_id, 1, 1) = '~' then
3318+
new_lrts_id_required_error(l_cwms_ts_id);
3319+
end if;
3320+
elsif upper(substr(l_interval_id, -5)) = 'LOCAL' then
3321+
if 'T' not in (require_new_lrts_format_on_input, allow_new_lrts_format_on_input) then
3322+
old_lrts_id_required_error(l_cwms_ts_id);
3323+
end if;
3324+
end if;
3325+
elsif upper(substr(l_interval_id, -5)) = 'LOCAL' then
3326+
not_lrts_error(l_cwms_ts_id);
3327+
end if;
32903328
l_location_id := cwms_util.split_text(l_cwms_ts_id, 1, '.');
32913329
l_location_code := cwms_loc.get_location_code(l_office_id, l_location_id);
32923330
l_parameter_id := cwms_util.split_text(l_cwms_ts_id, 2, '.');
3293-
l_ts_code := get_ts_code(p_cwms_ts_id, l_office_id);
32943331
l_location_code := cwms_loc.get_location_code(l_office_id, cwms_util.split_text(l_cwms_ts_id, 1, '.'));
32953332
l_time_zone_out := cwms_loc.get_local_timezone(substr(l_cwms_ts_id, 1, instr(l_cwms_ts_id, '.') - 1), l_office_id);
32963333
l_time_zone_in := case when p_time_zone is null then l_time_zone_out else cwms_util.get_timezone(p_time_zone) end;
@@ -5724,13 +5761,19 @@ AS
57245761
get_ts_code (p_cwms_ts_id => l_cwms_ts_id,
57255762
p_db_office_code => l_office_code);
57265763

5764+
l_is_lrts := is_lrts(l_ts_code) = 'T';
5765+
if l_is_lrts and
5766+
require_new_lrts_format_on_input = 'T' and
5767+
substr(cwms_util.split_text(p_cwms_ts_id, 4, '.'), 1, 1) = '~'
5768+
then
5769+
new_lrts_id_required_error(l_cwms_ts_id);
5770+
end if;
5771+
57275772
SELECT interval_utc_offset
57285773
INTO existing_utc_offset
57295774
FROM at_cwms_ts_spec
57305775
WHERE ts_code = l_ts_code;
57315776

5732-
l_is_lrts := is_lrts(l_ts_code) = 'T';
5733-
57345777
if l_is_lrts then
57355778
l_irr_offset := existing_utc_offset;
57365779
l_loc_tz := cwms_loc.get_local_timezone(l_location_code);
@@ -5792,7 +5835,6 @@ AS
57925835
p_utc_offset => l_utc_offset);
57935836
existing_utc_offset := l_utc_offset;
57945837
WHEN OTHERS THEN
5795-
dbms_output.put_line('==> ERROR is '||sqlerrm);
57965838
cwms_err.raise('ERROR', dbms_utility.format_error_backtrace);
57975839
END; -- END - Find TS_CODE
57985840

@@ -6038,16 +6080,6 @@ AS
60386080
from table(l_timeseries_data);
60396081
exception
60406082
when too_many_rows then
6041-
dbms_output.enable;
6042-
dbms_output.put_line('time series id = '||l_cwms_ts_id);
6043-
dbms_output.put_line('interval = '||l_irr_interval);
6044-
dbms_output.put_line('local time zone = '||l_loc_tz);
6045-
for i in 1..l_timeseries_data.count loop
6046-
dbms_output.put(i||chr(9)||l_timeseries_data(i).date_time);
6047-
dbms_output.put(chr(9)||from_tz(cwms_util.change_timezone(cast(l_timeseries_data(i).date_time as timestamp), extract(timezone_region from l_timeseries_data(i).date_time), l_loc_tz), l_loc_tz));
6048-
dbms_output.put(chr(9)||get_utc_interval_offset(from_tz(cwms_util.change_timezone(cast(l_timeseries_data(i).date_time as timestamp), extract(timezone_region from l_timeseries_data(i).date_time), l_loc_tz), l_loc_tz), l_irr_interval));
6049-
dbms_output.new_line;
6050-
end loop;
60516083
raise_application_error (
60526084
-20110,
60536085
'ERROR: Incoming data set contains multiple interval offsets. Unable to store data for '

0 commit comments

Comments
 (0)