From 35764ba040c83559a16390b79f3410bac8479fa9 Mon Sep 17 00:00:00 2001 From: Botond Baranyi <botond.baranyi@ericsson.com> Date: Wed, 7 Feb 2018 13:11:21 +0100 Subject: [PATCH] Fixed subtype check of ISO2022 ASN.1 string types (bug 526554) Change-Id: I145f6ba55ea4f2365938c14c74158846abf160f1 Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com> --- compiler2/subtype.cc | 4 +- regression_test/compileonly/Makefile | 3 +- .../compileonly/asnStringSubtypes/.gitignore | 7 +++ .../compileonly/asnStringSubtypes/Makefile | 54 +++++++++++++++++++ .../asnStringSubtypes/StringSubtypes.asn | 43 +++++++++++++++ .../compileonly/asnStringSubtypes/Values.ttcn | 32 +++++++++++ 6 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 regression_test/compileonly/asnStringSubtypes/.gitignore create mode 100644 regression_test/compileonly/asnStringSubtypes/Makefile create mode 100644 regression_test/compileonly/asnStringSubtypes/StringSubtypes.asn create mode 100644 regression_test/compileonly/asnStringSubtypes/Values.ttcn diff --git a/compiler2/subtype.cc b/compiler2/subtype.cc index 37f30769c..66328c6cc 100644 --- a/compiler2/subtype.cc +++ b/compiler2/subtype.cc @@ -1825,7 +1825,9 @@ void SubType::chk_this_value(Value *value) case Value::V_CSTR: case Value::V_ISO2022STR: if (subtype!=ST_CHARSTRING) FATAL_ERROR("SubType::chk_this_value()"); - is_invalid = (charstring_st!=NULL) && !charstring_st->is_element(val->get_val_str()); + is_invalid = (charstring_st!=NULL) && (val->get_valuetype() == Value::V_CSTR ? + !charstring_st->is_element(val->get_val_str()) : + !charstring_st->is_element(val->get_val_iso2022str())); break; case Value::V_USTR: case Value::V_CHARSYMS: diff --git a/regression_test/compileonly/Makefile b/regression_test/compileonly/Makefile index 7ec82dcf2..b072ec44c 100644 --- a/regression_test/compileonly/Makefile +++ b/regression_test/compileonly/Makefile @@ -29,7 +29,8 @@ CODIRS := dynamicTemplate styleGuide topLevelPdu \ attribQualif HT48786 selectCase openTypeNames \ defaultParamUsageBeforeDecl deterministic readFromFile \ asn1_hyphen nameClash portTranslation UntaggedOnTopLevelUnionSwitch \ - typeDescrGenWIthNoXER languageSpec asn1_opentype openTypeXER + typeDescrGenWIthNoXER languageSpec asn1_opentype openTypeXER \ + asnStringSubtypes ifdef DYN CODIRS += mfgen-xsd diff --git a/regression_test/compileonly/asnStringSubtypes/.gitignore b/regression_test/compileonly/asnStringSubtypes/.gitignore new file mode 100644 index 000000000..4b256b538 --- /dev/null +++ b/regression_test/compileonly/asnStringSubtypes/.gitignore @@ -0,0 +1,7 @@ +stringSubtypes +stringSubtypes.exe +StringSubtypes*.cc +StringSubtypes*.hh +Values*.cc +Values*.hh +stringSubtypes*.log diff --git a/regression_test/compileonly/asnStringSubtypes/Makefile b/regression_test/compileonly/asnStringSubtypes/Makefile new file mode 100644 index 000000000..a3bfc6b9a --- /dev/null +++ b/regression_test/compileonly/asnStringSubtypes/Makefile @@ -0,0 +1,54 @@ +############################################################################## +# Copyright (c) 2000-2017 Ericsson Telecom AB +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Baranyi, Botond – initial implementation +# +############################################################################## +TOPDIR := ../.. +include $(TOPDIR)/Makefile.regression + +.SUFFIXES: .ttcn .asn .hh +.PHONY: all clean dep run + +TTCN3_LIB = ttcn3$(RT2_SUFFIX)$(DYNAMIC_SUFFIX) + +TTCN3_MODULES = Values.ttcn + +ASN1_MODULES = StringSubtypes.asn + +GENERATED_SOURCES = $(ASN1_MODULES:.asn=.cc) $(TTCN3_MODULES:.ttcn=.cc) + +GENERATED_HEADERS = $(GENERATED_SOURCES:.cc=.hh) +ifdef CODE_SPLIT +GENERATED_SOURCES := $(foreach file, $(GENERATED_SOURCES:.cc=), $(addprefix $(file), .cc _seq.cc _set.cc _seqof.cc _setof.cc _union.cc)) +else ifdef SPLIT_TO_SLICES +POSTFIXES := $(foreach file, $(SPLIT_TO_SLICES), $(addsuffix $(file), _part_)) +POSTFIXES := $(foreach file, $(POSTFIXES), $(addprefix $(file), .cc)) +GENERATED_SOURCES2 := $(foreach file, $(GENERATED_SOURCES:.cc=), $(addprefix $(file), $(POSTFIXES))) +GENERATED_SOURCES += $(GENERATED_SOURCES2) +endif + +OBJECTS = $(GENERATED_SOURCES:.cc=.o) + +TARGET = stringSubtypes$(EXESUFFIX) + +all: $(TARGET) + +$(TARGET): $(GENERATED_SOURCES) $(USER_SOURCES) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ -L$(TTCN3_DIR)/lib -l$(TTCN3_LIB) -L$(OPENSSL_DIR)/lib -lcrypto $($(PLATFORM)_LIBS) + +$(GENERATED_SOURCES) $(GENERATED_HEADERS): compile + +compile: $(TTCN3_MODULES) $(ASN1_MODULES) + $(TTCN3_COMPILER) $(COMPILER_FLAGS) $^ + +clean distclean: + $(RM) $(TARGET) $(GENERATED_HEADERS) $(GENERATED_SOURCES) $(OBJECTS) *.log Makefile.bak + +dep: $(GENERATED_SOURCES) + makedepend $(CPPFLAGS) $(GENERATED_SOURCES) diff --git a/regression_test/compileonly/asnStringSubtypes/StringSubtypes.asn b/regression_test/compileonly/asnStringSubtypes/StringSubtypes.asn new file mode 100644 index 000000000..c624603d9 --- /dev/null +++ b/regression_test/compileonly/asnStringSubtypes/StringSubtypes.asn @@ -0,0 +1,43 @@ +--///////////////////////////////////////////////////////////////////////////// +-- Copyright (c) 2000-2017 Ericsson Telecom AB +-- All rights reserved. This program and the accompanying materials +-- are made available under the terms of the Eclipse Public License v1.0 +-- which accompanies this distribution, and is available at +-- http://www.eclipse.org/legal/epl-v10.html +-- +-- Contributors: +-- Baranyi, Botond +-- +--///////////////////////////////////////////////////////////////////////////// + +StringSubtypes +DEFINITIONS + +AUTOMATIC TAGS + +::= + +BEGIN + +IMPORTS ; -- nothing + + +-- Types + +TeletexStringRestricted ::= TeletexString (SIZE(4)) + +VideotexStringRestricted ::= VideotexString (SIZE(1..10)) + +GraphicStringRestricted ::= GraphicString (SIZE(0..3)) + +T61StringRestricted ::= T61String (SIZE(5)) + +GeneralStringRestricted ::= GeneralString (SIZE(1)) + +ObjectDescriptorRestricted ::= ObjectDescriptor (SIZE(2..4)) + +-- Values + +val T61StringRestricted ::= "abcde" + +END diff --git a/regression_test/compileonly/asnStringSubtypes/Values.ttcn b/regression_test/compileonly/asnStringSubtypes/Values.ttcn new file mode 100644 index 000000000..db2d20f81 --- /dev/null +++ b/regression_test/compileonly/asnStringSubtypes/Values.ttcn @@ -0,0 +1,32 @@ +/****************************************************************************** + * Copyright (c) 2000-2017 Ericsson Telecom AB + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Baranyi, Botond + * + ******************************************************************************/ + +module Values { + +import from StringSubtypes all; + +function f() { + var TeletexStringRestricted x; + x := "ttxx"; +} + +const VideotexStringRestricted c := "aaaaa"; + +template GraphicStringRestricted t := "gr"; + +modulepar ObjectDescriptorRestricted mp := "xyz"; + +control { + var template GeneralStringRestricted vt := "Q"; +} + +} -- GitLab