diff options
author | Sander Vrijders <[email protected]> | 2018-09-27 11:43:02 +0200 |
---|---|---|
committer | Dimitri Staessens <[email protected]> | 2018-09-28 11:02:44 +0200 |
commit | 937f2b345aa76272a1c80828e7666ab87611c0d1 (patch) | |
tree | 7075a29558228d12b385ffaa488fe96b93e2584c /src/lib/rib.c | |
parent | 656d1ffc2abdec309cd892b54b310da30fa08095 (diff) | |
download | ouroboros-937f2b345aa76272a1c80828e7666ab87611c0d1.tar.gz ouroboros-937f2b345aa76272a1c80828e7666ab87611c0d1.zip |
lib: Check return values init functions
This will check the return values of init functions so that the code
is more robust. It also removes a duplicate init in the timerwheel,
checks for buffer overflows in the RIB and checks string lengths.
Signed-off-by: Sander Vrijders <[email protected]>
Signed-off-by: Dimitri Staessens <[email protected]>
Diffstat (limited to 'src/lib/rib.c')
-rw-r--r-- | src/lib/rib.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/lib/rib.c b/src/lib/rib.c index 685575e5..88db9ed8 100644 --- a/src/lib/rib.c +++ b/src/lib/rib.c @@ -101,6 +101,9 @@ static int rib_read(const char * path, char comp[RIB_PATH_LEN + 1]; char * c; + if (strlen(path) > RIB_PATH_LEN) + return -1; + strcpy(comp, path + 1); c = strstr(comp, "/"); @@ -183,6 +186,9 @@ static size_t __getattr(const char * path, char comp[RIB_PATH_LEN + 1]; char * c; + if (strlen(path) > RIB_PATH_LEN) + return -1; + strcpy(comp, path + 1); c = strstr(comp, "/"); @@ -282,7 +288,8 @@ int rib_init(const char * mountpt) if (stat(rib.mnt, &st) == -1) switch(errno) { case ENOENT: - mkdir(rib.mnt, 0777); + if (mkdir(rib.mnt, 0777)) + return -1; break; case ENOTCONN: fuse_unmount(rib.mnt, rib.ch); @@ -385,6 +392,12 @@ int rib_reg(const char * path, return -ENOMEM; } + if (strlen(path) > RIB_PATH_LEN) { + pthread_rwlock_unlock(&rib.lock); + free(rc); + return -1; + } + strcpy(rc->path, path); rc->ops = ops; |