Re: [libvirt] [PATCH] Remove use of strncpy in qemudExtractMonitorPath.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Daniel P. Berrange wrote:
> On Fri, Aug 28, 2009 at 04:56:14PM +0200, Chris Lalancette wrote:
>> qemudExtractMonitorPath() was doing a VIR_ALLOC_N followed by a
>> strncpy.  However, this isn't necessary; we can do the same thing
>> using strndup, which is much safer.
>>
>> Signed-off-by: Chris Lalancette <clalance@xxxxxxxxxx>
>> ---
>>  src/qemu_driver.c |    6 +++---
>>  1 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/src/qemu_driver.c b/src/qemu_driver.c
>> index 772f2f9..a40d386 100644
>> --- a/src/qemu_driver.c
>> +++ b/src/qemu_driver.c
>> @@ -1029,12 +1029,12 @@ qemudExtractMonitorPath(virConnectPtr conn,
>>       */
>>      while (*tmp) {
>>          if (c_isspace(*tmp)) {
>> -            if (VIR_ALLOC_N(*path, (tmp-dev)+1) < 0) {
>> +            *path = strndup(dev, tmp-dev);
>> +            if (*path == NULL) {
>>                  virReportOOMError(conn);
>>                  return -1;
>>              }
>> -            strncpy(*path, dev, (tmp-dev));
>> -            (*path)[(tmp-dev)] = '\0';
>> +
>>              /* ... now further update offset till we get EOL */
>>              *offset = tmp - haystack;
>>              return 0;
> 
> ACK

Committed.

-- 
Chris Lalancette

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]