Browse Source

using strtoul instead of atoi

refer to https://www.securecoding.cert.org/confluence/x/qoAyAQ
Holger Jeromin 9 years ago
parent
commit
6b7f7d436a
1 changed files with 9 additions and 1 deletions
  1. 9 1
      examples/networklayer_tcp.c

+ 9 - 1
examples/networklayer_tcp.c

@@ -498,7 +498,15 @@ ClientNetworkLayerTCP_connect(UA_ConnectionConfig localConf, char *endpointUrl,
     UA_UInt16 port;
     UA_UInt16 port;
     for(port = 0; portpos < urlLength-1; portpos++) {
     for(port = 0; portpos < urlLength-1; portpos++) {
         if(endpointUrl[portpos] == ':') {
         if(endpointUrl[portpos] == ':') {
-            port = atoi(&endpointUrl[portpos+1]);
+            char *endPtr = NULL;
+            unsigned long int tempulong = strtoul(&endpointUrl[portpos+1], &endPtr, 10);
+            if (ERANGE != errno &&
+                tempulong < UINT16_MAX &&
+                tempulong > 0 &&
+                endPtr != &endpointUrl[portpos+1])
+            {
+                port = (UA_UInt16)tempulong;
+            }
             break;
             break;
         }
         }
     }
     }