aboutsummaryrefslogtreecommitdiffstats
path: root/src/MuxElements.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2018-02-16 17:39:28 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2018-02-16 17:39:28 +0100
commit131cbad6d9d368e4eee0206dbccfd6ecfd023fa1 (patch)
treee3b3f44914ad867b23d258a579ede6773e57df42 /src/MuxElements.cpp
parent0ac597ca41fdeacbe7c7e8fbe92981782a7763b3 (diff)
downloaddabmux-131cbad6d9d368e4eee0206dbccfd6ecfd023fa1.tar.gz
dabmux-131cbad6d9d368e4eee0206dbccfd6ecfd023fa1.tar.bz2
dabmux-131cbad6d9d368e4eee0206dbccfd6ecfd023fa1.zip
Properly check length of labels with utf-8
Diffstat (limited to 'src/MuxElements.cpp')
-rw-r--r--src/MuxElements.cpp32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/MuxElements.cpp b/src/MuxElements.cpp
index 24c81b3..4c81ca9 100644
--- a/src/MuxElements.cpp
+++ b/src/MuxElements.cpp
@@ -172,21 +172,29 @@ const string AnnouncementCluster::get_parameter(const string& parameter) const
int DabLabel::setLabel(const std::string& label)
{
- size_t len = label.length();
- if (len > DABLABEL_LENGTH)
- return -3;
-
- m_flag = 0xFF00; // truncate the label to the eight first characters
-
try {
- m_label = charset_converter.convert(label, false);
+ auto ebu_label = charset_converter.convert(label, false);
+ size_t len = ebu_label.length();
+ if (len > DABLABEL_LENGTH) {
+ return -3;
+ }
+
+ m_label = ebu_label;
}
catch (const utf8::exception& e) {
etiLog.level(warn) << "Failed to convert label '" << label <<
"' to EBU Charset";
+
+ size_t len = label.length();
+ if (len > DABLABEL_LENGTH) {
+ return -3;
+ }
+
m_label = label;
}
+ m_flag = 0xFF00; // truncate the label to the eight first characters
+
return 0;
}
@@ -198,6 +206,11 @@ int DabLabel::setLabel(const std::string& label, const std::string& short_label)
try {
newlabel.m_label = charset_converter.convert(label, false);
+ size_t len = newlabel.m_label.length();
+ if (len > DABLABEL_LENGTH) {
+ return -3;
+ }
+
int flag = newlabel.setShortLabel(
charset_converter.convert(short_label, false));
if (flag < 0) {
@@ -212,6 +225,11 @@ int DabLabel::setLabel(const std::string& label, const std::string& short_label)
// Use label as-is
+ size_t len = label.length();
+ if (len > DABLABEL_LENGTH) {
+ return -3;
+ }
+
newlabel.m_label = label;
newlabel.m_flag = 0xFF00;