summaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2011-08-23 16:12:27 +0100
committerRichard W.M. Jones <rjones@redhat.com>2011-08-23 16:12:27 +0100
commit4c76aaa391d591c5917a06b0277fb9eb7d6d790f (patch)
treec933491814d91e36165fb5d2bcd0eb1dacbde8f5 /generator
parentca727deac186981f4d9784696324c8f3af79f9e5 (diff)
downloadlibguestfs-4c76aaa391d591c5917a06b0277fb9eb7d6d790f.tar.gz
libguestfs-4c76aaa391d591c5917a06b0277fb9eb7d6d790f.tar.xz
libguestfs-4c76aaa391d591c5917a06b0277fb9eb7d6d790f.zip
Coverity: Check return value from sscanf in bindtests calls.
Diffstat (limited to 'generator')
-rw-r--r--generator/generator_bindtests.ml27
1 files changed, 22 insertions, 5 deletions
diff --git a/generator/generator_bindtests.ml b/generator/generator_bindtests.ml
index ebe2e246..859f189e 100644
--- a/generator/generator_bindtests.ml
+++ b/generator/generator_bindtests.ml
@@ -109,11 +109,17 @@ print_strings (char *const *argv)
pr " return 0;\n"
| RInt _ ->
pr " int r;\n";
- pr " sscanf (val, \"%%d\", &r);\n";
+ pr " if (sscanf (val, \"%%d\", &r) != 1) {\n";
+ pr " error (g, \"%%s: expecting int argument\", \"%s\");\n" name;
+ pr " return -1;\n";
+ pr " }\n";
pr " return r;\n"
| RInt64 _ ->
pr " int64_t r;\n";
- pr " sscanf (val, \"%%\" SCNi64, &r);\n";
+ pr " if (sscanf (val, \"%%\" SCNi64, &r) != 1) {\n";
+ pr " error (g, \"%%s: expecting int64 argument\", \"%s\");\n" name;
+ pr " return -1;\n";
+ pr " }\n";
pr " return r;\n"
| RBool _ ->
pr " return STREQ (val, \"true\");\n"
@@ -129,7 +135,10 @@ print_strings (char *const *argv)
| RStringList _ ->
pr " char **strs;\n";
pr " int n, i;\n";
- pr " sscanf (val, \"%%d\", &n);\n";
+ pr " if (sscanf (val, \"%%d\", &n) != 1) {\n";
+ pr " error (g, \"%%s: expecting int argument\", \"%s\");\n" name;
+ pr " return NULL;\n";
+ pr " }\n";
pr " strs = safe_malloc (g, (n+1) * sizeof (char *));\n";
pr " for (i = 0; i < n; ++i) {\n";
pr " strs[i] = safe_malloc (g, 16);\n";
@@ -143,14 +152,22 @@ print_strings (char *const *argv)
pr " return r;\n"
| RStructList (_, typ) ->
pr " struct guestfs_%s_list *r;\n" typ;
+ pr " uint32_t len;\n";
+ pr " if (sscanf (val, \"%%\" SCNu32, &len) != 1) {\n";
+ pr " error (g, \"%%s: expecting uint32 argument\", \"%s\");\n" name;
+ pr " return NULL;\n";
+ pr " }\n";
pr " r = safe_calloc (g, sizeof *r, 1);\n";
- pr " sscanf (val, \"%%d\", &r->len);\n";
+ pr " r->len = len;\n";
pr " r->val = safe_calloc (g, r->len, sizeof *r->val);\n";
pr " return r;\n"
| RHashtable _ ->
pr " char **strs;\n";
pr " int n, i;\n";
- pr " sscanf (val, \"%%d\", &n);\n";
+ pr " if (sscanf (val, \"%%d\", &n) != -1) {\n";
+ pr " error (g, \"%%s: expecting int argument\", \"%s\");\n" name;
+ pr " return NULL;\n";
+ pr " }\n";
pr " strs = safe_malloc (g, (n*2+1) * sizeof (*strs));\n";
pr " for (i = 0; i < n; ++i) {\n";
pr " strs[i*2] = safe_malloc (g, 16);\n";