From: Stefan Hajnoczi <stefanha@gmail.com>
To: Programmingkid <programmingkidx@gmail.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-devel qemu-devel <qemu-devel@nongnu.org>,
Qemu-block <qemu-block@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v3] raw-posix.c: Make physical devices usable in QEMU under Mac OS X host
Date: Fri, 24 Jul 2015 16:00:20 +0100 [thread overview]
Message-ID: <20150724150020.GA26843@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <4E49353C-F0D9-43CA-B4FE-BB5E85FCEEDC@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2908 bytes --]
On Fri, Jul 17, 2015 at 08:19:16PM -0400, Programmingkid wrote:
> @@ -2014,7 +2015,9 @@ kern_return_t GetBSDPath( io_iterator_t mediaIterator, char *bsdPath, CFIndex ma
> if ( bsdPathAsCFString ) {
> size_t devPathLength;
> strcpy( bsdPath, _PATH_DEV );
> - strcat( bsdPath, "r" );
> + if (flags & BDRV_O_NOCACHE) {
> + strcat(bsdPath, "r");
> + }
> devPathLength = strlen( bsdPath );
> if ( CFStringGetCString( bsdPathAsCFString, bsdPath + devPathLength, maxPathSize - devPathLength, kCFStringEncodingASCII ) ) {
> kernResult = KERN_SUCCESS;
This hunk should be a separate patch. It fixes raw-posix alignment
probing by only using the raw char device (which has alignment
constraints) if BDRV_O_NOCACHE was given.
> @@ -2027,7 +2030,35 @@ kern_return_t GetBSDPath( io_iterator_t mediaIterator, char *bsdPath, CFIndex ma
> return kernResult;
> }
>
> -#endif
> +/* Sets up a real cdrom for use in QEMU */
> +static bool setupCDROM(char *bsdPath)
> +{
> + int index, numOfTestPartitions = 2, fd;
> + char testPartition[MAXPATHLEN];
> + bool partitionFound = false;
> +
> + /* look for a working partition */
> + for (index = 0; index < numOfTestPartitions; index++) {
> + pstrcpy(testPartition, strlen(bsdPath)+1, bsdPath);
The safe way to use pstrcpy is:
char dest[LEN];
pstrcpy(dest, sizeof(dest), src);
Use the destination buffer size since that's what needs to be checked to
prevent buffer overflow.
Using the source buffer size could cause an overflow if the source
buffer is larger than the destination buffer. Even if that's not the
case today, it's bad practice because it could lead to bugs if code is
modified.
> + snprintf(testPartition, MAXPATHLEN, "%ss%d", testPartition, index);
Using the same buffer as the destination and a format string argument is
questionable. I wouldn't be surprised if some snprintf()
implementations produce garbage when you make them read from the same
buffer they are writing to.
Please replace pstrcpy() and snprintf() with a single call:
snprintf(testPartition, sizeof(testPartition), "%ss%d", bsdPath, index);
> + fd = qemu_open(testPartition, O_RDONLY | O_BINARY | O_LARGEFILE);
> + if (fd >= 0) {
> + partitionFound = true;
> + qemu_close(fd);
> + break;
> + }
> + }
> +
> + /* if a working partition on the device was not found */
> + if (partitionFound == false) {
> + printf("Error: Failed to find a working partition on disc!\n");
> + } else {
> + DPRINTF("Using %s as optical disc\n", testPartition);
> + pstrcpy(bsdPath, strlen(testPartition)+1, testPartition);
Please use MAXPATHLEN instead of strlen(testPartition)+1.
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2015-07-24 15:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-18 0:19 [Qemu-devel] [PATCH v3] raw-posix.c: Make physical devices usable in QEMU under Mac OS X host Programmingkid
2015-07-24 15:00 ` Stefan Hajnoczi [this message]
2015-07-24 15:37 ` Programmingkid
2015-07-27 10:27 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150724150020.GA26843@stefanha-thinkpad.redhat.com \
--to=stefanha@gmail.com \
--cc=kwolf@redhat.com \
--cc=programmingkidx@gmail.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).