Eric,

Can we please refrain from using sprintf, strlen and the like in kernel-mode 
drivers ? 
Expecially on buffers which are obviously too small for their purpose ?

Please use functions from ntstrsafe.h and work directly on W-buffers, thanks.

Thanks
Jérôme

Le dimanche 6 décembre 2020, 12:45:55 CET Eric Kohl a écrit :
> https://git.reactos.org/?p=reactos.git;a=commitdiff;h=cac7b003c04c1f42f45221
> 56c2d2f77996b271c2
> 
> commit cac7b003c04c1f42f4522156c2d2f77996b271c2
> Author:     Eric Kohl <eric.k...@reactos.org>
> AuthorDate: Sun Dec 6 12:42:50 2020 +0100
> Commit:     Eric Kohl <eric.k...@reactos.org>
> CommitDate: Sun Dec 6 12:42:50 2020 +0100
> 
>     Implement IRP_MN_QUERY_DEVICE_TEXT.DeviceTextLocationInformation
> ---
>  drivers/storage/port/scsiport/pdo.c | 34 +++++++++++++++++++++++++++++++---
> 1 file changed, 31 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/storage/port/scsiport/pdo.c
> b/drivers/storage/port/scsiport/pdo.c index 182f2b029ec..5ddbd7e2b34 100644
> --- a/drivers/storage/port/scsiport/pdo.c
> +++ b/drivers/storage/port/scsiport/pdo.c
> @@ -185,10 +185,12 @@ PdoHandleQueryDeviceText(
>      PIO_STACK_LOCATION IoStack;
>      UINT32 Offset = 0;
>      PINQUIRYDATA InquiryData;
> -    CHAR LocalBuffer[sizeof(InquiryData->VendorId) +
> sizeof(InquiryData->ProductId) + 2]; +    CHAR LocalBuffer[40];
>      ANSI_STRING AnsiString;
>      UNICODE_STRING DeviceDescription;
> 
> +    DPRINT("PdoHandleQueryDeviceText\n");
> +
>      IoStack = IoGetCurrentIrpStackLocation(Irp);
> 
>      InquiryData = &DeviceExtension->InquiryData;
> @@ -196,9 +198,8 @@ PdoHandleQueryDeviceText(
>      switch (IoStack->Parameters.QueryDeviceText.DeviceTextType)
>      {
>          case DeviceTextDescription:
> -        case DeviceTextLocationInformation:
>          {
> -            DPRINT("PdoHandleQueryDeviceText\n");
> +            DPRINT("DeviceTextDescription\n");
> 
>              Offset += CopyFieldTruncate(InquiryData->VendorId,
>                                          &LocalBuffer[Offset],
> @@ -227,6 +228,33 @@ PdoHandleQueryDeviceText(
>              Irp->IoStatus.Information =
> (ULONG_PTR)DeviceDescription.Buffer; return STATUS_SUCCESS;
>          }
> +
> +        case DeviceTextLocationInformation:
> +        {
> +            DPRINT("DeviceTextLocationInformation\n");
> +
> +            sprintf(LocalBuffer, "Bus Number %d, Target ID %d, LUN %d",
> +                    DeviceExtension->PathId, DeviceExtension->TargetId,
> DeviceExtension->Lun); +
> +            RtlInitAnsiString(&AnsiString, (PCSZ)&LocalBuffer);
> +
> +            DeviceDescription.Length = 0;
> +            DeviceDescription.MaximumLength = (USHORT)((strlen(LocalBuffer)
> + 1) * sizeof(WCHAR)); +            DeviceDescription.Buffer =
> ExAllocatePoolWithTag(PagedPool, +                                         
>                    DeviceDescription.MaximumLength, +                      
>                                       TAG_SCSIPORT); +            if
> (!DeviceDescription.Buffer)
> +            {
> +                Irp->IoStatus.Information = 0;
> +                return STATUS_INSUFFICIENT_RESOURCES;
> +            }
> +
> +            RtlAnsiStringToUnicodeString(&DeviceDescription, &AnsiString,
> FALSE); +
> +            Irp->IoStatus.Information =
> (ULONG_PTR)DeviceDescription.Buffer; +            return STATUS_SUCCESS;
> +        }
> +
>          default:
>          {
>              Irp->IoStatus.Information = 0;





_______________________________________________
Ros-dev mailing list
Ros-dev@reactos.org
http://reactos.org/mailman/listinfo/ros-dev

Reply via email to