wgtpkg-unit: Fix Segmentation fault 57/19957/1
authorJose Bollo <jose.bollo@iot.bzh>
Wed, 6 Feb 2019 15:11:42 +0000 (16:11 +0100)
committerJose Bollo <jose.bollo@iot.bzh>
Wed, 6 Feb 2019 15:16:34 +0000 (16:16 +0100)
This fixes a segmentation fault raised when
uninstalling a widget. This regression was
introduced by the commit f8b0495.

Bug-AGL: SPEC-2144

Change-Id: Ie10eb97a4d2f2663d73f83b210ef2b17717ed2e6
Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
src/wgtpkg-unit.c

index cca718f..9f14346 100644 (file)
@@ -382,10 +382,14 @@ static int add_metadata(struct json_object *jdesc, const struct unitconf *conf)
                n = json_object_array_length(targets);
                for (i = 0 ; i < n ; i++) {
                        targ = json_object_array_get_idx(targets, i);
-                       port = conf->port();
-                       if (port < 0)
-                               return port;
-                       sprintf(portstr, "%d", port);
+                       if (!conf->port)
+                               strcpy(portstr, "0");
+                       else {
+                               port = conf->port ? conf->port() : 0;
+                               if (port < 0)
+                                       return port;
+                               sprintf(portstr, "%d", port);
+                       }
                        if (!j_add_string_m(targ, "#metatarget.http-port", portstr))
                                return -1;
                }