/*
* 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 <errno.h>
+
+#include "wimlib/alloca.h"
#include "wimlib/assert.h"
#include "wimlib/compiler.h"
#include "wimlib/endianness.h"
#include "wimlib/reparse.h"
#include "wimlib/resource.h"
-#ifdef HAVE_ALLOCA_H
-# include <alloca.h>
-#endif
-#include <errno.h>
-#include <stdlib.h>
-
/*
* Read the data from a symbolic link, junction, or mount point reparse point
* buffer into a `struct reparse_data'.
(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);
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;