- case KERN_PANICINFO_IMAGE16:
- bitdepth = 16;
- /* and fall through */
- case KERN_PANICINFO_IMAGE32:
- /* allocate a buffer for the image pathname */
- MALLOC_ZONE(imname, char *, MAXPATHLEN, M_NAMEI, M_WAITOK);
-
- if (!newp) {
- bcopy(image_pathname, imname, image_pathlen);
- imname[image_pathlen] = '\0';
- } else
- imname[0] = '\0';
- error = sysctl_string(oldp, oldlenp, newp, newlen,
- imname, MAXPATHLEN);
- if (newp && !error) {
- char *tmpstr, *oldstr;
- off_t filesize = 0;
- size_t len;
- vm_offset_t image;
- vm_offset_t oimage;
- vm_size_t osize;
-
- len = strlen(imname);
- oldstr = image_pathname;
-
- error = panicimage_from_file(imname, imagesizelimit,
- &image, &filesize, p);
- if (error)
+ /* check the length of the incoming image before allocating space for it. */
+ if ( newlen > (size_t)image_size_limit ) {
+ error = ENOMEM;
+ break;
+ }
+
+ /* allocate some kernel wired memory for the new image */
+ kret = kmem_alloc(kernel_map, &newimage, (vm_size_t)round_page(newlen));
+
+ if (kret != KERN_SUCCESS) {
+ switch (kret) {
+ default:
+ error = EINVAL;
+ break;
+ case KERN_NO_SPACE:
+ case KERN_RESOURCE_SHORTAGE:
+ error = ENOMEM;
+ break;
+ case KERN_PROTECTION_FAILURE:
+ error = EPERM;
+ break;
+ }
+ break;
+ }
+
+ /* copy the image in from user space */
+ if ( (error = copyin(newp, (char *) newimage, newlen)) )