Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F108445392
D44419.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D44419.diff
View Options
diff --git a/usr.sbin/kldxref/ef.h b/usr.sbin/kldxref/ef.h
--- a/usr.sbin/kldxref/ef.h
+++ b/usr.sbin/kldxref/ef.h
@@ -189,6 +189,10 @@
int elf_read_raw_data_alloc(struct elf_file *efile, off_t offset,
size_t len, void **out);
+/* Reads a single string at the given offset from an ELF file. */
+int elf_read_raw_string(struct elf_file *efile, off_t offset, char *dst,
+ size_t len);
+
/*
* Read relocated data from an ELF file and return it in a
* dynamically-allocated buffer. Note that no translation
diff --git a/usr.sbin/kldxref/ef.c b/usr.sbin/kldxref/ef.c
--- a/usr.sbin/kldxref/ef.c
+++ b/usr.sbin/kldxref/ef.c
@@ -549,7 +549,6 @@
ef_seg_read_string(elf_file_t ef, GElf_Addr address, size_t len, char *dest)
{
GElf_Off ofs;
- int error;
ofs = ef_get_offset(ef, address);
if (ofs == 0) {
@@ -559,13 +558,7 @@
return (EFAULT);
}
- error = elf_read_raw_data(ef->ef_efile, ofs, dest, len);
- if (error != 0)
- return (error);
- if (strnlen(dest, len) == len)
- return (EFAULT);
-
- return (0);
+ return (elf_read_raw_string(ef->ef_efile, ofs, dest, len));
}
int
diff --git a/usr.sbin/kldxref/ef_obj.c b/usr.sbin/kldxref/ef_obj.c
--- a/usr.sbin/kldxref/ef_obj.c
+++ b/usr.sbin/kldxref/ef_obj.c
@@ -248,7 +248,6 @@
ef_obj_seg_read_string(elf_file_t ef, GElf_Addr address, size_t len, char *dest)
{
GElf_Off ofs;
- int error;
ofs = ef_obj_get_offset(ef, address);
if (ofs == 0) {
@@ -258,13 +257,7 @@
return (EFAULT);
}
- error = elf_read_raw_data(ef->ef_efile, ofs, dest, len);
- if (error != 0)
- return (error);
- if (strnlen(dest, len) == len)
- return (EFAULT);
-
- return (0);
+ return (elf_read_raw_string(ef->ef_efile, ofs, dest, len));
}
int
diff --git a/usr.sbin/kldxref/elf.c b/usr.sbin/kldxref/elf.c
--- a/usr.sbin/kldxref/elf.c
+++ b/usr.sbin/kldxref/elf.c
@@ -197,6 +197,24 @@
return (0);
}
+int
+elf_read_raw_string(struct elf_file *efile, off_t offset, char *dst, size_t len)
+{
+ ssize_t nread;
+
+ nread = pread(efile->ef_fd, dst, len, offset);
+ if (nread == -1)
+ return (errno);
+ if (nread == 0)
+ return (EIO);
+
+ /* A short read is ok so long as the data contains a terminator. */
+ if (strnlen(dst, nread) == nread)
+ return (EFAULT);
+
+ return (0);
+}
+
int
elf_read_data(struct elf_file *efile, Elf_Type type, off_t offset, size_t len,
void **out)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 25, 8:27 PM (19 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16162237
Default Alt Text
D44419.diff (2 KB)
Attached To
Mode
D44419: kldxref: Properly handle reading strings near the end of an ELF file
Attached
Detach File
Event Timeline
Log In to Comment