From 21df9b257b66b32e1e8cd82333fb2d1edc7b1f9f Mon Sep 17 00:00:00 2001 From: Christian Beer Date: Wed, 21 Oct 2015 16:37:55 +0200 Subject: [PATCH] use snprintf to prevent buffer overflow fixes CID 27994 found by Coverity also added sanity checks to fix CID 117636 --- sched/size_regulator.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sched/size_regulator.cpp b/sched/size_regulator.cpp index 5c4f835a9f..f456789a06 100644 --- a/sched/size_regulator.cpp +++ b/sched/size_regulator.cpp @@ -83,6 +83,8 @@ int main(int argc, char** argv) { log_messages.set_debug_level(atoi(argv[++i])); } else if (!strcmp(argv[i], "--sleep_time")) { sleep_time = atoi(argv[++i]); + if (sleep_time < 0) sleep_time = 0; + if (sleep_time > 1000000) sleep_time = 1000000; } else if (!strcmp(argv[i], "--random_order")) { order_clause = " order by random "; } else if (!strcmp(argv[i], "--priority_asc")) { @@ -119,7 +121,7 @@ int main(int argc, char** argv) { exit(1); } - sprintf(buf, "where name='%s'", app_name); + snprintf(buf, sizeof(buf), "where name='%s'", app_name); if (app.lookup(buf)) { log_messages.printf(MSG_CRITICAL, "no such app: %s\n", app_name); exit(1);