util: fix possible buffer overflow in util_get_process_exec_path
authorMarcin Ślusarz <marcin.slusarz@intel.com>
Fri, 24 Jul 2020 16:14:24 +0000 (18:14 +0200)
committerMarge Bot <eric+marge@anholt.net>
Thu, 30 Jul 2020 10:41:00 +0000 (10:41 +0000)
Found by Coverity.

Signed-off-by: Marcin Ślusarz <marcin.slusarz@intel.com>
Fixes: f8f1413070a ("util/u_process: add util_get_process_exec_path")
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6067>

src/util/u_process.c

index 74c4d10192ef34eb7a388ff9b7e583ef66d1038e..68fda93a53bb22515fb5c04f64d85534d8640df7 100644 (file)
@@ -187,6 +187,9 @@ util_get_process_exec_path(char* process_path, size_t len)
 
     return 0;
 success:
+   if (r == len)
+      return 0;
+
     process_path[r] = '\0';
     return r;