summaryrefslogtreecommitdiff
path: root/devel/gdb/files/commit-0064d22
blob: 5e778814432306436fa4d8d0bf4fc4468652fdfb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
commit 0064d22386b99c047bbff3bcc73b6bfce9c29b4c
Author: John Baldwin <jhb@FreeBSD.org>
Date:   Mon Jul 4 19:19:48 2016 -0700

    Handle version 1a of FreeBSD's NT_PRSINFO.
    
    Version 1a adds a pr_pid member containing the process ID of the
    terminating process.  The presence of pr_pid is inferred from the
    note's size.
    
    bfd/ChangeLog:
    
    	* elf.c (elfcore_grok_freebsd_psinfo): Check for minimum note size
    	and handle pr_pid if present.

diff --git bfd/elf.c bfd/elf.c
index 2cc64e8..ba1774e 100644
--- bfd/elf.c
+++ bfd/elf.c
@@ -9590,27 +9590,36 @@ elfcore_grok_freebsd_psinfo (bfd *abfd, Elf_Internal_Note *note)
 {
   size_t offset;
 
-  /* Check for version 1 in pr_version. */
-  if (bfd_h_get_32 (abfd, (bfd_byte *) note->descdata) != 1)
-    return FALSE;
-  offset = 4;
-
-  /* Skip over pr_psinfosz. */
   switch (abfd->arch_info->bits_per_word)
     {
     case 32:
-      offset += 4;
+      if (note->descsz < 108)
+	return FALSE;
       break;
 
     case 64:
-      offset += 4;	/* Padding before pr_psinfosz. */
-      offset += 8;
+      if (note->descsz < 120)
+	return FALSE;
       break;
 
     default:
       return FALSE;
     }
 
+  /* Check for version 1 in pr_version.  */
+  if (bfd_h_get_32 (abfd, (bfd_byte *) note->descdata) != 1)
+    return FALSE;
+  offset = 4;
+
+  /* Skip over pr_psinfosz. */
+  if (abfd->arch_info->bits_per_word == 32)
+    offset += 4;
+  else
+    {
+      offset += 4;	/* Padding before pr_psinfosz. */
+      offset += 8;
+    }
+
   /* pr_fname is PRFNAMESZ (16) + 1 bytes in size.  */
   elf_tdata (abfd)->core->program
     = _bfd_elfcore_strndup (abfd, note->descdata + offset, 17);
@@ -9619,6 +9628,17 @@ elfcore_grok_freebsd_psinfo (bfd *abfd, Elf_Internal_Note *note)
   /* pr_psargs is PRARGSZ (80) + 1 bytes in size.  */
   elf_tdata (abfd)->core->command
     = _bfd_elfcore_strndup (abfd, note->descdata + offset, 81);
+  offset += 81;
+
+  /* Padding before pr_pid.  */
+  offset += 2;
+
+  /* The pr_pid field was added in version "1a".  */
+  if (note->descsz < offset + 4)
+    return TRUE;
+
+  elf_tdata (abfd)->core->pid
+    = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + offset);
 
   return TRUE;
 }