From 85b998a4aff335f9d1f07c7dde30f61bd2a94531 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Tue, 30 Oct 2018 12:40:01 +0100 Subject: [PATCH] os: nullpointer check in os/path.h Issue #3022 --- repos/os/include/os/path.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/repos/os/include/os/path.h b/repos/os/include/os/path.h index 233b9b21a3..663edf2a37 100644 --- a/repos/os/include/os/path.h +++ b/repos/os/include/os/path.h @@ -182,7 +182,8 @@ class Genode::Path_base if (strlen(path) + orig_len + 1 >= _path_max_len) throw Path_too_long(); - strncpy(_path + orig_len, path, _path_max_len - orig_len); + if (_path) + strncpy(_path + orig_len, path, _path_max_len - orig_len); } void _append_slash_if_needed() @@ -270,7 +271,8 @@ class Genode::Path_base void strip_last_element() { char *p = last_element(_path); - p[p == _path ? 1 : 0] = 0; + if (p) + p[p == _path ? 1 : 0] = 0; } bool equals(Path_base const &ref) const { return strcmp(ref._path, _path) == 0; } @@ -406,6 +408,8 @@ namespace Genode { PATH path; char tmp[path.capacity()]; + memset(tmp, 0, sizeof(tmp)); + size_t len = strlen(label); size_t i = 0; @@ -414,7 +418,7 @@ namespace Genode { path.append("/"); strncpy(tmp, label+i, (j-i)+1); - /* rewrite any directory seperators */ + /* rewrite any directory separators */ for (size_t k = 0; k < path.capacity(); ++k) if (tmp[k] == '/') tmp[k] = '_'; @@ -426,7 +430,7 @@ namespace Genode { } path.append("/"); strncpy(tmp, label+i, path.capacity()); - /* rewrite any directory seperators */ + /* rewrite any directory separators */ for (size_t k = 0; k < path.capacity(); ++k) if (tmp[k] == '/') tmp[k] = '_';