summaryrefslogtreecommitdiffstats
path: root/gnu
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1998-01-18 13:18:55 +0000
committerbde <bde@FreeBSD.org>1998-01-18 13:18:55 +0000
commit938d820d5a3e694964732999b1f9167790f51cd2 (patch)
tree18b555035a8948cd4e9d63cfa2694e4665636c7c /gnu
parent731bdc143f08722842da1c37feec854720379de2 (diff)
downloadFreeBSD-src-938d820d5a3e694964732999b1f9167790f51cd2.zip
FreeBSD-src-938d820d5a3e694964732999b1f9167790f51cd2.tar.gz
Fixed endless loop for `p/x *(int *)0xf0000000'. kvm_uread() in
gdb was cloned from the buggy version of kvm_uread() in libkvm and had the same bugs. It looped endlessly on EOF and checked errno without setting it in the lseek() error check. The first bug caused gdb to loop endlessly for reads from addresses between the end of the user area and the start of the kernel text. kvm_uread() should not be used for addresses beyond the end of the user area, but is due to bugs elsewhere.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/usr.bin/binutils/gdb/i386/kvm-fbsd.c17
-rw-r--r--gnu/usr.bin/binutils/gdb/kvm-fbsd.c17
-rw-r--r--gnu/usr.bin/gdb/gdb/kvm-fbsd.c17
3 files changed, 30 insertions, 21 deletions
diff --git a/gnu/usr.bin/binutils/gdb/i386/kvm-fbsd.c b/gnu/usr.bin/binutils/gdb/i386/kvm-fbsd.c
index 8004a38..5cb03113 100644
--- a/gnu/usr.bin/binutils/gdb/i386/kvm-fbsd.c
+++ b/gnu/usr.bin/binutils/gdb/i386/kvm-fbsd.c
@@ -578,11 +578,8 @@ kvm_uread (core_kd, p, memaddr, myaddr, len)
if (devmem)
{
- cp = myaddr;
-
sprintf (procfile, "/proc/%d/mem", p->p_pid);
fd = open (procfile, O_RDONLY, 0);
-
if (fd < 0)
{
error ("cannot open %s", procfile);
@@ -590,12 +587,13 @@ kvm_uread (core_kd, p, memaddr, myaddr, len)
return (0);
}
+ cp = myaddr;
while (len > 0)
{
- if (lseek (fd, memaddr, 0) == -1 && errno != 0)
+ errno = 0;
+ if (lseek (fd, (off_t)memaddr, 0) == -1 && errno != 0)
{
- error ("invalid address (%x) in %s",
- memaddr, procfile);
+ error ("invalid address (%x) in %s", memaddr, procfile);
break;
}
amount = read (fd, cp, len);
@@ -604,13 +602,18 @@ kvm_uread (core_kd, p, memaddr, myaddr, len)
error ("error reading %s", procfile);
break;
}
+ if (amount == 0)
+ {
+ error ("EOF reading %s", procfile);
+ break;
+ }
cp += amount;
memaddr += amount;
len -= amount;
}
close (fd);
- return (ssize_t) (cp - myaddr);
+ return ((ssize_t) (cp - myaddr));
}
else
return (kernel_core_file_hook (core_kd, memaddr, myaddr, len));
diff --git a/gnu/usr.bin/binutils/gdb/kvm-fbsd.c b/gnu/usr.bin/binutils/gdb/kvm-fbsd.c
index 8004a38..5cb03113 100644
--- a/gnu/usr.bin/binutils/gdb/kvm-fbsd.c
+++ b/gnu/usr.bin/binutils/gdb/kvm-fbsd.c
@@ -578,11 +578,8 @@ kvm_uread (core_kd, p, memaddr, myaddr, len)
if (devmem)
{
- cp = myaddr;
-
sprintf (procfile, "/proc/%d/mem", p->p_pid);
fd = open (procfile, O_RDONLY, 0);
-
if (fd < 0)
{
error ("cannot open %s", procfile);
@@ -590,12 +587,13 @@ kvm_uread (core_kd, p, memaddr, myaddr, len)
return (0);
}
+ cp = myaddr;
while (len > 0)
{
- if (lseek (fd, memaddr, 0) == -1 && errno != 0)
+ errno = 0;
+ if (lseek (fd, (off_t)memaddr, 0) == -1 && errno != 0)
{
- error ("invalid address (%x) in %s",
- memaddr, procfile);
+ error ("invalid address (%x) in %s", memaddr, procfile);
break;
}
amount = read (fd, cp, len);
@@ -604,13 +602,18 @@ kvm_uread (core_kd, p, memaddr, myaddr, len)
error ("error reading %s", procfile);
break;
}
+ if (amount == 0)
+ {
+ error ("EOF reading %s", procfile);
+ break;
+ }
cp += amount;
memaddr += amount;
len -= amount;
}
close (fd);
- return (ssize_t) (cp - myaddr);
+ return ((ssize_t) (cp - myaddr));
}
else
return (kernel_core_file_hook (core_kd, memaddr, myaddr, len));
diff --git a/gnu/usr.bin/gdb/gdb/kvm-fbsd.c b/gnu/usr.bin/gdb/gdb/kvm-fbsd.c
index 8004a38..5cb03113 100644
--- a/gnu/usr.bin/gdb/gdb/kvm-fbsd.c
+++ b/gnu/usr.bin/gdb/gdb/kvm-fbsd.c
@@ -578,11 +578,8 @@ kvm_uread (core_kd, p, memaddr, myaddr, len)
if (devmem)
{
- cp = myaddr;
-
sprintf (procfile, "/proc/%d/mem", p->p_pid);
fd = open (procfile, O_RDONLY, 0);
-
if (fd < 0)
{
error ("cannot open %s", procfile);
@@ -590,12 +587,13 @@ kvm_uread (core_kd, p, memaddr, myaddr, len)
return (0);
}
+ cp = myaddr;
while (len > 0)
{
- if (lseek (fd, memaddr, 0) == -1 && errno != 0)
+ errno = 0;
+ if (lseek (fd, (off_t)memaddr, 0) == -1 && errno != 0)
{
- error ("invalid address (%x) in %s",
- memaddr, procfile);
+ error ("invalid address (%x) in %s", memaddr, procfile);
break;
}
amount = read (fd, cp, len);
@@ -604,13 +602,18 @@ kvm_uread (core_kd, p, memaddr, myaddr, len)
error ("error reading %s", procfile);
break;
}
+ if (amount == 0)
+ {
+ error ("EOF reading %s", procfile);
+ break;
+ }
cp += amount;
memaddr += amount;
len -= amount;
}
close (fd);
- return (ssize_t) (cp - myaddr);
+ return ((ssize_t) (cp - myaddr));
}
else
return (kernel_core_file_hook (core_kd, memaddr, myaddr, len));
OpenPOWER on IntegriCloud