X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Freparse.c;h=ff46e9b1061d683469e00b1718d3e871258c70ad;hb=b8ebc57d493d7b6e660a50f7789fcb5451f5d77d;hp=4df2a4b428831fd02cee77329a5ba198ba0a2514;hpb=cc7b6ee47d4037ae8fa11b4c2d5154091d543704;p=wimlib diff --git a/src/reparse.c b/src/reparse.c index 4df2a4b4..ff46e9b1 100644 --- a/src/reparse.c +++ b/src/reparse.c @@ -5,26 +5,27 @@ /* * Copyright (C) 2012, 2013 Eric Biggers * - * This file is part of wimlib, a library for working with WIM files. + * This file is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. * - * wimlib is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) - * any later version. - * - * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more + * This file is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * - * You should have received a copy of the GNU General Public License - * along with wimlib; if not, see http://www.gnu.org/licenses/. + * You should have received a copy of the GNU Lesser General Public License + * along with this file; if not, see http://www.gnu.org/licenses/. */ #ifdef HAVE_CONFIG_H # include "config.h" #endif +#include + +#include "wimlib/alloca.h" #include "wimlib/assert.h" #include "wimlib/compiler.h" #include "wimlib/endianness.h" @@ -35,12 +36,6 @@ #include "wimlib/reparse.h" #include "wimlib/resource.h" -#ifdef HAVE_ALLOCA_H -# include -#endif -#include -#include - /* * Read the data from a symbolic link, junction, or mount point reparse point * buffer into a `struct reparse_data'. @@ -117,6 +112,19 @@ make_reparse_buffer(const struct reparse_data * restrict rpdata, (struct reparse_buffer_disk*)rpbuf; u8 *data; + if (rpdata->rptag == WIM_IO_REPARSE_TAG_SYMLINK) + data = rpbuf_disk->symlink.data; + else + data = rpbuf_disk->junction.data; + + if ((data - rpbuf) + rpdata->substitute_name_nbytes + + rpdata->print_name_nbytes + + 2 * sizeof(utf16lechar) > REPARSE_POINT_MAX_SIZE) + { + ERROR("Reparse data is too long!"); + return WIMLIB_ERR_INVALID_REPARSE_DATA; + } + rpbuf_disk->rptag = cpu_to_le32(rpdata->rptag); rpbuf_disk->rpreserved = cpu_to_le16(rpdata->rpreserved); rpbuf_disk->symlink.substitute_name_offset = cpu_to_le16(0); @@ -124,23 +132,12 @@ make_reparse_buffer(const struct reparse_data * restrict rpdata, rpbuf_disk->symlink.print_name_offset = cpu_to_le16(rpdata->substitute_name_nbytes + 2); rpbuf_disk->symlink.print_name_nbytes = cpu_to_le16(rpdata->print_name_nbytes); - if (rpdata->rptag == WIM_IO_REPARSE_TAG_SYMLINK) { + if (rpdata->rptag == WIM_IO_REPARSE_TAG_SYMLINK) rpbuf_disk->symlink.rpflags = cpu_to_le32(rpdata->rpflags); - data = rpbuf_disk->symlink.data; - } else { - data = rpbuf_disk->junction.data; - } /* We null-terminate the substitute and print names, although this may * not be strictly necessary. Note that the byte counts should not * include the null terminators. */ - if (data + rpdata->substitute_name_nbytes + - rpdata->print_name_nbytes + - 2 * sizeof(utf16lechar) - rpbuf > REPARSE_POINT_MAX_SIZE) - { - ERROR("Reparse data is too long!"); - return WIMLIB_ERR_INVALID_REPARSE_DATA; - } data = mempcpy(data, rpdata->substitute_name, rpdata->substitute_name_nbytes); *(utf16lechar*)data = cpu_to_le16(0); data += 2;