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>
dev
Bryce Harrington 8 years ago
parent 82b9f2baec
commit 25a2bdd814
  1. 7
      compositor/main.c
  2. 9
      compositor/systemd-notify.c
  3. 9
      libweston/compositor.c
  4. 11
      libweston/libbacklight.c
  5. 7
      shared/config-parser.c
  6. 5
      shared/option-parser.c
  7. 7
      xwayland/launcher.c

@ -52,6 +52,7 @@
#include "compositor.h" #include "compositor.h"
#include "../shared/os-compatibility.h" #include "../shared/os-compatibility.h"
#include "../shared/helpers.h" #include "../shared/helpers.h"
#include "../shared/string-helpers.h"
#include "git-version.h" #include "git-version.h"
#include "version.h" #include "version.h"
#include "weston.h" #include "weston.h"
@ -1580,7 +1581,7 @@ int main(int argc, char *argv[])
char *modules = NULL; char *modules = NULL;
char *option_modules = NULL; char *option_modules = NULL;
char *log = NULL; char *log = NULL;
char *server_socket = NULL, *end; char *server_socket = NULL;
int32_t idle_time = -1; int32_t idle_time = -1;
int32_t help = 0; int32_t help = 0;
char *socket_name = NULL; char *socket_name = NULL;
@ -1699,9 +1700,7 @@ int main(int argc, char *argv[])
server_socket = getenv("WAYLAND_SERVER_SOCKET"); server_socket = getenv("WAYLAND_SERVER_SOCKET");
if (server_socket) { if (server_socket) {
weston_log("Running with single client\n"); weston_log("Running with single client\n");
errno = 0; if (!safe_strtoint(server_socket, &fd))
fd = strtol(server_socket, &end, 10);
if (errno != 0 || end == server_socket || *end != '\0')
fd = -1; fd = -1;
} else { } else {
fd = -1; fd = -1;

@ -25,12 +25,13 @@
#include "config.h" #include "config.h"
#include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <systemd/sd-daemon.h> #include <systemd/sd-daemon.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <wayland-server.h> #include <wayland-server.h>
#include "shared/helpers.h" #include "shared/helpers.h"
#include "shared/string-helpers.h"
#include "shared/zalloc.h" #include "shared/zalloc.h"
#include "compositor.h" #include "compositor.h"
@ -116,7 +117,6 @@ WL_EXPORT int
module_init(struct weston_compositor *compositor, module_init(struct weston_compositor *compositor,
int *argc, char *argv[]) int *argc, char *argv[])
{ {
char *tail;
char *watchdog_time_env; char *watchdog_time_env;
struct wl_event_loop *loop; struct wl_event_loop *loop;
long watchdog_time_conv; long watchdog_time_conv;
@ -140,13 +140,10 @@ module_init(struct weston_compositor *compositor,
* by systemd to transfer 'WatchdogSec' watchdog timeout * by systemd to transfer 'WatchdogSec' watchdog timeout
* setting from service file.*/ * setting from service file.*/
watchdog_time_env = getenv("WATCHDOG_USEC"); watchdog_time_env = getenv("WATCHDOG_USEC");
if (!watchdog_time_env) if (!watchdog_time_env)
return 0; return 0;
errno = 0; if (!safe_strtoint(watchdog_time_env, &watchdog_time_conv))
watchdog_time_conv = strtol(watchdog_time_env, &tail, 10);
if (errno != 0 || tail == watchdog_time_env || *tail != '\0')
return 0; return 0;
/* Convert 'WATCHDOG_USEC' to milliseconds and notify /* Convert 'WATCHDOG_USEC' to milliseconds and notify

@ -58,6 +58,7 @@
#include "presentation-time-server-protocol.h" #include "presentation-time-server-protocol.h"
#include "shared/helpers.h" #include "shared/helpers.h"
#include "shared/os-compatibility.h" #include "shared/os-compatibility.h"
#include "shared/string-helpers.h"
#include "shared/timespec-util.h" #include "shared/timespec-util.h"
#include "git-version.h" #include "git-version.h"
#include "version.h" #include "version.h"
@ -4622,15 +4623,11 @@ compositor_bind(struct wl_client *client,
WL_EXPORT int WL_EXPORT int
weston_environment_get_fd(const char *env) weston_environment_get_fd(const char *env)
{ {
char *e, *end; char *e;
int fd, flags; int fd, flags;
e = getenv(env); e = getenv(env);
if (!e) if (!e || !safe_strtoint(e, &fd))
return -1;
errno = 0;
fd = strtol(e, &end, 10);
if (errno != 0 || end == e || *end != '\0')
return -1; return -1;
flags = fcntl(fd, F_GETFD); flags = fcntl(fd, F_GETFD);

@ -44,13 +44,14 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "shared/string-helpers.h"
static long backlight_get(struct backlight *backlight, char *node) static long backlight_get(struct backlight *backlight, char *node)
{ {
char buffer[100]; char buffer[100];
char *path; char *path;
char *end; int fd, value;
int fd; long ret;
long value, ret;
if (asprintf(&path, "%s/%s", backlight->path, node) < 0) if (asprintf(&path, "%s/%s", backlight->path, node) < 0)
return -ENOMEM; return -ENOMEM;
@ -66,9 +67,7 @@ static long backlight_get(struct backlight *backlight, char *node)
goto out; goto out;
} }
errno = 0; if (!safe_strtoint(buffer, &value)) {
value = strtol(buffer, &end, 10);
if (errno != 0 || end == buffer || *end != '\0') {
ret = -1; ret = -1;
goto out; goto out;
} }

@ -41,6 +41,7 @@
#include <wayland-util.h> #include <wayland-util.h>
#include "config-parser.h" #include "config-parser.h"
#include "helpers.h" #include "helpers.h"
#include "string-helpers.h"
struct weston_config_entry { struct weston_config_entry {
char *key; char *key;
@ -161,7 +162,6 @@ weston_config_section_get_int(struct weston_config_section *section,
int32_t *value, int32_t default_value) int32_t *value, int32_t default_value)
{ {
struct weston_config_entry *entry; struct weston_config_entry *entry;
char *end;
entry = config_section_get_entry(section, key); entry = config_section_get_entry(section, key);
if (entry == NULL) { if (entry == NULL) {
@ -170,11 +170,8 @@ weston_config_section_get_int(struct weston_config_section *section,
return -1; return -1;
} }
errno = 0; if (!safe_strtoint(entry->value, value)) {
*value = strtol(entry->value, &end, 10);
if (errno != 0 || end == entry->value || *end != '\0') {
*value = default_value; *value = default_value;
errno = EINVAL;
return -1; return -1;
} }

@ -33,6 +33,7 @@
#include <errno.h> #include <errno.h>
#include "config-parser.h" #include "config-parser.h"
#include "string-helpers.h"
static int static int
handle_option(const struct weston_option *option, char *value) handle_option(const struct weston_option *option, char *value)
@ -41,9 +42,7 @@ handle_option(const struct weston_option *option, char *value)
switch (option->type) { switch (option->type) {
case WESTON_OPTION_INTEGER: case WESTON_OPTION_INTEGER:
errno = 0; if (!safe_strtoint(value, option->data))
* (int32_t *) option->data = strtol(value, &p, 10);
if (errno != 0 || p == value || *p != '\0')
return 0; return 0;
return 1; return 1;
case WESTON_OPTION_UNSIGNED_INTEGER: case WESTON_OPTION_UNSIGNED_INTEGER:

@ -39,6 +39,7 @@
#include "xwayland.h" #include "xwayland.h"
#include "xwayland-api.h" #include "xwayland-api.h"
#include "shared/helpers.h" #include "shared/helpers.h"
#include "shared/string-helpers.h"
#include "compositor/weston.h" #include "compositor/weston.h"
static int static int
@ -147,7 +148,7 @@ bind_to_unix_socket(int display)
static int static int
create_lockfile(int display, char *lockfile, size_t lsize) create_lockfile(int display, char *lockfile, size_t lsize)
{ {
char pid[16], *end; char pid[16];
int fd, size; int fd, size;
pid_t other; pid_t other;
@ -165,9 +166,7 @@ create_lockfile(int display, char *lockfile, size_t lsize)
return -1; return -1;
} }
errno = 0; if (!safe_strtoint(pid, &other)) {
other = strtol(pid, &end, 10);
if (errno != 0 || end == pid || *end != '\0') {
weston_log("can't parse lock file %s\n", weston_log("can't parse lock file %s\n",
lockfile); lockfile);
close(fd); close(fd);

Loading…
Cancel
Save