mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-27 20:36:29 -04:00
Bump dependencies (rcw hardening)
This commit is contained in:
+2
-2
@@ -43,7 +43,7 @@ func CopyShortcut(realPath string, field int, rcwPassword []byte) error {
|
||||
select {} // block indefinitely
|
||||
} else { // other
|
||||
// copy field to clipboard; launch clipboard clearing process
|
||||
if err = CopyString(true, decSlice[field]); err != nil {
|
||||
if err = CopyBytes(true, []byte(decSlice[field])); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -56,7 +56,7 @@ func CopyShortcut(realPath string, field int, rcwPassword []byte) error {
|
||||
// ClearArgument reads the assigned clipboard contents from stdin and passes them to clipClearProcess.
|
||||
func ClearArgument() error {
|
||||
assignedContents := back.ReadFromStdin()
|
||||
if assignedContents == "" {
|
||||
if assignedContents == nil {
|
||||
os.Exit(0) // use os.Exit directly since this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment)
|
||||
}
|
||||
return ClearProcess(assignedContents)
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
package clip
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rwinkhart/go-boilerplate/back"
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
// ClearProcess clears the clipboard after 30 seconds if the clipboard contents have not changed.
|
||||
// assignedContents can be omitted to clear the clipboard immediately and unconditionally.
|
||||
func ClearProcess(assignedContents string) error {
|
||||
func ClearProcess(assignedContents []byte) error {
|
||||
cmdPaste, cmdClear, err := getClipCommands()
|
||||
if err != nil {
|
||||
return errors.New("unable to determine clipboard platform: " + err.Error())
|
||||
@@ -27,7 +27,7 @@ func ClearProcess(assignedContents string) error {
|
||||
}
|
||||
|
||||
// if assignedContents is empty, clear the clipboard immediately and unconditionally
|
||||
if assignedContents == "" {
|
||||
if assignedContents == nil {
|
||||
if err := clearClipboard(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -41,8 +41,7 @@ func ClearProcess(assignedContents string) error {
|
||||
if err != nil {
|
||||
return errors.New("unable to read clipboard contents")
|
||||
}
|
||||
|
||||
if assignedContents == strings.TrimRight(string(newContents), "\r\n") {
|
||||
if bytes.Equal(assignedContents, newContents) {
|
||||
if err = clearClipboard(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+3
-3
@@ -10,8 +10,8 @@ import (
|
||||
"github.com/rwinkhart/go-boilerplate/back"
|
||||
)
|
||||
|
||||
// CopyString copies a string to the clipboard.
|
||||
func CopyString(clearClipboardAutomatically bool, copySubject string) error {
|
||||
// CopyBytes copies a byte slice to the clipboard.
|
||||
func CopyBytes(clearClipboardAutomatically bool, copySubject []byte) error {
|
||||
// determine whether to use wl-copy (Wayland) or xclip (X11)
|
||||
sessionIsWayland, err := isWayland()
|
||||
if err != nil {
|
||||
@@ -24,7 +24,7 @@ func CopyString(clearClipboardAutomatically bool, copySubject string) error {
|
||||
cmdCopy = exec.Command("xclip", "-sel", "c", "-t", "text/plain")
|
||||
}
|
||||
|
||||
_ = back.WriteToStdin(cmdCopy, copySubject)
|
||||
_ = back.WriteToStdinAndZeroizeInput(cmdCopy, copySubject)
|
||||
if err = cmdCopy.Run(); err != nil {
|
||||
return errors.New("unable to copy to clipboard: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ import (
|
||||
|
||||
// LaunchClearProcess launches the timed clipboard clearing process.
|
||||
// For non-interactive CLI implementations, an entirely separate process is created for this purpose.
|
||||
func LaunchClearProcess(copySubject string) {
|
||||
func LaunchClearProcess(copySubject []byte) {
|
||||
cmd := exec.Command(os.Args[0], "clipclear")
|
||||
cmd.SysProcAttr = global.GetSysProcAttr()
|
||||
_ = back.WriteToStdin(cmd, copySubject)
|
||||
_ = back.WriteToStdinAndZeroizeInput(cmd, copySubject)
|
||||
_ = cmd.Start()
|
||||
os.Exit(0) // use os.Exit directly since this version of this function is only meant for non-interactive CLI implementations
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ func TOTPCopier(secret string, errorChan chan<- error, done <-chan bool) {
|
||||
if firstRun && err != nil {
|
||||
errorChan <- err
|
||||
}
|
||||
err = CopyString(false, token)
|
||||
err = CopyBytes(false, []byte(token))
|
||||
if firstRun {
|
||||
if err != nil {
|
||||
errorChan <- err
|
||||
|
||||
Reference in New Issue
Block a user