From 256b6bb3dbab5a2c02f8bbc0a2aa674277ac29b8 Mon Sep 17 00:00:00 2001 From: nnorwitz Date: Sun, 16 Apr 2017 22:21:35 -0700 Subject: [PATCH] Don't blow out the stack. Use a smaller buffer and prevent buffer overruns with snprintf. --- modules/core/src/system.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index e5402614eb..1951af0c4d 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -859,9 +859,10 @@ void error( const Exception& exc ) else { const char* errorStr = cvErrorStr(exc.code); - char buf[1 << 16]; + char buf[1 << 12]; - sprintf( buf, "OpenCV Error: %s (%s) in %s, file %s, line %d", + snprintf( buf, sizeof(buf), + "OpenCV Error: %s (%s) in %s, file %s, line %d", errorStr, exc.err.c_str(), exc.func.size() > 0 ? exc.func.c_str() : "unknown function", exc.file.c_str(), exc.line ); fprintf( stderr, "%s\n", buf );