Fix null dereferences 46/249346/1
authorMichal Bloch <m.bloch@samsung.com>
Mon, 7 Dec 2020 21:16:07 +0000 (22:16 +0100)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 10 Dec 2020 09:44:30 +0000 (09:44 +0000)
Change-Id: Id23b9aaad60752f797783f9ccc6f9bbfa9357941
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
(cherry picked from commit a9a8f5e3955f55e03a05878a381257085dc02951)

src/crash-stack/proc.c

index 46f40e1..8946c21 100644 (file)
@@ -294,6 +294,8 @@ char *get_thread_states(const int *tids, int n)
 {
     int i;
     char *res = calloc(1, n);
+    if (!res)
+        return NULL;
 
     for (i = 0; i < n; ++i) {
         int state = proc_state(tids[i]);
@@ -383,6 +385,9 @@ static int copy_memory_process_vm_readv(int pid,
     remote_iov = malloc(sizeof(struct iovec)*n_frames);
     frame_bytes = malloc(sizeof(ssize_t)*n_frames);
 
+    if (!local_iov || !remote_iov || !frame_bytes)
+        goto process_vm_readv_end;
+
     for (i = 0; i < n_frames; ++i) {
         local_iov[i].iov_base = frames[i]->data;
         local_iov[i].iov_len = frames[i]->length;