Switch to use safe_strtoint instead of strtol

Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Bryce Harrington
2016-08-03 17:40:52 -07:00
parent 82b9f2baec
commit 25a2bdd814
7 changed files with 21 additions and 34 deletions
+3 -4
View File
@@ -52,6 +52,7 @@
#include "compositor.h"
#include "../shared/os-compatibility.h"
#include "../shared/helpers.h"
#include "../shared/string-helpers.h"
#include "git-version.h"
#include "version.h"
#include "weston.h"
@@ -1580,7 +1581,7 @@ int main(int argc, char *argv[])
char *modules = NULL;
char *option_modules = NULL;
char *log = NULL;
char *server_socket = NULL, *end;
char *server_socket = NULL;
int32_t idle_time = -1;
int32_t help = 0;
char *socket_name = NULL;
@@ -1699,9 +1700,7 @@ int main(int argc, char *argv[])
server_socket = getenv("WAYLAND_SERVER_SOCKET");
if (server_socket) {
weston_log("Running with single client\n");
errno = 0;
fd = strtol(server_socket, &end, 10);
if (errno != 0 || end == server_socket || *end != '\0')
if (!safe_strtoint(server_socket, &fd))
fd = -1;
} else {
fd = -1;
+3 -6
View File
@@ -25,12 +25,13 @@
#include "config.h"
#include <errno.h>
#include <stdlib.h>
#include <systemd/sd-daemon.h>
#include <sys/socket.h>
#include <wayland-server.h>
#include "shared/helpers.h"
#include "shared/string-helpers.h"
#include "shared/zalloc.h"
#include "compositor.h"
@@ -116,7 +117,6 @@ WL_EXPORT int
module_init(struct weston_compositor *compositor,
int *argc, char *argv[])
{
char *tail;
char *watchdog_time_env;
struct wl_event_loop *loop;
long watchdog_time_conv;
@@ -140,13 +140,10 @@ module_init(struct weston_compositor *compositor,
* by systemd to transfer 'WatchdogSec' watchdog timeout
* setting from service file.*/
watchdog_time_env = getenv("WATCHDOG_USEC");
if (!watchdog_time_env)
return 0;
errno = 0;
watchdog_time_conv = strtol(watchdog_time_env, &tail, 10);
if (errno != 0 || tail == watchdog_time_env || *tail != '\0')
if (!safe_strtoint(watchdog_time_env, &watchdog_time_conv))
return 0;
/* Convert 'WATCHDOG_USEC' to milliseconds and notify