Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1iQ7mH-0002WN-6X for mharc-grub-devel@gnu.org; Thu, 31 Oct 2019 06:34:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42286) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iQ7m9-0002ED-WD for grub-devel@gnu.org; Thu, 31 Oct 2019 06:33:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iQ7m6-0007bt-PW for grub-devel@gnu.org; Thu, 31 Oct 2019 06:33:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60028) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iQ7m4-0007YG-UW for grub-devel@gnu.org; Thu, 31 Oct 2019 06:33:54 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0E20D3695A for ; Thu, 31 Oct 2019 10:33:51 +0000 (UTC) Received: by mail-wm1-f69.google.com with SMTP id o202so864090wme.5 for ; Thu, 31 Oct 2019 03:33:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MYq84SPjFu+uCTxXmFEVBCcQ3GqTKj4KMAhqzqRKBvg=; b=TwBOrIRhBiuAGfpEZtCvbgiAEjeqPoaIlFzS+O53GD4DlbfCOnyCMRQAyfXLe9CuLr wxnJSJCliSu4Q9pS4Vx6bv7VVsX5XPdngGT5a3kFjkzSTJvYZ7wzFCOYh6SxnQjnCxcD pgpGIm3JmXS0pQmspXtQ6q00yIHp0ARqj13lhqkQ6v0lG1QA26hUEn/k3KmGqzz2NPrc BMM0MTNqMxY7zc9OMQpY8MQT1dXpeS6NVFKewViPfbTZZd4CTqfPIkbkycNNX9Leaqb+ JVy0ys5gL2yVs2XY2H0YExgc79TR38wsTVNgIjNm75v8xraBZ6SXOWC4D0+0H3VCrTt8 9MCw== X-Gm-Message-State: APjAAAU6Mwtg4IYJKu/bAtpXrzv1gEToJMzCHr/aiFpqefbsj7UFY67J U8Xl8QNwf5iYk8lNN6aVMRqTGRcplDJktRZ0nwqJW+LIBd4pDy4weLBGzDkIz3m2VUBTEHHMGXf Acx4UgSPjYGE= X-Received: by 2002:a1c:113:: with SMTP id 19mr2439762wmb.42.1572518029276; Thu, 31 Oct 2019 03:33:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqyxzkfpOG1SCxjarXz88DZVGthVI6BkhFkFcv3KwW0hYDpeIiqRibsmRnxQEaf+qDiwMWeNSg== X-Received: by 2002:a1c:113:: with SMTP id 19mr2439742wmb.42.1572518029013; Thu, 31 Oct 2019 03:33:49 -0700 (PDT) Received: from minerva.redhat.com ([90.168.169.92]) by smtp.gmail.com with ESMTPSA id t185sm4031066wmf.45.2019.10.31.03.33.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Oct 2019 03:33:48 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Lenny Szubowicz , Mark Salter , Javier Martinez Canillas Subject: [PATCH] tftp: Normalize slashes in tftp paths Date: Thu, 31 Oct 2019 11:33:39 +0100 Message-Id: <20191031103339.2682-1-javierm@redhat.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Oct 2019 10:34:03 -0000 From: Lenny Szubowicz Some tftp servers do not handle multiple consecutive slashes correctly; this patch avoids sending tftp requests with non-normalized paths. Signed-off-by: Lenny Szubowicz Signed-off-by: Mark Salter Signed-off-by: Javier Martinez Canillas --- grub-core/net/tftp.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git grub-core/net/tftp.c grub-core/net/tftp.c index 7d90bf66e76..6dbb9cdbb7a 100644 --- grub-core/net/tftp.c +++ grub-core/net/tftp.c @@ -300,6 +300,25 @@ destroy_pq (tftp_data_t data) grub_priority_queue_destroy (data->pq); } =20 +/* Create a normalized copy of the filename. + Compress any string of consecutive forward slashes to a single forwar= d + slash. */ +static void +grub_normalize_filename (char *normalized, const char *filename) +{ + char *dest =3D normalized; + const char *src =3D filename; + + while (*src !=3D '\0') + { + if (src[0] =3D=3D '/' && src[1] =3D=3D '/') + src++; + else + *dest++ =3D *src++; + } + *dest =3D '\0'; +} + static grub_err_t tftp_open (struct grub_file *file, const char *filename) { @@ -337,9 +356,12 @@ tftp_open (struct grub_file *file, const char *filen= ame) rrqlen =3D 0; =20 tftph->opcode =3D grub_cpu_to_be16_compile_time (TFTP_RRQ); - grub_strcpy (rrq, filename); - rrqlen +=3D grub_strlen (filename) + 1; - rrq +=3D grub_strlen (filename) + 1; + + /* Copy and normalize the filename to work-around issues on some tftp + servers when file names are being matched for remapping. */ + grub_normalize_filename (rrq, filename); + rrqlen +=3D grub_strlen (rrq) + 1; + rrq +=3D grub_strlen (rrq) + 1; =20 grub_strcpy (rrq, "octet"); rrqlen +=3D grub_strlen ("octet") + 1; --=20 2.21.0