FreeBSD Bugzilla – Attachment 164966 Details for
Bug 205806
bsdinstall(8): partedit can hang/crash on read/lseek/malloc failures
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
malloc + read in a loop -> mmap
mmap.patch (text/plain), 1.30 KB, created by
will
on 2016-01-02 19:53:55 UTC
(
hide
)
Description:
malloc + read in a loop -> mmap
Filename:
MIME Type:
Creator:
will
Created:
2016-01-02 19:53:55 UTC
Size:
1.30 KB
patch
obsolete
>Index: partedit/gpart_ops.c >=================================================================== >--- partedit/gpart_ops.c (revision 293048) >+++ partedit/gpart_ops.c (working copy) >@@ -28,6 +28,7 @@ > > #include <sys/param.h> > #include <sys/stat.h> >+#include <sys/mman.h> > #include <errno.h> > #include <libutil.h> > #include <inttypes.h> >@@ -380,7 +381,7 @@ > struct gctl_req *r; > const char *errstr, *scheme; > uint8_t *boot; >- size_t bootsize, bytes; >+ ssize_t bootsize; > int bootfd; > > /* >@@ -406,13 +407,19 @@ > } > > bootsize = lseek(bootfd, 0, SEEK_END); >- boot = malloc(bootsize); >- lseek(bootfd, 0, SEEK_SET); >- bytes = 0; >- while (bytes < bootsize) >- bytes += read(bootfd, boot + bytes, bootsize - bytes); >- close(bootfd); >+ if (bootsize == -1) { >+ dialog_msgbox("Bootcode Error", strerror(errno), 0, 0, >+ TRUE); >+ return; >+ } > >+ boot = mmap(0, bootsize, PROT_READ, 0, bootfd, 0); >+ if (boot == MAP_FAILED) { >+ dialog_msgbox("Bootcode Error", strerror(errno), 0, 0, >+ TRUE); >+ return; >+ } >+ > r = gctl_get_handle(); > gctl_ro_param(r, "class", -1, "PART"); > gctl_ro_param(r, "arg0", -1, gp->lg_name); >@@ -423,7 +430,8 @@ > if (errstr != NULL && errstr[0] != '\0') > gpart_show_error("Bootcode Error", NULL, errstr); > gctl_free(r); >- free(boot); >+ munmap(boot, bootsize); >+ close(bootfd); > } > > static void
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 205806
: 164966