]> wimlib.net Git - wimlib/blobdiff - src/reparse.c
wimboot.c: Fix format string
[wimlib] / src / reparse.c
index 4df2a4b428831fd02cee77329a5ba198ba0a2514..cf9fc686139696980cb9e17145430f7f836e6619 100644 (file)
@@ -5,20 +5,18 @@
 /*
  * 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
@@ -117,6 +115,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 +135,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;