{"id":810285,"url":"http://patchwork.ozlabs.org/api/patches/810285/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/patch/1504643122-14874-10-git-send-email-adhemerval.zanella@linaro.org/","project":{"id":41,"url":"http://patchwork.ozlabs.org/api/projects/41/?format=json","name":"GNU C Library","link_name":"glibc","list_id":"libc-alpha.sourceware.org","list_email":"libc-alpha@sourceware.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1504643122-14874-10-git-send-email-adhemerval.zanella@linaro.org>","list_archive_url":null,"date":"2017-09-05T20:25:22","name":"[9/9] posix: Fix glob with GLOB_NOCHECK returning modified patterns (BZ#10246)","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"1ee74c91a751314e95c84147ed739c067d1d936d","submitter":{"id":66065,"url":"http://patchwork.ozlabs.org/api/people/66065/?format=json","name":"Adhemerval Zanella Netto","email":"adhemerval.zanella@linaro.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/glibc/patch/1504643122-14874-10-git-send-email-adhemerval.zanella@linaro.org/mbox/","series":[{"id":1647,"url":"http://patchwork.ozlabs.org/api/series/1647/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/list/?series=1647","date":"2017-09-05T20:25:13","name":"posix: glob fixes and refactor","version":1,"mbox":"http://patchwork.ozlabs.org/series/1647/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/810285/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/810285/checks/","tags":{},"related":[],"headers":{"Return-Path":"<libc-alpha-return-84216-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-84216-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"RE9SAcqs\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xmyvJ5cVSz9sPs\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed,  6 Sep 2017 06:27:40 +1000 (AEST)","(qmail 51261 invoked by alias); 5 Sep 2017 20:25:59 -0000","(qmail 50633 invoked by uid 89); 5 Sep 2017 20:25:57 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:from:to:cc:subject:date:message-id:in-reply-to\n\t:references; q=dns; s=default; b=Rr9eUcmuiurdUQdn7TBWpyUencv7nDm\n\tb0kESQLTARYJXIAMrMgQNFo6WCxJCeTHrL3xnm5UaOlcA/0xKsqe/UwfEhCnlBmt\n\tj1+gXhqNLwRq4lPDrJarTR1pm15sT2MJwtCHsU6tmBheWgUtBKIfIT9EW106Wv16\n\tE/J4CH0ehpWA=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:from:to:cc:subject:date:message-id:in-reply-to\n\t:references; s=default; bh=r5pvJkGhNDRzvlyhiDJzFiWqMNw=; b=RE9SA\n\tcqsK/7hZXjq+DEV4+qO8QBTcWIeQEDqX4sqNR0Z2viTqG6Ey3q5k6KydY90ccTJ5\n\tNOYJIBZ1z+qthz4HAWSVo/kQsTp+g4LVJnOqamOSTPdXrNKvm0tJr+a1U8jb8tpr\n\tfdArcdonJajH98W6ZLnXZXfUFb/SWmUBDzipdY=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-27.6 required=5.0 tests=BAYES_00, GIT_PATCH_0,\n\tGIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=responsable, 2728,\n\tHx-languages-length:3671","X-HELO":"mail-qt0-f179.google.com","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=7QXjKJO8zzOSdkRYK7Gp21lxzE7yhu//UewS53dVdJY=;\n\tb=tplxf5XaSwWiBrUeBb9rW6Em3DuscJsE6zv5G7BgngQ90+V0am1KSdyKOFzGjMUiyb\n\tWK5dSkglCD3jTS9tG+AgJdY7lVs3uvlACWGBtNUO4LRS/MjGZCgoUPvQtIJ/Xavvqn/8\n\t5jSkBQ9cqu6rUQgiofB7UcAYBDExMbPHvIMJQG17oASkrJvmFPaVG1B6hqTPBK1TpjxT\n\trux9L/6OgNn6if5WWjY4V6hPxMsVUKhvpHgyg2YBhVdZJDEk3qTissytM1rAbfMSj70I\n\tAXK86QctT/c8uXtfNiv4TbWbFxMXwx4HAKjFGcMmO6rTo9HRrxdjOpdjda2rScv40ss6\n\tPUqw==","X-Gm-Message-State":"AHPjjUiV/RtzeQ3/grJoBxHTSsbyOO8r5ZxNAW09+ydXgOsg/yWaM5kw\n\tBXXvxaB1jqwILjXjxXOzbw==","X-Google-Smtp-Source":"ADKCNb5AsVso9ORimOJeC4SVW44hZQ7SJpmX2DL1Gy01P237rLhUgcII5ruCMHabjJ0y4RUq/bVAew==","X-Received":"by 10.200.11.13 with SMTP id e13mr446688qti.215.1504643148958;\n\tTue, 05 Sep 2017 13:25:48 -0700 (PDT)","From":"Adhemerval Zanella <adhemerval.zanella@linaro.org>","To":"libc-alpha@sourceware.org","Cc":"Paul Eggert <eggert@cs.ucla.edu>","Subject":"[PATCH 9/9] posix: Fix glob with GLOB_NOCHECK returning modified\n\tpatterns (BZ#10246)","Date":"Tue,  5 Sep 2017 17:25:22 -0300","Message-Id":"<1504643122-14874-10-git-send-email-adhemerval.zanella@linaro.org>","In-Reply-To":"<1504643122-14874-1-git-send-email-adhemerval.zanella@linaro.org>","References":"<1504643122-14874-1-git-send-email-adhemerval.zanella@linaro.org>"},"content":"According to POSIX glob with GLOB_NOCHECK should return a list consisting\nof only of the input pattern in case of no match.  However GLIBC does not\nhonor in case of '//<something'.  This is due internally this is handled\nand special case and prefix_array (responsable to prepend the directory\nname) does not know if the input already contains a slash or not since\neither '/<something>' or '//<something>' will be handle in same way.\n\nThis patch fix it by using a empty directory name for the latter (since\nprefix_array already adds a slash as default for each entry).\n\nChecked on x86_64-linux-gnu and on a build using build-many-glibcs.py\nfor all major architectures.\n\n\t[BZ #10246]\n\t* posix/glob.c (glob): Handle pattern that do not match and\n\tstart with '/' correctly.\n\t* posix/globtest.sh: New tests for NOCHECK.\n---\n ChangeLog         |  7 ++++++-\n posix/glob.c      | 13 +++++++------\n posix/globtest.sh | 37 +++++++++++++++++++++++++++++++++++++\n 3 files changed, 50 insertions(+), 7 deletions(-)","diff":"diff --git a/posix/glob.c b/posix/glob.c\nindex 30a4143..25c5d24 100644\n--- a/posix/glob.c\n+++ b/posix/glob.c\n@@ -272,6 +272,8 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int),\n   size_t oldcount;\n   int meta;\n   int dirname_modified;\n+  /* Indicate if the directory should be prepended on return values.  */\n+  bool dirname_prefix = true;\n   int malloc_dirname = 0;\n   glob_t dirs;\n   int retval = 0;\n@@ -495,6 +497,10 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int),\n       dirname = (char *) \"/\";\n       dirlen = 1;\n       ++filename;\n+      /* prefix_array adds a separator for each result and DIRNAME is\n+\t already '/'.  So we indicate later that we should not prepend\n+\t anything for this specific case.  */\n+      dirname_prefix = false;\n     }\n   else\n     {\n@@ -1086,7 +1092,7 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int),\n       if (dirlen > 0)\n \t{\n \t  /* Stick the directory on the front of each name.  */\n-\t  if (prefix_array (dirname,\n+\t  if (prefix_array (dirname_prefix ? dirname : \"\",\n \t\t\t    &pglob->gl_pathv[old_pathc + pglob->gl_offs],\n \t\t\t    pglob->gl_pathc - old_pathc))\n \t    {\n@@ -1167,11 +1173,6 @@ prefix_array (const char *dirname, char **array, size_t n)\n   size_t dirlen = strlen (dirname);\n   char dirsep_char = '/';\n \n-  if (dirlen == 1 && dirname[0] == '/')\n-    /* DIRNAME is just \"/\", so normal prepending would get us \"//foo\".\n-       We want \"/foo\" instead, so don't prepend any chars from DIRNAME.  */\n-    dirlen = 0;\n-\n #if defined __MSDOS__ || defined WINDOWS32\n   if (dirlen > 1)\n     {\ndiff --git a/posix/globtest.sh b/posix/globtest.sh\nindex 73f7ae3..92a8e37 100755\n--- a/posix/globtest.sh\n+++ b/posix/globtest.sh\n@@ -242,6 +242,43 @@ if test $failed -ne 0; then\n   result=1\n fi\n \n+# Test NOCHECK for specific cases where the pattern used starts\n+# with '/' (BZ#10246).\n+failed=0\n+${test_program_prefix} \\\n+${common_objpfx}posix/globtest -c \"$testdir\" \"/%\" |\n+sort > $testout\n+cat <<\"EOF\" | $CMP - $testout >> $logfile || failed=1\n+`/%'\n+EOF\n+if test $failed -ne 0; then\n+  echo \"No check test failed\" >> $logfile\n+  result=1\n+fi\n+\n+${test_program_prefix} \\\n+${common_objpfx}posix/globtest -c \"$testdir\" \"//%\" |\n+sort > $testout\n+cat <<\"EOF\" | $CMP - $testout >> $logfile || failed=1\n+`//%'\n+EOF\n+if test $failed -ne 0; then\n+  echo \"No check test failed\" >> $logfile\n+  result=1\n+fi\n+\n+${test_program_prefix} \\\n+${common_objpfx}posix/globtest -c \"$testdir\" \"///%\" |\n+sort > $testout\n+cat <<\"EOF\" | $CMP - $testout >> $logfile || failed=1\n+`///%'\n+EOF\n+if test $failed -ne 0; then\n+  echo \"No check test failed\" >> $logfile\n+  result=1\n+fi\n+\n+\n # Test NOMAGIC without magic characters\n failed=0\n ${test_program_prefix} \\\n","prefixes":["9/9"]}