Re: [ros-diffs] [reactos] 01/01: Implement IRP_MN_QUERY_DEVICE_TEXT.DeviceTextLocationInformation

[email protected] Mon, 07 Dec 2020 10:31:47 +0100
Newsgroups gmane.os.reactos.kernel
Message-ID <[email protected]>
Eric,

Can we please refrain from using sprintf, strlen and the like in kernel-mod=
e =

drivers ? =

Expecially on buffers which are obviously too small for their purpose ?

Please use functions from ntstrsafe.h and work directly on W-buffers, thank=
s.

Thanks
J=E9r=F4me

Le dimanche 6 d=E9cembre 2020, 12:45:55 CET Eric Kohl a =E9crit :
> https://git.reactos.org/?p=3Dreactos.git;a=3Dcommitdiff;h=3Dcac7b003c04c1=
f42f45221
> 56c2d2f77996b271c2
> =

> commit cac7b003c04c1f42f4522156c2d2f77996b271c2
> Author:     Eric Kohl <[email protected]>
> AuthorDate: Sun Dec 6 12:42:50 2020 +0100
> Commit:     Eric Kohl <[email protected]>
> 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 1006=
44
> --- 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 =3D 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 =3D IoGetCurrentIrpStackLocation(Irp);
> =

>      InquiryData =3D &DeviceExtension->InquiryData;
> @@ -196,9 +198,8 @@ PdoHandleQueryDeviceText(
>      switch (IoStack->Parameters.QueryDeviceText.DeviceTextType)
>      {
>          case DeviceTextDescription:
> -        case DeviceTextLocationInformation:
>          {
> -            DPRINT("PdoHandleQueryDeviceText\n");
> +            DPRINT("DeviceTextDescription\n");
> =

>              Offset +=3D CopyFieldTruncate(InquiryData->VendorId,
>                                          &LocalBuffer[Offset],
> @@ -227,6 +228,33 @@ PdoHandleQueryDeviceText(
>              Irp->IoStatus.Information =3D
> (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 =3D 0;
> +            DeviceDescription.MaximumLength =3D (USHORT)((strlen(LocalBu=
ffer)
> + 1) * sizeof(WCHAR)); +            DeviceDescription.Buffer =3D
> ExAllocatePoolWithTag(PagedPool, +                                       =
  =

>                    DeviceDescription.MaximumLength, +                    =
  =

>                                       TAG_SCSIPORT); +            if
> (!DeviceDescription.Buffer)
> +            {
> +                Irp->IoStatus.Information =3D 0;
> +                return STATUS_INSUFFICIENT_RESOURCES;
> +            }
> +
> +            RtlAnsiStringToUnicodeString(&DeviceDescription, &AnsiString,
> FALSE); +
> +            Irp->IoStatus.Information =3D
> (ULONG_PTR)DeviceDescription.Buffer; +            return STATUS_SUCCESS;
> +        }
> +
>          default:
>          {
>              Irp->IoStatus.Information =3D 0;