Skip to content

Commit 2fb9b3c

Browse files
jasondellalucepoiana
authored andcommitted
update(userspace): narrow down buf boundaries
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
1 parent 333394b commit 2fb9b3c

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

userspace/libscap/linux/scap_fds.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int32_t scap_fd_handle_pipe(struct scap_proclist* proclist, char *fname, scap_th
7575
uint64_t ino;
7676
struct stat sb;
7777

78-
r = readlink(fname, link_name, SCAP_MAX_PATH_SIZE);
78+
r = readlink(fname, link_name, SCAP_MAX_PATH_SIZE - 1);
7979
if (r <= 0)
8080
{
8181
return scap_errprintf(error, errno, "Could not read link %s", fname);
@@ -274,7 +274,7 @@ int32_t scap_fd_handle_regular_file(struct scap_proclist *proclist, char *fname,
274274
char link_name[SCAP_MAX_PATH_SIZE];
275275
ssize_t r;
276276

277-
r = readlink(fname, link_name, SCAP_MAX_PATH_SIZE);
277+
r = readlink(fname, link_name, SCAP_MAX_PATH_SIZE - 1);
278278
if (r <= 0)
279279
{
280280
return SCAP_SUCCESS;
@@ -382,7 +382,7 @@ int32_t scap_fd_handle_socket(struct scap_proclist *proclist, char *fname, scap_
382382
}
383383
}
384384

385-
r = readlink(fname, link_name, SCAP_MAX_PATH_SIZE);
385+
r = readlink(fname, link_name, SCAP_MAX_PATH_SIZE - 1);
386386
if(r <= 0)
387387
{
388388
return SCAP_SUCCESS;
@@ -1227,7 +1227,7 @@ int32_t scap_fd_scan_fd_dir(scap_t *handle, char *procdir, scap_threadinfo *tinf
12271227
// Get the network namespace of the process
12281228
//
12291229
snprintf(f_name, sizeof(f_name), "%sns/net", procdir);
1230-
r = readlink(f_name, link_name, sizeof(link_name));
1230+
r = readlink(f_name, link_name, sizeof(link_name) - 1);
12311231
if(r <= 0)
12321232
{
12331233
//

userspace/libscap/linux/scap_procs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,10 @@ int32_t scap_proc_fill_root(char* error, struct scap_threadinfo* tinfo, const ch
557557
{
558558
char root_path[SCAP_MAX_PATH_SIZE];
559559
snprintf(root_path, sizeof(root_path), "%sroot", procdirname);
560-
if ( readlink(root_path, tinfo->root, sizeof(tinfo->root)) > 0)
560+
ssize_t r = readlink(root_path, tinfo->root, sizeof(tinfo->root) - 1);
561+
if (r > 0)
561562
{
563+
tinfo->root[r] = '\0';
562564
return SCAP_SUCCESS;
563565
}
564566
else

userspace/libsinsp/parsers.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4561,6 +4561,7 @@ void sinsp_parser::parse_getcwd_exit(sinsp_evt *evt)
45614561

45624562
if(target_res > 0)
45634563
{
4564+
target_name[target_res] = '\0';
45644565
if(target_name != evt->m_tinfo->get_cwd())
45654566
{
45664567
printf("%s != %s", target_name, evt->m_tinfo->get_cwd().c_str());

userspace/libsinsp/sinsp_auth.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ std::string sinsp_ssl::memorize_file(const std::string& disk_file)
6868
char buf[FILENAME_MAX] = { 0 };
6969
std::ifstream ifs(disk_file);
7070
std::string fd_path = "/proc/self/fd/" + std::to_string(fd);
71-
ssize_t sz = readlink(fd_path.c_str(), buf, sizeof(buf));
71+
ssize_t sz = readlink(fd_path.c_str(), buf, sizeof(buf) - 1);
7272
if(sz != -1 && sz <= static_cast<ssize_t>(sizeof(buf)))
7373
{
7474
mem_file.assign(buf, sz);

0 commit comments

Comments
 (0)