浏览代码

using strtoul instead of atoi

refer to https://www.securecoding.cert.org/confluence/x/qoAyAQ
Holger Jeromin 9 年之前
父节点
当前提交
6b7f7d436a
共有 1 个文件被更改,包括 9 次插入1 次删除
  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;
     for(port = 0; portpos < urlLength-1; 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;
         }
     }