diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-04-25 18:23:49 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-04-25 18:23:49 (EDT) |
commit | 1ce4ec34c05a6a58f229dc231664ba66875598bc (patch) | |
tree | d232b635e96182198929771020f1d74444514bf5 /src/fd.sh | |
parent | 32b7c2ab14c83caa7efb3b0a83cc546213435455 (diff) |
fopen(), fclose(): Replace echo, improve eval safety
Diffstat (limited to 'src/fd.sh')
-rw-r--r-- | src/fd.sh | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -57,7 +57,8 @@ fopen() # Find first available file descriptor. i=${_FD_MIN} while [ ${i} -le ${_FD_MAX} ]; do - if [ "x$(eval echo "\${_fd_${i}+set}")" != 'xset' ]; then + if [ "x$(eval "printf '%s' \"\${_fd_${i}+set}\"")" != 'xset' ] + then fd=${i} break fi @@ -68,8 +69,8 @@ fopen() return 1 fi - if eval "exec ${fd}${mode}'${path}'"; then - eval "_fd_${fd}='${mode}${path}'" + if eval "exec ${fd}${mode}\"\${path}\""; then + eval "_fd_${fd}=\"\${mode}\${path}\"" FD="${fd}" return 0 else @@ -84,7 +85,7 @@ fclose() shift 1 # Make sure the file descriptor is open. - if [ "x$(eval echo "\${_fd_${fd}+set}")" != 'xset' ]; then + if [ "x$(eval "printf '%s' \"\${_fd_${fd}+set}\"")" != 'xset' ]; then error "$(get_msg 'ebadf')" return 1 fi |