[Xfce4-commits] [xfce/xfce4-session] 03/04: atoi (argv[2]) is unsafe
noreply at xfce.org
noreply at xfce.org
Mon Sep 22 08:23:37 CEST 2014
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository xfce/xfce4-session.
commit a3a4725ef4d63034981b0915194930bfb8d274f1
Author: Eric Koegel <eric.koegel at gmail.com>
Date: Tue Sep 16 20:27:52 2014 +0300
atoi (argv[2]) is unsafe
Passing argv command line arguments directly into atoi is unsafe.
Use strtol and check/sanatize what it returns.
---
engines/mice/generate.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/engines/mice/generate.c b/engines/mice/generate.c
index c2870fa..9645290 100644
--- a/engines/mice/generate.c
+++ b/engines/mice/generate.c
@@ -28,6 +28,9 @@
#include <stdlib.h>
#endif
+#include <limits.h>
+#include <errno.h>
+
#include <gtk/gtk.h>
@@ -77,6 +80,7 @@ int main (int argc, char **argv)
{
GdkPixbuf *base;
GdkPixbuf *result;
+ glong val;
gtk_init (&argc, &argv);
@@ -93,7 +97,23 @@ int main (int argc, char **argv)
return EXIT_FAILURE;
}
- result = create_slide (base, atoi (argv[2]));
+ val = strtol (argv[2], NULL, 10);
+
+ /* Error checking for untrusted input */
+ if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) || (errno != 0 && val == 0))
+ {
+ perror("strtol");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Sanity checks */
+ if (val > INT_MAX)
+ val = INT_MAX;
+
+ if (val < 0)
+ val = 0;
+
+ result = create_slide (base, val);
gdk_pixbuf_save (result, "slide.png", "png", NULL, NULL);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list