Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 415bd4e

Browse files
jeromemarchandyonghong-song
authored andcommittedNov 1, 2018
covscan: fix miscellaneaous errors (iovisor#2003)
* Coverity #def53: COPY_PASTE_ERROR * Coverity #def18: DC.STREAM_BUFFER. Double-check max length of dev * Coverity #def44: MISSING_BREAK. This looks like it should be here * Coverity #def67: STRING_NULL: potential OOB read if 0 bytes read. * Coverity #def66: FORWARD_NULL: potential null ptr deref * Coverity #def17: RESOURCE_LEAK: missing free() * Dont free the result of dirname dirname() may return pointers to statically allocated memory. Don't free the pointer it returns.
1 parent b998421 commit 415bd4e

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed
 

‎src/cc/bcc_elf.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ static int verify_checksum(const char *file, unsigned int crc) {
398398
static char *find_debug_via_debuglink(Elf *e, const char *binpath,
399399
int check_crc) {
400400
char fullpath[PATH_MAX];
401+
char *tmppath;
401402
char *bindir = NULL;
402403
char *res = NULL;
403404
unsigned int crc;
@@ -406,8 +407,8 @@ static char *find_debug_via_debuglink(Elf *e, const char *binpath,
406407
if (!find_debuglink(e, &name, &crc))
407408
return NULL;
408409

409-
bindir = strdup(binpath);
410-
bindir = dirname(bindir);
410+
tmppath = strdup(binpath);
411+
bindir = dirname(tmppath);
411412

412413
// Search for the file in 'binpath', but ignore the file we find if it
413414
// matches the binary itself: the binary will always be probed later on,
@@ -434,9 +435,11 @@ static char *find_debug_via_debuglink(Elf *e, const char *binpath,
434435
}
435436

436437
DONE:
437-
free(bindir);
438-
if (res && check_crc && !verify_checksum(res, crc))
438+
free(tmppath);
439+
if (res && check_crc && !verify_checksum(res, crc)) {
440+
free(res);
439441
return NULL;
442+
}
440443
return res;
441444
}
442445

‎src/cc/bcc_proc.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ int bcc_procutils_each_module(int pid, bcc_procutils_modulecb callback,
9292
if (!procmap)
9393
return -1;
9494

95-
char buf[PATH_MAX + 1], perm[5], dev[8];
95+
char buf[PATH_MAX + 1], perm[5], dev[6];
9696
char *name;
9797
uint64_t begin, end, inode;
9898
unsigned long long offset;
9999
while (true) {
100100
buf[0] = '\0';
101101
// From fs/proc/task_mmu.c:show_map_vma
102-
if (fscanf(procmap, "%lx-%lx %s %llx %s %lu%[^\n]", &begin, &end, perm,
102+
if (fscanf(procmap, "%lx-%lx %4s %llx %5s %lu%[^\n]", &begin, &end, perm,
103103
&offset, dev, &inode, buf) != 7)
104104
break;
105105

‎src/cc/frontends/b/type_check.cc

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ StatusTuple TypeCheck::visit_binop_expr_node(BinopExprNode *n) {
204204
case Tok::TCGT:
205205
case Tok::TCGE:
206206
n->bit_width_ = 1;
207+
break;
207208
default:
208209
n->bit_width_ = std::max(n->lhs_->bit_width_, n->rhs_->bit_width_);
209210
}

‎src/cc/frontends/p4/compiler/ebpfTable.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def __init__(self, match_fields, program):
110110
ebpfHeader = program.getInstance(instance.name)
111111
assert isinstance(ebpfHeader, ebpfInstance.SimpleInstance)
112112
basetype = ebpfHeader.type
113-
eInstance = program.getInstance(instance.base_name)
113+
eInstance = program.getInstance(instance.name)
114114

115115
ebpfField = basetype.getField(fieldname)
116116
assert isinstance(ebpfField, ebpfStructType.EbpfField)

‎src/cc/libbpf.c

+11-9
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,16 @@ int bpf_prog_load(enum bpf_prog_type prog_type, const char *name,
521521
}
522522
}
523523

524-
if (strncmp(name, "kprobe__", 8) == 0)
525-
name_offset = 8;
526-
else if (strncmp(name, "tracepoint__", 12) == 0)
527-
name_offset = 12;
528-
else if (strncmp(name, "raw_tracepoint__", 16) == 0)
529-
name_offset = 16;
530-
memcpy(attr.prog_name, name + name_offset,
531-
min(name_len - name_offset, BPF_OBJ_NAME_LEN - 1));
524+
if (name_len) {
525+
if (strncmp(name, "kprobe__", 8) == 0)
526+
name_offset = 8;
527+
else if (strncmp(name, "tracepoint__", 12) == 0)
528+
name_offset = 12;
529+
else if (strncmp(name, "raw_tracepoint__", 16) == 0)
530+
name_offset = 16;
531+
memcpy(attr.prog_name, name + name_offset,
532+
min(name_len - name_offset, BPF_OBJ_NAME_LEN - 1));
533+
}
532534

533535
ret = syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr));
534536
// BPF object name is not supported on older Kernels.
@@ -698,7 +700,7 @@ static int bpf_get_retprobe_bit(const char *event_type)
698700
close(fd);
699701
if (ret < 0 || ret >= sizeof(buf))
700702
return -1;
701-
if (strlen(buf) < strlen("config:"))
703+
if (strncmp(buf, "config:", strlen("config:")))
702704
return -1;
703705
errno = 0;
704706
ret = (int)strtol(buf + strlen("config:"), NULL, 10);

0 commit comments

Comments
 (0)
Please sign in to comment.