Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F110667820
D6360.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
D6360.diff
View Options
Index: head/usr.sbin/acpi/acpidump/acpi.c
===================================================================
--- head/usr.sbin/acpi/acpidump/acpi.c
+++ head/usr.sbin/acpi/acpidump/acpi.c
@@ -1466,27 +1466,34 @@
void
aml_disassemble(ACPI_TABLE_HEADER *rsdt, ACPI_TABLE_HEADER *dsdp)
{
- char buf[PATH_MAX], tmpstr[PATH_MAX];
+ char buf[PATH_MAX], tmpstr[PATH_MAX], wrkdir[PATH_MAX];
+ const char *iname = "/acpdump.din";
+ const char *oname = "/acpdump.dsl";
const char *tmpdir;
- char *tmpext;
FILE *fp;
size_t len;
- int fd;
+ int fd, status;
+ pid_t pid;
tmpdir = getenv("TMPDIR");
if (tmpdir == NULL)
tmpdir = _PATH_TMP;
- strncpy(tmpstr, tmpdir, sizeof(tmpstr));
- if (realpath(tmpstr, buf) == NULL) {
+ if (realpath(tmpdir, buf) == NULL) {
perror("realpath tmp dir");
return;
}
- strncpy(tmpstr, buf, sizeof(tmpstr));
- strncat(tmpstr, "/acpidump.", sizeof(tmpstr) - strlen(buf));
- len = strlen(tmpstr);
- tmpext = tmpstr + len;
- strncpy(tmpext, "XXXXXX", sizeof(tmpstr) - len);
- fd = mkstemp(tmpstr);
+ len = sizeof(wrkdir) - strlen(iname);
+ if ((size_t)snprintf(wrkdir, len, "%s/acpidump.XXXXXX", buf) > len-1 ) {
+ fprintf(stderr, "$TMPDIR too long\n");
+ return;
+ }
+ if (mkdtemp(wrkdir) == NULL) {
+ perror("mkdtemp tmp working dir");
+ return;
+ }
+ assert((size_t)snprintf(tmpstr, sizeof(tmpstr), "%s%s", wrkdir, iname)
+ <= sizeof(tmpstr) - 1);
+ fd = open(tmpstr, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
if (fd < 0) {
perror("iasl tmp file");
return;
@@ -1495,28 +1502,46 @@
close(fd);
/* Run iasl -d on the temp file */
- if (fork() == 0) {
+ if ((pid = fork()) == 0) {
close(STDOUT_FILENO);
if (vflag == 0)
close(STDERR_FILENO);
execl("/usr/sbin/iasl", "iasl", "-d", tmpstr, NULL);
err(1, "exec");
}
-
- wait(NULL);
- unlink(tmpstr);
+ if (pid > 0)
+ wait(&status);
+ if (unlink(tmpstr) < 0) {
+ perror("unlink");
+ goto out;
+ }
+ if (pid < 0) {
+ perror("fork");
+ goto out;
+ }
+ if (status != 0) {
+ fprintf(stderr, "iast exit status = %d\n", status);
+ }
/* Dump iasl's output to stdout */
- strncpy(tmpext, "dsl", sizeof(tmpstr) - len);
+ assert((size_t)snprintf(tmpstr, sizeof(tmpstr), "%s%s", wrkdir, oname)
+ <= sizeof(tmpstr) -1);
fp = fopen(tmpstr, "r");
- unlink(tmpstr);
+ if (unlink(tmpstr) < 0) {
+ perror("unlink");
+ goto out;
+ }
if (fp == NULL) {
perror("iasl tmp file (read)");
- return;
+ goto out;
}
while ((len = fread(buf, 1, sizeof(buf), fp)) > 0)
fwrite(buf, 1, len, stdout);
fclose(fp);
+
+ out:
+ if (rmdir(wrkdir) < 0)
+ perror("rmdir");
}
void
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Feb 22, 4:44 PM (7 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16775129
Default Alt Text
D6360.diff (2 KB)
Attached To
Mode
D6360: Fix acpidump CID 1011278 (Buffer not null terminated) and other issues
Attached
Detach File
Event Timeline
Log In to Comment