libxl: use thread-safe localtime_r and handle NULL
authorWei Liu <wei.liu2@citrix.com>
Thu, 23 Jul 2015 07:59:02 +0000 (08:59 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Fri, 24 Jul 2015 10:23:27 +0000 (11:23 +0100)
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/libxl/libxl_x86.c

index b3cf3e238aaaefeb2f5a5cc0bc67f5bc4da8d54c..b379e09b2019a18ecfc3602a17bc13efc55f157d 100644 (file)
@@ -306,10 +306,16 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
     rtc_timeoffset = d_config->b_info.rtc_timeoffset;
     if (libxl_defbool_val(d_config->b_info.localtime)) {
         time_t t;
-        struct tm *tm;
+        struct tm *tm, result;
 
         t = time(NULL);
-        tm = localtime(&t);
+        tm = localtime_r(&t, &result);
+
+        if (!tm) {
+            LOGE(ERROR, "Failed to call localtime_r");
+            ret = ERROR_FAIL;
+            goto out;
+        }
 
         rtc_timeoffset += tm->tm_gmtoff;
     }
@@ -335,6 +341,7 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
         }
     }
 
+out:
     return ret;
 }