os: nullpointer check in os/path.h

Issue #3022
This commit is contained in:
Alexander Boettcher 2018-10-30 12:40:01 +01:00 committed by Norman Feske
parent 67fd3333e2
commit 85b998a4af

View File

@ -182,6 +182,7 @@ class Genode::Path_base
if (strlen(path) + orig_len + 1 >= _path_max_len) if (strlen(path) + orig_len + 1 >= _path_max_len)
throw Path_too_long(); throw Path_too_long();
if (_path)
strncpy(_path + orig_len, path, _path_max_len - orig_len); strncpy(_path + orig_len, path, _path_max_len - orig_len);
} }
@ -270,6 +271,7 @@ class Genode::Path_base
void strip_last_element() void strip_last_element()
{ {
char *p = last_element(_path); char *p = last_element(_path);
if (p)
p[p == _path ? 1 : 0] = 0; p[p == _path ? 1 : 0] = 0;
} }
@ -406,6 +408,8 @@ namespace Genode {
PATH path; PATH path;
char tmp[path.capacity()]; char tmp[path.capacity()];
memset(tmp, 0, sizeof(tmp));
size_t len = strlen(label); size_t len = strlen(label);
size_t i = 0; size_t i = 0;
@ -414,7 +418,7 @@ namespace Genode {
path.append("/"); path.append("/");
strncpy(tmp, label+i, (j-i)+1); strncpy(tmp, label+i, (j-i)+1);
/* rewrite any directory seperators */ /* rewrite any directory separators */
for (size_t k = 0; k < path.capacity(); ++k) for (size_t k = 0; k < path.capacity(); ++k)
if (tmp[k] == '/') if (tmp[k] == '/')
tmp[k] = '_'; tmp[k] = '_';
@ -426,7 +430,7 @@ namespace Genode {
} }
path.append("/"); path.append("/");
strncpy(tmp, label+i, path.capacity()); strncpy(tmp, label+i, path.capacity());
/* rewrite any directory seperators */ /* rewrite any directory separators */
for (size_t k = 0; k < path.capacity(); ++k) for (size_t k = 0; k < path.capacity(); ++k)
if (tmp[k] == '/') if (tmp[k] == '/')
tmp[k] = '_'; tmp[k] = '_';