Commit d44c9c10 authored by Leon Hiemstra's avatar Leon Hiemstra

crash fixes due to missing size checks

parent 6f2aeec8
......@@ -131,13 +131,15 @@ bool Common::read(TermOutput& termout, const string addr)
std::vector<int> datavec;
if(node->mread(termout.strout,relative_addr,0,datavec,nvalues)) {
retcnt++;
//for(uint i=0;i<datavec.size();i++) {
// if(i>0) termout.strout << ",";
// termout.strout << datavec[i];
//}
}
} else if(type == "dev") {
if(node->get_system_info(termout.strout,peripheral)) retcnt++;
if(node->get_system_info(termout.strout,peripheral)) {
retcnt++;
} else {
termout.strerr << "no such peripheral: " << peripheral;
}
} else {
termout.strerr << "no such type: " << type;
}
termout.strout << "]";
......@@ -217,18 +219,20 @@ int Common::unb_name_to_number(const std::string unb_name)
{
int number = -1;
char *s = new char[unb_name.length() + 1];
s[unb_name.length()] = '\0';
for(uint i=0;i<unb_name.length();i++) {
s[i] = unb_name.c_str()[i];
}
if(unb_name.length() >= 4) {
char *s = new char[unb_name.length() + 1];
s[unb_name.length()] = '\0';
if(s[0] == 'u' && s[1] == 'n' && s[2] == 'b') {
char *s_ptr = &s[3];
number = atoi(s_ptr);
for(uint i=0;i<unb_name.length();i++) {
s[i] = unb_name.c_str()[i];
}
if(s[0] == 'u' && s[1] == 'n' && s[2] == 'b') {
char *s_ptr = &s[3];
number = atoi(s_ptr);
}
delete[] s;
}
delete[] s;
return number;
}
......@@ -236,8 +240,10 @@ int Common::pn_name_to_number(const std::string pn_name)
{
int number = -1;
if(pn_name.c_str()[0] == 'p' && pn_name.c_str()[1] == 'n' && isdigit(pn_name.c_str()[2])) {
number = pn_name.c_str()[2] - '0';
if(pn_name.length() >= 3) {
if(pn_name.c_str()[0] == 'p' && pn_name.c_str()[1] == 'n' && isdigit(pn_name.c_str()[2])) {
number = pn_name.c_str()[2] - '0';
}
}
return number;
}
......@@ -251,11 +257,15 @@ int Common::path_to_node(std::string path_str)
while (std::getline(ss, token, '/')) {
tokens.push_back(token);
}
if(tokens[0] == "") {
// ok, is absolute path starting with '/'
int unb = unb_name_to_number(tokens[1]);
int pn = pn_name_to_number(tokens[2]);
node = pn+(4*unb);
if(tokens.size() >= 3) {
if(tokens[0] == "") {
// ok, is absolute path starting with '/'
int unb = unb_name_to_number(tokens[1]);
int pn = pn_name_to_number(tokens[2]);
if(unb>=0 && pn>=0) {
node = pn+(4*unb);
}
}
}
return node;
}
......
......@@ -77,6 +77,11 @@ static UA_StatusCode UNB_MethodCallback(UA_Server *server,
UA_String tmp = UA_STRING_ALLOC((char *)p_termout(termout).c_str());
UA_Variant_setScalarCopy(output, &tmp, &UA_TYPES[UA_TYPES_STRING]);
UA_String_clear(&tmp);
} else {
cout <<"inputStr->data=nothing" <<endl;
UA_String tmp = UA_STRING_ALLOC("none");
UA_Variant_setScalarCopy(output, &tmp, &UA_TYPES[UA_TYPES_STRING]);
UA_String_clear(&tmp);
}
UA_String *outputStr = (UA_String*)output->data;
......
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