src/windows/native/java/io/canonicalize_md.c

Print this page


   1 /*
   2  * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 162     char *p = start;
 163     while (*p) {
 164         if ((p = strchr(p, '.')) == NULL) // find next occurence of '.'
 165             return 0; // no more dots
 166         p++; // next char
 167         while ((*p) == '.') // go to the end of dots
 168             p++;
 169         if (*p && (*p != '\\')) // path element does not end with a dot
 170             p++; // go to the next char
 171         else
 172             return 1; // path element does end with a dot - prohibited
 173     }
 174     return 0; // no prohibited combinations of dots found
 175 }
 176 
 177 /* Wide character version of dots */
 178 static int
 179 wdots(WCHAR *start)
 180 {
 181     WCHAR *p = start;




 182     while (*p) {
 183         if ((p = wcschr(p, L'.')) == NULL) // find next occurence of '.'
 184             return 0; // no more dots
 185         p++; // next char
 186         while ((*p) == L'.') // go to the end of dots
 187             p++;
 188         if (*p && (*p != L'\\')) // path element does not end with a dot
 189             p++; // go to the next char
 190         else
 191             return 1; // path element does end with a dot - prohibited
 192     }
 193     return 0; // no prohibited combinations of dots found
 194 }
 195 
 196 /* If the lookup of a particular prefix fails because the file does not exist,
 197    because it is of the wrong type, because access is denied, or because the
 198    network is unreachable then canonicalization does not fail, it terminates
 199    successfully after copying the rest of the original path to the result path.
 200    Other I/O errors cause an error return.
 201 */


   1 /*
   2  * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 162     char *p = start;
 163     while (*p) {
 164         if ((p = strchr(p, '.')) == NULL) // find next occurence of '.'
 165             return 0; // no more dots
 166         p++; // next char
 167         while ((*p) == '.') // go to the end of dots
 168             p++;
 169         if (*p && (*p != '\\')) // path element does not end with a dot
 170             p++; // go to the next char
 171         else
 172             return 1; // path element does end with a dot - prohibited
 173     }
 174     return 0; // no prohibited combinations of dots found
 175 }
 176 
 177 /* Wide character version of dots */
 178 static int
 179 wdots(WCHAR *start)
 180 {
 181     WCHAR *p = start;
 182     // Skip "\\.\" prefix
 183     if (wcslen(p) > 4 && !wcsncmp(p, L"\\\\.\\", 4))
 184         p = p + 4;
 185 
 186     while (*p) {
 187         if ((p = wcschr(p, L'.')) == NULL) // find next occurence of '.'
 188             return 0; // no more dots
 189         p++; // next char
 190         while ((*p) == L'.') // go to the end of dots
 191             p++;
 192         if (*p && (*p != L'\\')) // path element does not end with a dot
 193             p++; // go to the next char
 194         else
 195             return 1; // path element does end with a dot - prohibited
 196     }
 197     return 0; // no prohibited combinations of dots found
 198 }
 199 
 200 /* If the lookup of a particular prefix fails because the file does not exist,
 201    because it is of the wrong type, because access is denied, or because the
 202    network is unreachable then canonicalization does not fail, it terminates
 203    successfully after copying the rest of the original path to the result path.
 204    Other I/O errors cause an error return.
 205 */