From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DA54A46AE6 for ; Thu, 3 Jul 2025 16:28:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BEE1E40264; Thu, 3 Jul 2025 16:28:12 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 86E6A40264 for ; Thu, 3 Jul 2025 16:28:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751552890; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wnS7FHnB67+5iepYi/v//JGF4u49bm31aZEEkoIs0ww=; b=QhDu1DHNInxPZ37Z1+GzuP7FE4sxYnSyM3hrwOWyor2BuljPyZd1+sqM13KPoMy4RcqcyY IcQXeX38j5PswSJEG3rYhuXq/XMEzmZGGuEZfmlWWZp9OI1hLz8kgh9LmdBR9ptDDjNiLz R1DVsWqQSxHyEvdSwFwWKLM44dhJYuo= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-668-s8KsXitBM4-tAylsowaUnA-1; Thu, 03 Jul 2025 10:28:08 -0400 X-MC-Unique: s8KsXitBM4-tAylsowaUnA-1 X-Mimecast-MFC-AGG-ID: s8KsXitBM4-tAylsowaUnA_1751552887 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-553b396258eso3596227e87.3 for ; Thu, 03 Jul 2025 07:28:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751552887; x=1752157687; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wnS7FHnB67+5iepYi/v//JGF4u49bm31aZEEkoIs0ww=; b=uRaq9B5WhTUe8hgZnEy9n5RMOVRxqKapMnNQutsMLkw3OvuyX3hP0tNdBwBd+hMlLH 8OO3jcAm97FONkGvOuykv8+6DCTKfN2yruiF4pbofJ+fAk9eDD8VG67+wa6pErBQzlCw OdLP/GtD8OgZ2ZqN6yADK6lHAi+BMjaVJ4DEHWJpm9rvzsIJnDj8frCuGXvcaKgaXcPD uJoqtj3t7A17Kra1m3wNcePu+rD3ylLIt6PVAuzAxUx6WpugMcSKFcQRUKA6VbijXfae 7BYLhqdUV2BZyt/U25xBJQADR4hGpaQeaf+ZwuD/3RVHjQIINZ0mJ9tGW3bHHqbXk2tk 9PcA== X-Forwarded-Encrypted: i=1; AJvYcCVhW03PoQWki0VjPZH9LCie4gWcJLyNKPBjPUVyawkgkIhF09zHT4zo3XuMNxxb9RgzAnscrXA=@dpdk.org X-Gm-Message-State: AOJu0Yz4kpmbgcMA1hjoIZfuEn+TEpjJvPXOlk1UiMM8lagJ9t991URv z4zkWruYQvcyrwGQcxcNGdQRkomesUi+8DXXHYo4HETdr8/gBcx3qBkgjw6v+k+5ve/o/xNNREn SXY3zuj7qhRfmbL70Qtz8DTuwd5XiUn27eplkgOOhhhi0r/KYCpm05YnYBI432zS6aPeyFR2QFg 0SKXv+R9am4tN0O0gjttODMzs= X-Gm-Gg: ASbGncvtXPhcQEkI79FvtnHvB6HKUGCYVAI82tZ9WV56zGHHy6O6JBhYbcGgSWyu8jB QnwmF1a7MEiwCnLhGXr0MehcEOk/UJlEKBPfw5tunYolsJS77/jRPCv67LASlVSLAkEutRmzHy8 HDgkljzA== X-Received: by 2002:a05:6512:3185:b0:553:aa2d:1af5 with SMTP id 2adb3069b0e04-5562ee1feeamr1327469e87.8.1751552886993; Thu, 03 Jul 2025 07:28:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvAmXdv14Cd01fUP/wjsOZTIkudS4aByRxkxZCrYuc07nrX7uPE6TEyNcCVomUUj14txKb+tErHuhp/s8/LtA= X-Received: by 2002:a05:6512:3185:b0:553:aa2d:1af5 with SMTP id 2adb3069b0e04-5562ee1feeamr1327464e87.8.1751552886482; Thu, 03 Jul 2025 07:28:06 -0700 (PDT) MIME-Version: 1.0 References: <20250619071037.37325-1-david.marchand@redhat.com> <20250623135242.461965-1-david.marchand@redhat.com> <20250623135242.461965-5-david.marchand@redhat.com> In-Reply-To: From: David Marchand Date: Thu, 3 Jul 2025 16:27:53 +0200 X-Gm-Features: Ac12FXwc5HWwD5fWPGyLK6v16YIB4ypf3E-m9XhqYZKlpLFqvevcOb7mbjbB-hM Message-ID: Subject: Re: [PATCH v2 04/10] eal: fix plugin dir walk To: Marat Khalili Cc: "dev@dpdk.org" , "stable@dpdk.org" , Bruce Richardson , Tyler Retzlaff , Timothy Redaelli , Maxime Coquelin X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: iGHDngjLBSxaOLdf_9PSIOSU1_O9wE251r1P9jMAIns_1751552887 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org On Wed, Jun 25, 2025 at 10:43=E2=80=AFAM Marat Khalili wrote: > > Thank you for doing this. > > > +static bool > > +ends_with(const char *str, size_t str_len, const char *tail) > > I too think we should have a general ends_with, I for one had to code one= just this week. However, I do not think it should support non-null-termina= ted strings. > > > +{ > > + size_t tail_len =3D strlen(tail); > > + > > + return str_len >=3D tail_len && strncmp(&str[str_len - tail_len],= tail, > > tail_len) =3D=3D 0; > > +} > > Note that when str is not null-terminated and both str_len and tail_len a= re zeroes &str[str_len - tail_len] will dereference one character after the= end before taking a reference to it again, which would be a UB. (Won't hap= pen in your case of course since your tail is always non-empty, but may hap= pen if this function is moved into a general-use library.) As a generic helper, it would be worth to make it more robust. Though here, as a fix, I would avoid adding a helper so the backport can be done without adding a new API. > > > @@ -417,13 +425,12 @@ eal_plugindir_init(const char *path) > > } > > > > while ((dent =3D readdir(d)) !=3D NULL) { > > + size_t nlen =3D strnlen(dent->d_name, sizeof(dent->d_name= )); > > struct stat sb; > > - int nlen =3D strnlen(dent->d_name, sizeof(dent->d_name)); > > > > /* check if name ends in .so or .so.ABI_VERSION */ > > - if (strcmp(&dent->d_name[nlen - 3], ".so") !=3D 0 && > > - strcmp(&dent->d_name[nlen - 4 - strlen(ABI_VERSION)], > > - ".so."ABI_VERSION) !=3D 0) > > + if (!ends_with(dent->d_name, nlen, ".so") && > > + !ends_with(dent->d_name, nlen, ".so."ABI_= VERSION)) > > continue; > > I do not think we should try to handle the non-null-terminated dent->d_na= me case here, I'd just delete nlen and everything related to it. To be supe= r-defensive we could add a check that `memchr(dent->d_name, 0, sizeof(dent-= >d_name)) !=3D NULL`, but I don't think it's needed. > Mm, good point. I did not reevaluate this part of the code, but it is indeed odd trying to protect against a non null terminated dent->d_name here. https://pubs.opengroup.org/onlinepubs/007904875/basedefs/dirent.h.html """ The character array d_name is of unspecified size, but the number of bytes preceding the terminating null byte shall not exceed {NAME_MAX}. """ I'll rework this local helper so it assumes null terminated strings. --=20 David Marchand