Fixes an issue with running DU sim locally 05/10905/1
authorAbhijit Gadgil <gabhijit@iitbombay.org>
Wed, 12 Apr 2023 12:05:13 +0000 (17:35 +0530)
committerAbhijit Gadgil <gabhijit@iitbombay.org>
Wed, 12 Apr 2023 12:11:55 +0000 (17:41 +0530)
When DU simulator is run locally, the function crashes due to segfault
inside `nf_oran_du_init` when trying to read `ves_template.json` file.
This is because `ves_template.json` file is not copied during the image
creation.

Also, the actual utility function `file_read_content` instead of
returning a `NULL` crashes, because uninitialized `length` was used to
assign a value when `buffer` was `NULL`. Fixed this as well, the
`buffer[length]` value is only sent if the file exists and a valid
buffer is allocated.

Issue-Id: SIM-109
Change-Id: I75eb985f479331850de2e9fc4aac2ca588fa133c
Signed-off-by: Abhijit Gadgil <gabhijit@iitbombay.org>
ntsimulator/deploy/o-ran-du/local.Dockerfile
ntsimulator/ntsim-ng/utils/sys_utils.c

index 83b39fd..0c1787a 100644 (file)
@@ -24,8 +24,7 @@ LABEL maintainer="alexandru.stancu@highstreet-technologies.com / adrian.lita@hig
 COPY ./yang /opt/dev/deploy/yang
 COPY ./data /opt/dev/deploy/data
 COPY ./config.json /opt/dev/ntsim-ng/config/config.json
-COPY ./config.json /opt/dev/ntsim-ng/config/config.json
-
+COPY ./ves_template.json /opt/dev/ntsim-ng/config/ves_template.json
 
 # ntsim-ng init docker
 RUN /opt/dev/ntsim-ng/ntsim-ng --container-init -w /opt/dev/ntsim-ng
index 9b49995..2b93d52 100644 (file)
@@ -91,10 +91,10 @@ char *file_read_content(const char *fname) {
         buffer = (char*)malloc(sizeof(char) * (length + 1));
         if(buffer) {
             fread(buffer, 1, length, f);
+               buffer[length] = 0;
         }
         fclose(f);
     }
-    buffer[length] = 0;
 
     return buffer;
 }
@@ -177,7 +177,7 @@ bool get_local_ips(const char *ifname, char **ipv4, char **ipv6) {
                 ret = false;
                 goto get_local_ips_free;
             }
-            
+
             *ipv4 = strdup(host);
             break;
         }
@@ -195,7 +195,7 @@ bool get_local_ips(const char *ifname, char **ipv4, char **ipv6) {
                 ret = false;
                 goto get_local_ips_free;
             }
-            
+
             *ipv6 = strdup(host);
             break;
         }
@@ -217,7 +217,7 @@ bool check_port_open(const char *host, uint16_t port) {
     assert(host);
 
     int simpleSocket = 0;
-    int returnStatus = 0; 
+    int returnStatus = 0;
     struct addrinfo simpleServer;
     struct addrinfo *res;
 
@@ -243,7 +243,7 @@ bool check_port_open(const char *host, uint16_t port) {
     char s[INET6_ADDRSTRLEN];
     switch(res->ai_addr->sa_family) {
         case AF_INET: {
-            struct sockaddr_in *addr_in = (struct sockaddr_in *)res->ai_addr; 
+            struct sockaddr_in *addr_in = (struct sockaddr_in *)res->ai_addr;
             inet_ntop(AF_INET, &(addr_in->sin_addr), s, INET_ADDRSTRLEN);
             returnStatus = connect(simpleSocket, res->ai_addr, res->ai_addrlen);
             break;
@@ -262,10 +262,10 @@ bool check_port_open(const char *host, uint16_t port) {
 
     freeaddrinfo(res);
     close(simpleSocket);
-    if(returnStatus == 0) {    
+    if(returnStatus == 0) {
         return true;
     }
-    
+
     return false;
 }
 
@@ -455,7 +455,7 @@ char *read_key(const char *filename) {
                     return 0;
                 }
             }
-            
+
             free(line);
             line = 0;
             len = 0;