Commit 64189593 authored by Botond Baranyi's avatar Botond Baranyi
Browse files

Fixed RAW decoding of strings to no longer change the static empty string values (bug 522656)



Change-Id: I9d79f7d1a704b03c2bf4e12cd51175e48abf2570
Signed-off-by: Botond Baranyi's avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent 55528f72
......@@ -1052,7 +1052,8 @@ int BITSTRING::RAW_decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& buff,
cp.fieldorder = p_td.raw->fieldorder;
cp.hexorder = ORDER_LSB;
buff.get_b((size_t) decode_length, val_ptr->bits_ptr, cp, top_bit_ord);
if (p_td.raw->length_restrition != -1) {
if (p_td.raw->length_restrition != -1 &&
decode_length > p_td.raw->length_restrition) {
val_ptr->n_bits = p_td.raw->length_restrition;
if (p_td.raw->endianness == ORDER_LSB) {
if ((decode_length - val_ptr->n_bits) % 8) {
......
......@@ -1614,7 +1614,8 @@ int CHARSTRING::RAW_decode(const TTCN_Typedescriptor_t& p_td,
temp_buff.get_string(*this);
decode_length=str_len+8;
}
if (p_td.raw->length_restrition != -1) {
if (p_td.raw->length_restrition != -1 &&
decode_length > p_td.raw->length_restrition) {
val_ptr->n_chars = p_td.raw->length_restrition;
if (p_td.raw->endianness == ORDER_MSB) memmove(val_ptr->chars_ptr,
val_ptr->chars_ptr + (decode_length / 8 - val_ptr->n_chars),
......
......@@ -828,7 +828,8 @@ int HEXSTRING::RAW_decode(const TTCN_Typedescriptor_t& p_td, TTCN_Buffer& buff,
init_struct(decode_length / 4);
buff.get_b((size_t) decode_length, val_ptr->nibbles_ptr, cp, top_bit_ord);
if (p_td.raw->length_restrition != -1) {
if (p_td.raw->length_restrition != -1 &&
decode_length > p_td.raw->length_restrition) {
val_ptr->n_nibbles = p_td.raw->length_restrition;
if (p_td.raw->endianness == ORDER_MSB) {
if ((decode_length - val_ptr->n_nibbles * 4) % 8) {
......
......@@ -1261,7 +1261,8 @@ int OCTETSTRING::RAW_decode(const TTCN_Typedescriptor_t& p_td,
init_struct(decode_length / 8);
buff.get_b((size_t) decode_length, val_ptr->octets_ptr, cp, top_bit_ord);
if (p_td.raw->length_restrition != -1) {
if (p_td.raw->length_restrition != -1 &&
decode_length > p_td.raw->length_restrition) {
val_ptr->n_octets = p_td.raw->length_restrition;
if (p_td.raw->endianness == ORDER_MSB) memmove(val_ptr->octets_ptr,
val_ptr->octets_ptr + (decode_length / 8 - val_ptr->n_octets),
......
Bug522656
Bug522656.exe
Bug522656*.cc
Bug522656*.hh
compile
Bug522656*.log
*.d
/******************************************************************************
* 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:
* Botond, Baranyi
*
******************************************************************************/
// RAW decoding strings with an empty buffer changes the length of the static 'empty
// string' values to the length restriction, if a length restriction is set.
module Bug522656 {
type bitstring Bit2 length (2)
with { variant "FIELDLENGTH(2)" }
type hexstring Hex2 length (2)
with { variant "FIELDLENGTH(2)" }
type octetstring Oct1 length (1)
with { variant "FIELDLENGTH(1)" }
type charstring Char3 length (3)
with { variant "FIELDLENGTH(3)" }
type record Rec {
Bit2 b,
Hex2 h,
Oct1 o,
Char3 c
}
type component CT {}
// This test case decodes the strings. The decoder is set to display only warnings
// upon failure, and continue the decoding.
// The changes in the empty strings are checked in other test cases.
testcase tc_decode() runs on CT {
var Rec x;
var bitstring buffer := ''B;
var integer result := decvalue(buffer, x);
if (result != 0) {
setverdict(pass);
}
else {
setverdict(fail, "Decoded with empty buffer successful.");
}
}
// Make sure the empty bitstring value has not changed.
testcase tc_bitstring() runs on CT {
var bitstring empty_bit := ''B;
if (lengthof(empty_bit) == 0) {
setverdict(pass);
}
else {
setverdict(fail, "Empty bitstring length: ", lengthof(empty_bit));
}
}
// Make sure the empty hexstring value has not changed.
testcase tc_hexstring() runs on CT {
var hexstring empty_hex := ''H;
if (lengthof(empty_hex) == 0) {
setverdict(pass);
}
else {
setverdict(fail, "Empty hexstring length: ", lengthof(empty_hex));
}
}
// Make sure the empty octetstring value has not changed.
testcase tc_octetstring() runs on CT {
var octetstring empty_oct := ''O;
if (lengthof(empty_oct) == 0) {
setverdict(pass);
}
else {
setverdict(fail, "Empty octetstring length: ", lengthof(empty_oct));
}
}
// Make sure the empty charstring value has not changed.
testcase tc_charstring() runs on CT {
var charstring empty_char := "";
if (lengthof(empty_char) == 0) {
setverdict(pass);
}
else {
setverdict(fail, "Empty charstring length: ", lengthof(empty_char));
}
}
control {
execute(tc_decode()); // must be executed before the other test cases
execute(tc_bitstring());
execute(tc_hexstring());
execute(tc_octetstring());
execute(tc_charstring());
}
}
with {
encode "RAW"
}
##############################################################################
# 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:
# Botond, Baranyi
#
##############################################################################
TOPDIR := ../..
include ../../Makefile.regression
# WARNING! This Makefile can be used with GNU make only.
# Other versions of make may report syntax errors in it.
#
# Do NOT touch this line...
#
.PHONY: all archive check clean dep objects
.SUFFIXES: .d
#
# Set these variables...
#
# Flags for dependency generation
CXXDEPFLAGS = -MM
ifeq ($(PLATFORM), WIN32)
# Silence linker warnings.
# Overridden by Makefile.cfg
endif
# Flags for the TTCN-3 and ASN.1 compiler:
COMPILER_FLAGS +=
# Execution mode: (either ttcn3 or ttcn3-parallel)
TTCN3_LIB = ttcn3$(RT2_SUFFIX)$(DYNAMIC_SUFFIX)
#
# You may change these variables. Add your files if necessary...
#
# TTCN-3 modules of this project:
TTCN3_MODULES = Bug522656.ttcn
# ASN.1 modules of this project:
ASN1_MODULES =
# C++ source & header files generated from the TTCN-3 & ASN.1 modules of
# this project:
GENERATED_SOURCES = $(TTCN3_MODULES:.ttcn=.cc) $(ASN1_MODULES:.asn=.cc)
GENERATED_HEADERS = $(GENERATED_SOURCES:.cc=.hh)
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
# C/C++ Source & header files of Test Ports, external functions and
# other modules:
USER_SOURCES =
USER_HEADERS = $(USER_SOURCES:.cc=.hh)
# Object files of this project that are needed for the executable test suite:
OBJECTS = $(GENERATED_OBJECTS) $(USER_OBJECTS)
GENERATED_OBJECTS = $(GENERATED_SOURCES:.cc=.o)
USER_OBJECTS = $(USER_SOURCES:.cc=.o)
DEPFILES = $(USER_OBJECTS:.o=.d) $(GENERATED_OBJECTS:.o=.d)
# The name of the executable test suite:
TARGET = Bug522656$(EXESUFFIX)
# Rules for building the executable...
#
all: $(TARGET) ;
objects: $(OBJECTS) ;
$(TARGET): $(OBJECTS)
if $(CXX) $(LDFLAGS) -o $@ $^ \
-L$(TTCN3_DIR)/lib -l$(TTCN3_LIB) \
-L$(OPENSSL_DIR)/lib -lcrypto \
-L$(XMLDIR)/lib $($(PLATFORM)_LIBS); \
then : ; else $(TTCN3_DIR)/bin/titanver $(OBJECTS); exit 1; fi
.cc.o .c.o:
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
.cc.d .c.d:
@echo Creating dependency file for '$<'; set -e; \
$(CXX) $(CXXDEPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $< \
| sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \
[ -s $@ ] || rm -f $@
$(GENERATED_SOURCES) $(GENERATED_HEADERS): compile
@if [ ! -f $@ ]; then $(RM) compile; $(MAKE) compile; fi
compile: $(TTCN3_MODULES) $(ASN1_MODULES)
$(TTCN3_COMPILER) $(COMPILER_FLAGS) $^ - $?
touch $@
clean:
-$(RM) $(TARGET) $(OBJECTS) $(GENERATED_HEADERS) \
$(GENERATED_SOURCES) compile $(DEPFILES) \
tags *.log
distclean: clean
-$(RM) $(DEPFILES)
dep: $(GENERATED_SOURCES) $(USER_SOURCES) ;
ifeq ($(findstring n,$(MAKEFLAGS)),)
ifeq ($(filter clean distclean check compile archive diag,$(MAKECMDGOALS)),)
-include $(DEPFILES)
endif
endif
diag:
$(TTCN3_COMPILER) -v 2>&1
$(TTCN3_DIR)/bin/mctr_cli -v 2>&1
$(CXX) -v 2>&1
@echo TTCN3_DIR=$(TTCN3_DIR)
@echo OPENSSL_DIR=$(OPENSSL_DIR)
@echo XMLDIR=$(XMLDIR)
@echo PLATFORM=$(PLATFORM)
#
# Add your rules here if necessary...
#
run: $(TARGET) ./config.cfg
./$^
###############################################################################
# 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:
# Botond, Baranyi
#
###############################################################################
[LOGGING]
LogFile := "Bug522656.log"
FileMask := LOG_ALL
ConsoleMask := TTCN_ERROR | TTCN_TESTCASE | TTCN_STATISTICS
LogSourceInfo := Yes
[EXECUTE]
Bug522656.control
[TESTPORT_PARAMETERS]
......@@ -18,7 +18,7 @@
TOPDIR := ..
include $(TOPDIR)/Makefile.regression
RDIRS = Examples HN25015 HQ26535 HQ49956 HS16977 ustr Annex_E_variants Bug521125 Lengthto_Offset
RDIRS = Examples HN25015 HQ26535 HQ49956 HS16977 ustr Annex_E_variants Bug521125 Lengthto_Offset Bug522656
all dep clean run distclean:
for dir in $(RDIRS); do (cd $$dir && $(MAKE) $@) || exit; done
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment