diff --git a/.gitattributes b/.gitattributes index db64e0c7..24037174 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,6 +4,7 @@ *.in eol=lf *.m4 eol=lf missing eol=lf +compile eol=lf configure eol=lf install-sh eol=lf *.sln eol=crlf diff --git a/.github/workflows/mingw.yml b/.github/workflows/mingw.yml index 34306e4b..2552b3ef 100644 --- a/.github/workflows/mingw.yml +++ b/.github/workflows/mingw.yml @@ -48,6 +48,7 @@ jobs: install: >- mingw-w64-${{ matrix.env }}-toolchain base-devel + autotools git upx diff --git a/install-sh b/install-sh index e3e4aa8e..ec298b53 100644 --- a/install-sh +++ b/install-sh @@ -1,7 +1,7 @@ #!/bin/sh # install - install a program, script, or datafile -scriptversion=2009-04-28.21; # UTC +scriptversion=2020-11-14.01; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the @@ -35,25 +35,21 @@ scriptversion=2009-04-28.21; # UTC # FSF changes to this file are in the public domain. # # Calling this script install-sh is preferred over install.sh, to prevent -# `make' implicit rules from creating a file called install from it +# 'make' implicit rules from creating a file called install from it # when there is no Makefile. # # This script is compatible with the BSD install script, but was written # from scratch. +tab=' ' nl=' ' -IFS=" "" $nl" +IFS=" $tab$nl" -# set DOITPROG to echo to test this script +# Set DOITPROG to "echo" to test this script. -# Don't use :- since 4.3BSD and earlier shells don't like it. doit=${DOITPROG-} -if test -z "$doit"; then - doit_exec=exec -else - doit_exec=$doit -fi +doit_exec=${doit:-exec} # Put in absolute file names if you don't have them in your path; # or use environment vars. @@ -68,22 +64,16 @@ mvprog=${MVPROG-mv} rmprog=${RMPROG-rm} stripprog=${STRIPPROG-strip} -posix_glob='?' -initialize_posix_glob=' - test "$posix_glob" != "?" || { - if (set -f) 2>/dev/null; then - posix_glob= - else - posix_glob=: - fi - } -' - posix_mkdir= # Desired mode of installed file. mode=0755 +# Create dirs (including intermediate dirs) using mode 755. +# This is like GNU 'install' as of coreutils 8.32 (2020). +mkdir_umask=22 + +backupsuffix= chgrpcmd= chmodcmd=$chmodprog chowncmd= @@ -97,7 +87,7 @@ dir_arg= dst_arg= copy_on_change=false -no_target_directory= +is_target_a_directory=possibly usage="\ Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE @@ -114,18 +104,28 @@ Options: --version display version info and exit. -c (ignored) - -C install only if different (preserve the last data modification time) + -C install only if different (preserve data modification time) -d create directories instead of installing files. -g GROUP $chgrpprog installed files to GROUP. -m MODE $chmodprog installed files to MODE. -o USER $chownprog installed files to USER. + -p pass -p to $cpprog. -s $stripprog installed files. + -S SUFFIX attempt to back up existing files, with suffix SUFFIX. -t DIRECTORY install into DIRECTORY. -T report an error if DSTFILE is a directory. Environment variables override the default commands: CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG + +By default, rm is invoked with -f; when overridden with RMPROG, +it's up to you to specify -f if you want it. + +If -S is not specified, no backups are attempted. + +Email bug reports to bug-automake@gnu.org. +Automake home page: https://www.gnu.org/software/automake/ " while test $# -ne 0; do @@ -137,42 +137,62 @@ while test $# -ne 0; do -d) dir_arg=true;; -g) chgrpcmd="$chgrpprog $2" - shift;; + shift;; --help) echo "$usage"; exit $?;; -m) mode=$2 - case $mode in - *' '* | *' '* | *' -'* | *'*'* | *'?'* | *'['*) - echo "$0: invalid mode: $mode" >&2 - exit 1;; - esac - shift;; + case $mode in + *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) + echo "$0: invalid mode: $mode" >&2 + exit 1;; + esac + shift;; -o) chowncmd="$chownprog $2" - shift;; + shift;; + + -p) cpprog="$cpprog -p";; -s) stripcmd=$stripprog;; - -t) dst_arg=$2 - shift;; + -S) backupsuffix="$2" + shift;; - -T) no_target_directory=true;; + -t) + is_target_a_directory=always + dst_arg=$2 + # Protect names problematic for 'test' and other utilities. + case $dst_arg in + -* | [=\(\)!]) dst_arg=./$dst_arg;; + esac + shift;; + + -T) is_target_a_directory=never;; --version) echo "$0 $scriptversion"; exit $?;; - --) shift - break;; + --) shift + break;; - -*) echo "$0: invalid option: $1" >&2 - exit 1;; + -*) echo "$0: invalid option: $1" >&2 + exit 1;; *) break;; esac shift done +# We allow the use of options -d and -T together, by making -d +# take the precedence; this is for compatibility with GNU install. + +if test -n "$dir_arg"; then + if test -n "$dst_arg"; then + echo "$0: target directory not allowed when installing a directory." >&2 + exit 1 + fi +fi + if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then # When -d is used, all remaining arguments are directories to create. # When -t is used, the destination is already specified. @@ -186,6 +206,10 @@ if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then fi shift # arg dst_arg=$arg + # Protect names problematic for 'test' and other utilities. + case $dst_arg in + -* | [=\(\)!]) dst_arg=./$dst_arg;; + esac done fi @@ -194,13 +218,26 @@ if test $# -eq 0; then echo "$0: no input file specified." >&2 exit 1 fi - # It's OK to call `install-sh -d' without argument. + # It's OK to call 'install-sh -d' without argument. # This can happen when creating conditional directories. exit 0 fi if test -z "$dir_arg"; then - trap '(exit $?); exit' 1 2 13 15 + if test $# -gt 1 || test "$is_target_a_directory" = always; then + if test ! -d "$dst_arg"; then + echo "$0: $dst_arg: Is not a directory." >&2 + exit 1 + fi + fi +fi + +if test -z "$dir_arg"; then + do_exit='(exit $ret); exit $ret' + trap "ret=129; $do_exit" 1 + trap "ret=130; $do_exit" 2 + trap "ret=141; $do_exit" 13 + trap "ret=143; $do_exit" 15 # Set umask so as not to create temps with too-generous modes. # However, 'strip' requires both read and write access to temps. @@ -211,16 +248,16 @@ if test -z "$dir_arg"; then *[0-7]) if test -z "$stripcmd"; then - u_plus_rw= + u_plus_rw= else - u_plus_rw='% 200' + u_plus_rw='% 200' fi cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; *) if test -z "$stripcmd"; then - u_plus_rw= + u_plus_rw= else - u_plus_rw=,u+rw + u_plus_rw=,u+rw fi cp_umask=$mode$u_plus_rw;; esac @@ -228,9 +265,9 @@ fi for src do - # Protect names starting with `-'. + # Protect names problematic for 'test' and other utilities. case $src in - -*) src=./$src;; + -* | [=\(\)!]) src=./$src;; esac if test -n "$dir_arg"; then @@ -238,6 +275,10 @@ do dstdir=$dst test -d "$dstdir" dstdir_status=$? + # Don't chown directories that already exist. + if test $dstdir_status = 0; then + chowncmd="" + fi else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command @@ -252,185 +293,150 @@ do echo "$0: no destination specified." >&2 exit 1 fi - dst=$dst_arg - # Protect names starting with `-'. - case $dst in - -*) dst=./$dst;; - esac - # If destination is a directory, append the input filename; won't work - # if double slashes aren't ignored. + # If destination is a directory, append the input filename. if test -d "$dst"; then - if test -n "$no_target_directory"; then - echo "$0: $dst_arg: Is a directory" >&2 - exit 1 + if test "$is_target_a_directory" = never; then + echo "$0: $dst_arg: Is a directory" >&2 + exit 1 fi dstdir=$dst - dst=$dstdir/`basename "$src"` + dstbase=`basename "$src"` + case $dst in + */) dst=$dst$dstbase;; + *) dst=$dst/$dstbase;; + esac dstdir_status=0 else - # Prefer dirname, but fall back on a substitute if dirname fails. - dstdir=` - (dirname "$dst") 2>/dev/null || - expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$dst" : 'X\(//\)[^/]' \| \ - X"$dst" : 'X\(//\)$' \| \ - X"$dst" : 'X\(/\)' \| . 2>/dev/null || - echo X"$dst" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ - s//\1/ - q - } - /^X\(\/\/\)[^/].*/{ - s//\1/ - q - } - /^X\(\/\/\)$/{ - s//\1/ - q - } - /^X\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q' - ` - + dstdir=`dirname "$dst"` test -d "$dstdir" dstdir_status=$? fi fi + case $dstdir in + */) dstdirslash=$dstdir;; + *) dstdirslash=$dstdir/;; + esac + obsolete_mkdir_used=false if test $dstdir_status != 0; then case $posix_mkdir in '') - # Create intermediate dirs using mode 755 as modified by the umask. - # This is like FreeBSD 'install' as of 1997-10-28. - umask=`umask` - case $stripcmd.$umask in - # Optimize common cases. - *[2367][2367]) mkdir_umask=$umask;; - .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; + # With -d, create the new directory with the user-specified mode. + # Otherwise, rely on $mkdir_umask. + if test -n "$dir_arg"; then + mkdir_mode=-m$mode + else + mkdir_mode= + fi - *[0-7]) - mkdir_umask=`expr $umask + 22 \ - - $umask % 100 % 40 + $umask % 20 \ - - $umask % 10 % 4 + $umask % 2 - `;; - *) mkdir_umask=$umask,go-w;; - esac + posix_mkdir=false + # The $RANDOM variable is not portable (e.g., dash). Use it + # here however when possible just to lower collision chance. + tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ - # With -d, create the new directory with the user-specified mode. - # Otherwise, rely on $mkdir_umask. - if test -n "$dir_arg"; then - mkdir_mode=-m$mode + trap ' + ret=$? + rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null + exit $ret + ' 0 + + # Because "mkdir -p" follows existing symlinks and we likely work + # directly in world-writeable /tmp, make sure that the '$tmpdir' + # directory is successfully created first before we actually test + # 'mkdir -p'. + if (umask $mkdir_umask && + $mkdirprog $mkdir_mode "$tmpdir" && + exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 + then + if test -z "$dir_arg" || { + # Check for POSIX incompatibilities with -m. + # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or + # other-writable bit of parent directory when it shouldn't. + # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. + test_tmpdir="$tmpdir/a" + ls_ld_tmpdir=`ls -ld "$test_tmpdir"` + case $ls_ld_tmpdir in + d????-?r-*) different_mode=700;; + d????-?--*) different_mode=755;; + *) false;; + esac && + $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { + ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` + test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" + } + } + then posix_mkdir=: + fi + rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" else - mkdir_mode= + # Remove any dirs left behind by ancient mkdir implementations. + rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null fi - - posix_mkdir=false - case $umask in - *[123567][0-7][0-7]) - # POSIX mkdir -p sets u+wx bits regardless of umask, which - # is incompatible with FreeBSD 'install' when (umask & 300) != 0. - ;; - *) - tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ - trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 - - if (umask $mkdir_umask && - exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 - then - if test -z "$dir_arg" || { - # Check for POSIX incompatibilities with -m. - # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or - # other-writeable bit of parent directory when it shouldn't. - # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. - ls_ld_tmpdir=`ls -ld "$tmpdir"` - case $ls_ld_tmpdir in - d????-?r-*) different_mode=700;; - d????-?--*) different_mode=755;; - *) false;; - esac && - $mkdirprog -m$different_mode -p -- "$tmpdir" && { - ls_ld_tmpdir_1=`ls -ld "$tmpdir"` - test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" - } - } - then posix_mkdir=: - fi - rmdir "$tmpdir/d" "$tmpdir" - else - # Remove any dirs left behind by ancient mkdir implementations. - rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null - fi - trap '' 0;; - esac;; + trap '' 0;; esac if $posix_mkdir && ( - umask $mkdir_umask && - $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" + umask $mkdir_umask && + $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" ) then : else - # The umask is ridiculous, or mkdir does not conform to POSIX, + # mkdir does not conform to POSIX, # or it failed possibly due to a race condition. Create the # directory the slow way, step by step, checking for races as we go. case $dstdir in - /*) prefix='/';; - -*) prefix='./';; - *) prefix='';; + /*) prefix='/';; + [-=\(\)!]*) prefix='./';; + *) prefix='';; esac - eval "$initialize_posix_glob" - oIFS=$IFS IFS=/ - $posix_glob set -f + set -f set fnord $dstdir shift - $posix_glob set +f + set +f IFS=$oIFS prefixes= for d do - test -z "$d" && continue + test X"$d" = X && continue - prefix=$prefix$d - if test -d "$prefix"; then - prefixes= - else - if $posix_mkdir; then - (umask=$mkdir_umask && - $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break - # Don't fail if two instances are running concurrently. - test -d "$prefix" || exit 1 - else - case $prefix in - *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; - *) qprefix=$prefix;; - esac - prefixes="$prefixes '$qprefix'" - fi - fi - prefix=$prefix/ + prefix=$prefix$d + if test -d "$prefix"; then + prefixes= + else + if $posix_mkdir; then + (umask $mkdir_umask && + $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break + # Don't fail if two instances are running concurrently. + test -d "$prefix" || exit 1 + else + case $prefix in + *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; + *) qprefix=$prefix;; + esac + prefixes="$prefixes '$qprefix'" + fi + fi + prefix=$prefix/ done if test -n "$prefixes"; then - # Don't fail if two instances are running concurrently. - (umask $mkdir_umask && - eval "\$doit_exec \$mkdirprog $prefixes") || - test -d "$dstdir" || exit 1 - obsolete_mkdir_used=true + # Don't fail if two instances are running concurrently. + (umask $mkdir_umask && + eval "\$doit_exec \$mkdirprog $prefixes") || + test -d "$dstdir" || exit 1 + obsolete_mkdir_used=true fi fi fi @@ -443,14 +449,25 @@ do else # Make a couple of temp file names in the proper directory. - dsttmp=$dstdir/_inst.$$_ - rmtmp=$dstdir/_rm.$$_ + dsttmp=${dstdirslash}_inst.$$_ + rmtmp=${dstdirslash}_rm.$$_ # Trap to clean up those temp files at exit. trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 # Copy the file name to the temp name. - (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && + (umask $cp_umask && + { test -z "$stripcmd" || { + # Create $dsttmp read-write so that cp doesn't create it read-only, + # which would cause strip to fail. + if test -z "$doit"; then + : >"$dsttmp" # No need to fork-exec 'touch'. + else + $doit touch "$dsttmp" + fi + } + } && + $doit_exec $cpprog "$src" "$dsttmp") && # and set any options; do chmod last to preserve setuid bits. # @@ -465,20 +482,24 @@ do # If -C, don't bother to copy if it wouldn't change the file. if $copy_on_change && - old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && - new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && - - eval "$initialize_posix_glob" && - $posix_glob set -f && + old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && + new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && + set -f && set X $old && old=:$2:$4:$5:$6 && set X $new && new=:$2:$4:$5:$6 && - $posix_glob set +f && - + set +f && test "$old" = "$new" && $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 then rm -f "$dsttmp" else + # If $backupsuffix is set, and the file being installed + # already exists, attempt a backup. Don't worry if it fails, + # e.g., if mv doesn't support -f. + if test -n "$backupsuffix" && test -f "$dst"; then + $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null + fi + # Rename the file to the real destination. $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || @@ -486,24 +507,24 @@ do # to itself, or perhaps because mv is so ancient that it does not # support -f. { - # Now remove or move aside any old file at destination location. - # We try this two ways since rm can't unlink itself on some - # systems and the destination file might be busy for other - # reasons. In this case, the final cleanup might fail but the new - # file should still install successfully. - { - test ! -f "$dst" || - $doit $rmcmd -f "$dst" 2>/dev/null || - { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && - { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } - } || - { echo "$0: cannot unlink or rename $dst" >&2 - (exit 1); exit 1 - } - } && + # Now remove or move aside any old file at destination location. + # We try this two ways since rm can't unlink itself on some + # systems and the destination file might be busy for other + # reasons. In this case, the final cleanup might fail but the new + # file should still install successfully. + { + test ! -f "$dst" || + $doit $rmcmd "$dst" 2>/dev/null || + { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && + { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } + } || + { echo "$0: cannot unlink or rename $dst" >&2 + (exit 1); exit 1 + } + } && - # Now rename the file to the real destination. - $doit $mvcmd "$dsttmp" "$dst" + # Now rename the file to the real destination. + $doit $mvcmd "$dsttmp" "$dst" } fi || exit 1 @@ -512,10 +533,9 @@ do done # Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-time-zone: "UTC" +# time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: - \ No newline at end of file diff --git a/src/checksum.c b/src/checksum.c index 34291cb2..abca0332 100644 --- a/src/checksum.c +++ b/src/checksum.c @@ -1064,9 +1064,10 @@ INT_PTR CALLBACK ChecksumCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM safe_release_dc(GetDlgItem(hDlg, IDC_MD5), hDC); - for (i=(int)safe_strlen(image_path); (i>0)&&(image_path[i]!='\\'); i--); - if (image_path != NULL) // VS code analysis has a false positive on this one - SetWindowTextU(hDlg, &image_path[i+1]); + if (image_path != NULL) { + for (i = (int)strlen(image_path); (i > 0) && (image_path[i] != '\\'); i--); + SetWindowTextU(hDlg, &image_path[i + 1]); + } // Set focus on the OK button SendMessage(hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlg, IDOK), TRUE); CenterDialog(hDlg, NULL); diff --git a/src/dev.c b/src/dev.c index fb4c45b7..1be9b32f 100644 --- a/src/dev.c +++ b/src/dev.c @@ -655,6 +655,7 @@ BOOL GetDevices(DWORD devnum) } // Also test for "_SD&" instead of "_SD_" and so on to allow for devices like // "SCSI\DiskRicoh_Storage_SD&REV_3.0" to be detected. + assert(strlen(scsi_card_name_copy) > 1); scsi_card_name_copy[strlen(scsi_card_name_copy) - 1] = '&'; if (safe_strstr(buffer, scsi_card_name_copy) != NULL) { props.is_CARD = TRUE; @@ -668,7 +669,7 @@ BOOL GetDevices(DWORD devnum) if (!SetupDiGetDeviceInstanceIdA(dev_info, &dev_info_data, device_instance_id, sizeof(device_instance_id), &size)) { uprintf("SetupDiGetDeviceInstanceId failed: %s", WindowsErrorString()); - static_strcpy(device_instance_id, ""); + strcpy(device_instance_id, ""); } memset(buffer, 0, sizeof(buffer)); diff --git a/src/dos_locale.c b/src/dos_locale.c index 98730081..8a4dace9 100644 --- a/src/dos_locale.c +++ b/src/dos_locale.c @@ -1,7 +1,7 @@ /* * Rufus: The Reliable USB Formatting Utility * DOS keyboard locale setup - * Copyright © 2011-2020 Pete Batard + * Copyright © 2011-2021 Pete Batard * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -982,6 +982,7 @@ BOOL SetDOSLocale(const char* path, BOOL bFreeDOS) kb = "us"; kbdrv = bFreeDOS?fd_get_kbdrv(kb):ms_get_kbdrv(kb); // Always succeeds } + assert(kbdrv >= 0); uprintf("Will use DOS keyboard '%s' [%s]\n", kb, kb_to_hr(kb)); // Now get a codepage diff --git a/src/ext2fs/alloc.c b/src/ext2fs/alloc.c index ea573efb..69baf14c 100644 --- a/src/ext2fs/alloc.c +++ b/src/ext2fs/alloc.c @@ -301,8 +301,8 @@ errcode_t ext2fs_get_free_blocks2(ext2_filsys fs, blk64_t start, blk64_t finish, if (!num) num = 1; c_ratio = 1 << ext2fs_get_bitmap_granularity(map); - b &= ~(c_ratio - 1); - finish &= ~(c_ratio -1); + b &= ~((blk64_t)c_ratio - 1); + finish &= ~((blk64_t)c_ratio - 1); do { if (b + num - 1 >= ext2fs_blocks_count(fs->super)) { if (finish > start) diff --git a/src/ext2fs/ext_attr.c b/src/ext2fs/ext_attr.c index affc1a8f..0d794ea6 100644 --- a/src/ext2fs/ext_attr.c +++ b/src/ext2fs/ext_attr.c @@ -1438,7 +1438,7 @@ static errcode_t xattr_array_update(struct ext2_xattr_handle *h, return 0; } - if (h->ibody_count <= old_idx) { + if (old_idx >= 0 && h->ibody_count <= old_idx) { block_free += EXT2_EXT_ATTR_LEN(name_len); if (!h->attrs[old_idx].ea_ino) block_free += diff --git a/src/ext2fs/fileio.c b/src/ext2fs/fileio.c index a0b5d971..cac97af8 100644 --- a/src/ext2fs/fileio.c +++ b/src/ext2fs/fileio.c @@ -357,13 +357,8 @@ ext2fs_file_write_inline_data(ext2_file_t file, const void *buf, file->pos += count; /* Update inode size */ - if (count != 0 && EXT2_I_SIZE(&file->inode) < file->pos) { - errcode_t rc; - - rc = ext2fs_file_set_size2(file, file->pos); - if (retval == 0) - retval = rc; - } + if (count != 0 && EXT2_I_SIZE(&file->inode) < file->pos) + retval = ext2fs_file_set_size2(file, file->pos); if (written) *written = count; diff --git a/src/ext2fs/gen_bitmap.c b/src/ext2fs/gen_bitmap.c index c94c21b6..542d17a9 100644 --- a/src/ext2fs/gen_bitmap.c +++ b/src/ext2fs/gen_bitmap.c @@ -117,7 +117,7 @@ errcode_t ext2fs_make_generic_bitmap(errcode_t magic, ext2_filsys fs, } else bitmap->description = 0; - size = (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1); + size = (((size_t)bitmap->real_end - bitmap->start) / 8) + 1; /* Round up to allow for the BT x86 instruction */ size = (size + 7) & ~3; retval = ext2fs_get_mem(size, &bitmap->bitmap); @@ -303,7 +303,7 @@ void ext2fs_clear_generic_bitmap(ext2fs_generic_bitmap bitmap) } memset(bitmap32->bitmap, 0, - (size_t) (((bitmap32->real_end - bitmap32->start) / 8) + 1)); + (((size_t)bitmap32->real_end - bitmap32->start) / 8) + 1); } errcode_t ext2fs_fudge_generic_bitmap_end(ext2fs_inode_bitmap gen_bitmap, diff --git a/src/ext2fs/inode.c b/src/ext2fs/inode.c index c4377eeb..6e6c89f2 100644 --- a/src/ext2fs/inode.c +++ b/src/ext2fs/inode.c @@ -87,10 +87,11 @@ void ext2fs_free_inode_cache(struct ext2_inode_cache *icache) return; if (icache->buffer) ext2fs_free_mem(&icache->buffer); - for (i = 0; i < icache->cache_size; i++) - ext2fs_free_mem(&icache->cache[i].inode); - if (icache->cache) + if (icache->cache) { + for (i = 0; i < icache->cache_size; i++) + ext2fs_free_mem(&icache->cache[i].inode); ext2fs_free_mem(&icache->cache); + } icache->buffer_blk = 0; ext2fs_free_mem(&icache); } diff --git a/src/ext2fs/nt_io.c b/src/ext2fs/nt_io.c index a4231bef..36013af1 100644 --- a/src/ext2fs/nt_io.c +++ b/src/ext2fs/nt_io.c @@ -278,7 +278,7 @@ static __inline BOOLEAN _IsMounted(IN HANDLE Handle) { IO_STATUS_BLOCK IoStatusBlock; PF_INIT(NtFsControlFile, NtDll); - return (pfNtFsControlFile == NULL) ? STATUS_DLL_NOT_FOUND : + return (pfNtFsControlFile == NULL) ? FALSE : (BOOLEAN)(pfNtFsControlFile(Handle, 0, 0, 0, &IoStatusBlock, FSCTL_IS_VOLUME_MOUNTED, 0, 0, 0, 0) == STATUS_SUCCESS); } diff --git a/src/format.c b/src/format.c index 8bf57bf8..eb492d17 100644 --- a/src/format.c +++ b/src/format.c @@ -1175,6 +1175,7 @@ static BOOL SetupWinPE(char drive_letter) for (i=1; i '%s'\n", i, &buffer[i], patch_str_rep[index][j]); strcpy(&buffer[i], patch_str_rep[index][j]); i += (DWORD)max(strlen(patch_str_org[j]), strlen(patch_str_rep[index][j])); // in case org is a substring of rep @@ -2093,6 +2094,7 @@ DWORD WINAPI FormatThread(void* param) if ((hLogicalVolume != NULL) && (hLogicalVolume != INVALID_HANDLE_VALUE)) { PrintInfoDebug(0, MSG_227); if (!CloseHandle(hLogicalVolume)) { + hLogicalVolume = INVALID_HANDLE_VALUE; uprintf("Could not close volume: %s", WindowsErrorString()); FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_ACCESS_DENIED; goto out; diff --git a/src/format_ext.c b/src/format_ext.c index 6fbc5100..e60f926b 100644 --- a/src/format_ext.c +++ b/src/format_ext.c @@ -1,7 +1,7 @@ /* * Rufus: The Reliable USB Formatting Utility * extfs formatting - * Copyright © 2019-2020 Pete Batard + * Copyright © 2019-2021 Pete Batard * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -212,6 +212,7 @@ const char* GetExtFsLabel(DWORD DriveIndex, uint64_t PartitionOffset) r = ext2fs_open(volume_name, EXT2_FLAG_SKIP_MMP, 0, 0, manager, &ext2fs); free(volume_name); if (r == 0) { + assert(ext2fs != NULL); strncpy(label, ext2fs->super->s_volume_name, EXT2_LABEL_LEN); label[EXT2_LABEL_LEN] = 0; } diff --git a/src/format_fat32.c b/src/format_fat32.c index 1fd1d32d..087c8b2d 100644 --- a/src/format_fat32.c +++ b/src/format_fat32.c @@ -2,7 +2,7 @@ * Rufus: The Reliable USB Formatting Utility * Large FAT32 formatting * Copyright © 2007-2009 Tom Thornhill/Ridgecrop - * Copyright © 2011-2020 Pete Batard + * Copyright © 2011-2021 Pete Batard * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -414,7 +414,7 @@ BOOL FormatLargeFAT32(DWORD DriveIndex, uint64_t PartitionOffset, DWORD ClusterS } for (i = 0; i < (SystemAreaSize + BurstSize - 1); i += BurstSize) { - UpdateProgressWithInfo(OP_FORMAT, MSG_217, (uint64_t)i, (uint64_t)(SystemAreaSize + BurstSize)); + UpdateProgressWithInfo(OP_FORMAT, MSG_217, (uint64_t)i, (uint64_t)SystemAreaSize + BurstSize); CHECK_FOR_USER_CANCEL; if (write_sectors(hLogicalVolume, BytesPerSect, i, BurstSize, pZeroSect) != (BytesPerSect * BurstSize)) { die("Error clearing reserved sectors", ERROR_WRITE_FAULT); diff --git a/src/icon.c b/src/icon.c index b717cd02..2dd5882c 100644 --- a/src/icon.c +++ b/src/icon.c @@ -1,7 +1,7 @@ /* * Rufus: The Reliable USB Formatting Utility * Extract icon from executable and set autorun.inf - * Copyright © 2012-2019 Pete Batard + * Copyright © 2012-2021 Pete Batard * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +26,7 @@ #include #include #include +#include #include "rufus.h" #include "missing.h" @@ -185,7 +186,8 @@ BOOL SetAutorun(const char* path) uprintf("Created: %s", filename); // .inf -> .ico - filename[strlen(filename)-1] = 'o'; - filename[strlen(filename)-2] = 'c'; + assert(strlen(filename) >= 2); + filename[strlen(filename) - 1] = 'o'; + filename[strlen(filename) - 2] = 'c'; return ExtractAppIcon(filename, FALSE); } diff --git a/src/iso.c b/src/iso.c index cf55c00f..63d152a0 100644 --- a/src/iso.c +++ b/src/iso.c @@ -180,7 +180,7 @@ static BOOL check_iso_props(const char* psz_dirname, int64_t file_length, const // Check for archiso loader/entries/*.conf files if (safe_stricmp(psz_dirname, "/loader/entries") == 0) { - len = strlen(psz_basename); + len = safe_strlen(psz_basename); props->is_conf = ((len > 4) && (stricmp(&psz_basename[len - 5], ".conf") == 0)); } @@ -863,7 +863,7 @@ BOOL ExtractISO(const char* src_iso, const char* dest_dir, BOOL scan) size_t i, j, size, sl_index = 0; uint16_t sl_version; FILE* fd; - int r = 1; + int k, r = 1; iso9660_t* p_iso = NULL; iso9660_pvd_t pvd; udf_t* p_udf = NULL; @@ -969,8 +969,8 @@ out: if ((iso9660_ifs_read_pvd(p_iso, &pvd)) && (_stat64U(src_iso, &stat) == 0)) img_report.mismatch_size = (int64_t)(iso9660_get_pvd_space_size(&pvd)) * ISO_BLOCKSIZE - stat.st_size; // Remove trailing spaces from the label - for (j=safe_strlen(img_report.label)-1; ((j>0)&&(isspaceU(img_report.label[j]))); j--) - img_report.label[j] = 0; + for (k=(int)safe_strlen(img_report.label)-1; ((k>0)&&(isspaceU(img_report.label[k]))); k--) + img_report.label[k] = 0; // We use the fact that UDF_BLOCKSIZE and ISO_BLOCKSIZE are the same here img_report.projected_size = total_blocks * ISO_BLOCKSIZE; // We will link the existing isolinux.cfg from a syslinux.cfg we create diff --git a/src/libcdio/iso9660/iso9660_fs.c b/src/libcdio/iso9660/iso9660_fs.c index c6b8ae48..079b3b03 100644 --- a/src/libcdio/iso9660/iso9660_fs.c +++ b/src/libcdio/iso9660/iso9660_fs.c @@ -937,7 +937,7 @@ _iso9660_dir_to_statbuf (iso9660_dir_t *p_iso9660_dir, if (su_length % 2) su_length--; - if (su_length < 0 || su_length < sizeof (iso9660_xa_t)) + if (su_length < sizeof (iso9660_xa_t)) return p_stat; if (nope == b_xa) { diff --git a/src/missing.h b/src/missing.h index 729ec66c..0689b827 100644 --- a/src/missing.h +++ b/src/missing.h @@ -89,12 +89,12 @@ static __inline uint8_t popcnt8(uint8_t val) static __inline uint8_t popcnt64(register uint64_t u) { - u = (u & 0x5555555555555555) + ((u >> 1) & 0x5555555555555555); - u = (u & 0x3333333333333333) + ((u >> 2) & 0x3333333333333333); - u = (u & 0x0f0f0f0f0f0f0f0f) + ((u >> 4) & 0x0f0f0f0f0f0f0f0f); - u = (u & 0x00ff00ff00ff00ff) + ((u >> 8) & 0x00ff00ff00ff00ff); - u = (u & 0x0000ffff0000ffff) + ((u >> 16) & 0x0000ffff0000ffff); - u = (u & 0x00000000ffffffff) + ((u >> 32) & 0x00000000ffffffff); + u = (u & 0x5555555555555555ULL) + ((u >> 1) & 0x5555555555555555ULL); + u = (u & 0x3333333333333333ULL) + ((u >> 2) & 0x3333333333333333ULL); + u = (u & 0x0f0f0f0f0f0f0f0fULL) + ((u >> 4) & 0x0f0f0f0f0f0f0f0fULL); + u = (u & 0x00ff00ff00ff00ffULL) + ((u >> 8) & 0x00ff00ff00ff00ffULL); + u = (u & 0x0000ffff0000ffffULL) + ((u >> 16) & 0x0000ffff0000ffffULL); + u = (u & 0x00000000ffffffffULL) + ((u >> 32) & 0x00000000ffffffffULL); return (uint8_t)u; } diff --git a/src/msapi_utf8.h b/src/msapi_utf8.h index 521f9d80..779a7d49 100644 --- a/src/msapi_utf8.h +++ b/src/msapi_utf8.h @@ -821,7 +821,7 @@ static __inline int SHDeleteDirectoryExU(HWND hwnd, const char* pszPath, FILEOP_ int ret; // String needs to be double NULL terminated, so we just use the length of the UTF-8 string // which is always expected to be larger than our UTF-16 one, and add 2 chars for good measure. - size_t wpszPath_len = strlen(pszPath) + 2; + size_t wpszPath_len = (pszPath == NULL) ? 0 : strlen(pszPath) + 2; // coverity[returned_null] walloc(pszPath, wpszPath_len); SHFILEOPSTRUCTW shfo = { hwnd, FO_DELETE, wpszPath, NULL, fFlags, FALSE, NULL, NULL }; diff --git a/src/parser.c b/src/parser.c index 878ca324..0a326624 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,7 +1,7 @@ /* * Rufus: The Reliable USB Formatting Utility * Elementary Unicode compliant find/replace parser - * Copyright © 2012-2020 Pete Batard + * Copyright © 2012-2021 Pete Batard * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -796,13 +796,20 @@ char* set_token_data_file(const char* token, const char* data, const char* filen } out: - if (fd_in != NULL) fclose(fd_in); - if (fd_out != NULL) fclose(fd_out); + if (fd_in != NULL) { + fclose(fd_in); + fd_in = NULL; + } + if (fd_out != NULL) { + fclose(fd_out); + fd_out = NULL; + } // If an insertion occurred, delete existing file and use the new one if (ret != NULL) { // We're in Windows text mode => Remove CRs if requested - fd_in = _wfopen(wtmpname, L"rb"); + if (wtmpname != NULL) + fd_in = _wfopen(wtmpname, L"rb"); fd_out = _wfopen(wfilename, L"wb"); // Don't check fds if ((fd_in != NULL) && (fd_out != NULL)) { @@ -1052,7 +1059,7 @@ out: if (fd_out != NULL) fclose(fd_out); // If an insertion occurred, delete existing file and use the new one - if (ret != NULL) { + if (ret != NULL && wtmpname != NULL && wfilename != NULL) { // We're in Windows text mode => Remove CRs if requested fd_in = _wfopen(wtmpname, L"rb"); fd_out = _wfopen(wfilename, L"wb"); @@ -1229,7 +1236,7 @@ out: if (fd_out != NULL) fclose(fd_out); // If a replacement occurred, delete existing file and use the new one - if (ret != NULL) { + if (ret != NULL && wtmpname != NULL && wfilename != NULL) { // We're in Windows text mode => Remove CRs if requested fd_in = _wfopen(wtmpname, L"rb"); fd_out = _wfopen(wfilename, L"wb"); diff --git a/src/process.c b/src/process.c index 83ce771e..b5e91abc 100644 --- a/src/process.c +++ b/src/process.c @@ -4,7 +4,7 @@ * * Modified from Process Hacker: * https://github.com/processhacker2/processhacker2/ - * Copyright © 2017-2020 Pete Batard + * Copyright © 2017-2021 Pete Batard * Copyright © 2017 dmex * Copyright © 2009-2016 wj32 * @@ -506,6 +506,9 @@ static DWORD WINAPI SearchProcessThread(LPVOID param) if (i >= handles->NumberOfHandles) break; + if (handleInfo == NULL) + continue; + // Don't bother with processes we can't access if (handleInfo->UniqueProcessId == last_access_denied_pid) continue; @@ -609,7 +612,7 @@ static DWORD WINAPI SearchProcessThread(LPVOID param) // The above may not work on Windows 7, so try QueryFullProcessImageName (Vista or later) if (!bGotCmdLine) { - bGotCmdLine = QueryFullProcessImageNameW(processHandle, 0, wexe_path, &size); + bGotCmdLine = (QueryFullProcessImageNameW(processHandle, 0, wexe_path, &size) != FALSE); if (bGotCmdLine) wchar_to_utf8_no_alloc(wexe_path, cmdline, sizeof(cmdline)); } diff --git a/src/rufus.c b/src/rufus.c index e3aac859..2b02cc05 100755 --- a/src/rufus.c +++ b/src/rufus.c @@ -751,9 +751,6 @@ static void EnableMBRBootOptions(BOOL enable, BOOL remove_checkboxes) actual_enable_mbr = FALSE; mbr_selected_by_user = FALSE; } - if (boot_type == BT_NON_BOOTABLE) { - actual_enable_fix = FALSE; - } } if (remove_checkboxes) { @@ -1135,6 +1132,7 @@ static void DisplayISOProps(void) PRINT_ISO_PROP(HAS_WINPE(img_report), " Uses: WinPE %s", (img_report.uses_minint) ? "(with /minint)" : ""); if (HAS_WININST(img_report)) { inst_str[4] = '0' + img_report.wininst_index; + assert(strlen(img_report.wininst_path[0]) >= 3); uprintf(" Uses: Install.%s%s (version %d.%d.%d%s)", &img_report.wininst_path[0][strlen(img_report.wininst_path[0]) - 3], (img_report.wininst_index > 1) ? inst_str : "", (img_report.wininst_version >> 24) & 0xff, (img_report.wininst_version >> 16) & 0xff, (img_report.wininst_version >> 8) & 0xff, @@ -2218,6 +2216,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA static SHChangeNotifyEntry NotifyEntry; static DWORD_PTR thread_affinity[CHECKSUM_MAX + 1]; static HFONT hyperlink_font = NULL; + static wchar_t wtooltip[128]; LONG lPos; BOOL set_selected_fs; DRAWITEMSTRUCT* pDI; @@ -2234,7 +2233,6 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA char tmp[MAX_PATH], *log_buffer = NULL; wchar_t* wbuffer = NULL; loc_cmd* lcmd = NULL; - wchar_t wtooltip[128]; switch (message) { diff --git a/src/rufus.h b/src/rufus.h index 50dc0d48..d50c7615 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -132,7 +132,7 @@ #ifndef STRINGIFY #define STRINGIFY(x) #x #endif -#define PERCENTAGE(percent, value) ((1ULL * percent * value) / 100ULL) +#define PERCENTAGE(percent, value) ((1ULL * (percent) * (value)) / 100ULL) #define IsChecked(CheckBox_ID) (IsDlgButtonChecked(hMainDialog, CheckBox_ID) == BST_CHECKED) #define MB_IS_RTL (right_to_left_mode?MB_RTLREADING|MB_RIGHT:0) #define CHECK_FOR_USER_CANCEL if (IS_ERROR(FormatStatus) && (SCODE_CODE(FormatStatus) == ERROR_CANCELLED)) goto out @@ -149,7 +149,7 @@ ((char*)(dst))[safe_min(count, dst_max)-1] = 0;} while(0) #define safe_strcpy(dst, dst_max, src) safe_strcp(dst, dst_max, src, safe_strlen(src)+1) #define static_strcpy(dst, src) safe_strcpy(dst, sizeof(dst), src) -#define safe_strncat(dst, dst_max, src, count) strncat(dst, src, safe_min(count, dst_max - safe_strlen(dst) - 1)) +#define safe_strncat(dst, dst_max, src, count) strncat(dst, src, safe_min(count, (dst_max) - safe_strlen(dst) - 1)) #define safe_strcat(dst, dst_max, src) safe_strncat(dst, dst_max, src, safe_strlen(src)+1) #define static_strcat(dst, src) safe_strcat(dst, sizeof(dst), src) #define safe_strcmp(str1, str2) strcmp(((str1==NULL)?"":str1), ((str2==NULL)?"":str2)) @@ -178,7 +178,7 @@ extern void _uprintfs(const char *str); #define vvuprintf(...) do { if (verbose > 1) _uprintf(__VA_ARGS__); } while(0) #define suprintf(...) do { if (!bSilent) _uprintf(__VA_ARGS__); } while(0) #define uuprintf(...) do { if (usb_debug) _uprintf(__VA_ARGS__); } while(0) -#define ubprintf(...) do { safe_sprintf(&ubuffer[ubuffer_pos], UBUFFER_SIZE - ubuffer_pos - 2, __VA_ARGS__); \ +#define ubprintf(...) do { safe_sprintf(&ubuffer[ubuffer_pos], UBUFFER_SIZE - ubuffer_pos - 4, __VA_ARGS__); \ ubuffer_pos = strlen(ubuffer); ubuffer[ubuffer_pos++] = '\r'; ubuffer[ubuffer_pos++] = '\n'; \ ubuffer[ubuffer_pos] = 0; } while(0) #define ubflush() do { if (ubuffer_pos) uprintf("%s", ubuffer); ubuffer_pos = 0; } while(0) @@ -389,7 +389,7 @@ typedef struct { BOOLEAN has_kolibrios; BOOLEAN uses_casper; BOOLEAN uses_minint; - BOOLEAN compression_type; + uint8_t compression_type; winver_t win_version; // Windows ISO version uint16_t sl_version; // Syslinux/Isolinux version char sl_version_str[12]; diff --git a/src/rufus.rc b/src/rufus.rc index bb970462..5a50cc5a 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 232, 326 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_ACCEPTFILES -CAPTION "Rufus 3.18.1854" +CAPTION "Rufus 3.18.1856" FONT 9, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP @@ -395,8 +395,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 3,18,1854,0 - PRODUCTVERSION 3,18,1854,0 + FILEVERSION 3,18,1856,0 + PRODUCTVERSION 3,18,1856,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -414,13 +414,13 @@ BEGIN VALUE "Comments", "https://rufus.ie" VALUE "CompanyName", "Akeo Consulting" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "3.18.1854" + VALUE "FileVersion", "3.18.1856" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2021 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" VALUE "OriginalFilename", "rufus-3.18.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "3.18.1854" + VALUE "ProductVersion", "3.18.1856" END END BLOCK "VarFileInfo" diff --git a/src/stdio.c b/src/stdio.c index 50b80c18..a9df73a4 100644 --- a/src/stdio.c +++ b/src/stdio.c @@ -662,7 +662,7 @@ const char *WindowsErrorString(void) size = FormatMessageU(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, HRESULT_CODE(error_code), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), - &err_string[presize], sizeof(err_string)-(DWORD)strlen(err_string), NULL); + &err_string[presize], (DWORD)(sizeof(err_string)-strlen(err_string)), NULL); if (size == 0) { format_error = GetLastError(); if ((format_error) && (format_error != ERROR_MR_MID_NOT_FOUND) && (format_error != ERROR_MUI_FILE_NOT_LOADED)) diff --git a/src/stdlg.c b/src/stdlg.c index 088176d9..33046aec 100644 --- a/src/stdlg.c +++ b/src/stdlg.c @@ -155,9 +155,12 @@ void BrowseForFolder(void) { dialog_showing++; hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC, &IID_IFileOpenDialog, (LPVOID)&pfod); - if (FAILED(hr)) { + if (FAILED(hr) || pfod == NULL) { uprintf("CoCreateInstance for FileOpenDialog failed: error %X\n", hr); - pfod = NULL; // Just in case + if (pfod != NULL) { + IFileOpenDialog_Release(pfod); + pfod = NULL; // Just in case + } goto fallback; } hr = IFileOpenDialog_SetOptions(pfod, FOS_PICKFOLDERS); @@ -180,7 +183,7 @@ void BrowseForFolder(void) { } hr = SHCreateItemFromParsingName(wpath, NULL, &IID_IShellItem, (LPVOID)&si_path); - if (SUCCEEDED(hr)) { + if (SUCCEEDED(hr) && pfod != NULL) { if (wpath != NULL) { IFileOpenDialog_SetFolder(pfod, si_path); } @@ -191,7 +194,7 @@ void BrowseForFolder(void) { safe_free(wpath); hr = IFileOpenDialog_Show(pfod, hMainDialog); - if (SUCCEEDED(hr)) { + if (SUCCEEDED(hr) && pfod != NULL) { hr = IFileOpenDialog_GetResult(pfod, &psi); if (SUCCEEDED(hr)) { IShellItem_GetDisplayName(psi, SIGDN_FILESYSPATH, &wpath); @@ -277,7 +280,10 @@ char* FileDialog(BOOL save, char* path, const ext_t* ext, DWORD options) if (FAILED(hr)) { SetLastError(hr); uprintf("CoCreateInstance for FileOpenDialog failed: %s\n", WindowsErrorString()); - pfd = NULL; // Just in case + if (pfd != NULL) { + IFileDialog_Release(pfd); + pfd = NULL; // Just in case + } goto fallback; } @@ -789,8 +795,8 @@ INT_PTR CALLBACK NotificationCallback(HWND hDlg, UINT message, WPARAM wParam, LP EndDialog(hDlg, LOWORD(wParam)); return (INT_PTR)TRUE; case IDC_MORE_INFO: - assert(notification_more_info->callback != NULL); if (notification_more_info != NULL) { + assert(notification_more_info->callback != NULL); if (notification_more_info->id == MORE_INFO_URL) { ShellExecuteA(hDlg, "open", notification_more_info->url, NULL, NULL, SW_SHOWNORMAL); } else { @@ -1613,7 +1619,7 @@ BOOL SetUpdateCheck(void) } // If the user hasn't set the interval in the dialog, set to default if ( (ReadSetting32(SETTING_UPDATE_INTERVAL) == 0) || - ((ReadSetting32(SETTING_UPDATE_INTERVAL) == -1) && enable_updates) ) + (ReadSetting32(SETTING_UPDATE_INTERVAL) == -1) ) WriteSetting32(SETTING_UPDATE_INTERVAL, 86400); } SetFidoCheck(); @@ -2005,7 +2011,7 @@ static BOOL CALLBACK AlertPromptCallback(HWND hWnd, LPARAM lParam) if (GetWindowTextU(hWnd, str, sizeof(str)) == 0) return TRUE; - if (safe_strcmp(str, button_str) == 0) + if (strcmp(str, button_str) == 0) *found = TRUE; return TRUE; } diff --git a/src/syslinux.c b/src/syslinux.c index ba6583cb..6c154590 100644 --- a/src/syslinux.c +++ b/src/syslinux.c @@ -194,7 +194,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system) } /* Create ldlinux.sys file */ - static_sprintf(path, "%C:\\%s.%s", drive_letter, ldlinux, ldlinux_ext[0]); + static_sprintf(path, "%c:\\%s.%s", drive_letter, ldlinux, ldlinux_ext[0]); f_handle = CreateFileA(path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, @@ -236,7 +236,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system) switch (file_system) { case FS_NTFS: - static_sprintf(tmp, "%C:\\", drive_letter); + static_sprintf(tmp, "%c:\\", drive_letter); vol_info.Handle = d_handle; err = NtfsSectGetVolumeInfo(tmp, &vol_info); if (err != ERROR_SUCCESS) { @@ -333,7 +333,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system) IGNORE_RETVAL(_chdirU(app_data_dir)); static_sprintf(path, "%s\\%s-%s", FILES_DIR, syslinux, embedded_sl_version_str[1]); IGNORE_RETVAL(_chdir(path)); - static_sprintf(path, "%C:\\%s.%s", drive_letter, ldlinux, ldlinux_ext[2]); + static_sprintf(path, "%c:\\%s.%s", drive_letter, ldlinux, ldlinux_ext[2]); fd = fopen(&path[3], "rb"); if (fd == NULL) { uprintf("Caution: No '%s' was provided. The target will be missing a required Syslinux file!", &path[3]); @@ -354,7 +354,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system) goto out; } /* Create mboot.c32 file */ - static_sprintf(path, "%C:\\%s", drive_letter, mboot_c32); + static_sprintf(path, "%c:\\%s", drive_letter, mboot_c32); f_handle = CreateFileA(path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); @@ -368,7 +368,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system) goto out; } safe_closehandle(f_handle); - static_sprintf(path, "%C:\\syslinux.cfg", drive_letter); + static_sprintf(path, "%c:\\syslinux.cfg", drive_letter); fd = fopen(path, "w"); if (fd == NULL) { uprintf("Could not create ReactOS 'syslinux.cfg'"); diff --git a/src/ui.c b/src/ui.c index 8db33a80..806d48cd 100644 --- a/src/ui.c +++ b/src/ui.c @@ -575,8 +575,9 @@ void SetSectionHeaders(HWND hDlg) SendDlgItemMessageA(hDlg, section_control_ids[i], WM_SETFONT, (WPARAM)hf, TRUE); hCtrl = GetDlgItem(hDlg, section_control_ids[i]); memset(wtmp, 0, sizeof(wtmp)); - GetWindowTextW(hCtrl, wtmp, ARRAYSIZE(wtmp) - 3); + GetWindowTextW(hCtrl, wtmp, ARRAYSIZE(wtmp) - 4); wlen = wcslen(wtmp); + assert(wlen < ARRAYSIZE(wtmp - 2)); wtmp[wlen++] = L' '; wtmp[wlen++] = L' '; SetWindowTextW(hCtrl, wtmp); @@ -788,8 +789,7 @@ void ToggleImageOptions(void) if (image_option_txt[0] == 0) GetWindowTextU(GetDlgItem(hMainDialog, IDS_IMAGE_OPTION_TXT), image_option_txt, sizeof(image_option_txt)); - if ( ((has_wintogo) && !(image_options & IMOP_WINTOGO)) || - ((!has_wintogo) && (image_options & IMOP_WINTOGO)) ) { + if ((has_wintogo) != (image_options & IMOP_WINTOGO)) { image_options ^= IMOP_WINTOGO; if (image_options & IMOP_WINTOGO) { // Set the Windows To Go selection in the dropdown @@ -797,8 +797,7 @@ void ToggleImageOptions(void) } } - if (((has_persistence) && !(image_options & IMOP_PERSISTENCE)) || - ((!has_persistence) && (image_options & IMOP_PERSISTENCE))) { + if ((has_persistence) != (image_options & IMOP_PERSISTENCE)) { image_options ^= IMOP_PERSISTENCE; if (image_options & IMOP_PERSISTENCE) { SetWindowTextU(GetDlgItem(hMainDialog, IDS_IMAGE_OPTION_TXT), lmprintf(MSG_123)); @@ -1069,7 +1068,7 @@ void CreateAdditionalControls(HWND hDlg) hAdvancedDeviceToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, TOOLBAR_STYLE, 0, 0, 0, 0, hMainDialog, (HMENU)IDC_ADVANCED_DEVICE_TOOLBAR, hMainInstance, NULL); SendMessage(hAdvancedDeviceToolbar, CCM_SETVERSION, (WPARAM)6, 0); - memset(tbToolbarButtons, 0, sizeof(TBBUTTON)); + memset(tbToolbarButtons, 0, sizeof(tbToolbarButtons)); tbToolbarButtons[0].idCommand = IDC_ADVANCED_DRIVE_PROPERTIES; tbToolbarButtons[0].fsStyle = BTNS_SHOWTEXT | BTNS_AUTOSIZE; tbToolbarButtons[0].fsState = TBSTATE_ENABLED; @@ -1091,7 +1090,7 @@ void CreateAdditionalControls(HWND hDlg) hAdvancedFormatToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, TOOLBAR_STYLE, 0, 0, 0, 0, hMainDialog, (HMENU)IDC_ADVANCED_FORMAT_TOOLBAR, hMainInstance, NULL); SendMessage(hAdvancedFormatToolbar, CCM_SETVERSION, (WPARAM)6, 0); - memset(tbToolbarButtons, 0, sizeof(TBBUTTON)); + memset(tbToolbarButtons, 0, sizeof(tbToolbarButtons)); tbToolbarButtons[0].idCommand = IDC_ADVANCED_FORMAT_OPTIONS; tbToolbarButtons[0].fsStyle = BTNS_SHOWTEXT | BTNS_AUTOSIZE; tbToolbarButtons[0].fsState = TBSTATE_ENABLED;