Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[tcf-dev] [PATCH 1/2] asyncreq.c: Check return value from snprintf() for buffer overflow

---
 agent/tcf/framework/asyncreq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/agent/tcf/framework/asyncreq.c b/agent/tcf/framework/asyncreq.c
index aa1e39b..9343346 100644
--- a/agent/tcf/framework/asyncreq.c
+++ b/agent/tcf/framework/asyncreq.c
@@ -396,6 +396,7 @@ static void * worker_thread_handler(void * x) {
                     struct DirFileNode * file = req->u.dio.files + cnt;
                     struct dirent * e;
                     struct stat st;
+                    int rc;
                     errno = 0;
                     e = readdir((DIR *)req->u.dio.dir);
                     if (e == NULL) {
@@ -407,7 +408,8 @@ static void * worker_thread_handler(void * x) {
                     if (strcmp(e->d_name, "..") == 0) continue;
                     file->path = loc_strdup(e->d_name);
                     memset(&st, 0, sizeof(st));
-                    snprintf(path, sizeof(path), "%s/%s", req->u.dio.path, e->d_name);
+                    rc = snprintf(path, sizeof(path), "%s/%s", req->u.dio.path, e->d_name);
+                    if (rc >= sizeof(path) ) continue;
                     if (stat(path, &st) == 0) {
 #if defined(_WIN32) || defined(__CYGWIN__)
                         file->win32_attrs =  GetFileAttributes(path);
-- 
1.8.3.1



Back to the top