crypto: fix compiler warnings in gpg
Handle unused return values of calls to dup() and write().
Related to .
@@ -784,25 +784,37 @@ int CRYPTO_PLUGIN_FUNCTION (gpgCall) (KeySet * conf, Key * errorKey, Key * msgKe
if (msgKey)
{
close (STDIN_FILENO);
- dup (pipe_stdin[0]);
+ if (dup (pipe_stdin[0]) < 0)
+ {
+ ELEKTRA_SET_ERROR (ELEKTRA_ERROR_CRYPTO_GPG, errorKey, "failed to redirect stdin.");
+ return -2;
+ }
}
close (pipe_stdin[0]);
// redirect stdout to pipe
close (STDOUT_FILENO);
- dup (pipe_stdout[1]);
+ if (dup (pipe_stdout[1]) < 0)
+ {
+ ELEKTRA_SET_ERROR (ELEKTRA_ERROR_CRYPTO_GPG, errorKey, "failed to redirect the stdout.");
+ return -2;
+ }
close (pipe_stdout[1]);
// redirect stderr to pipe
close (STDERR_FILENO);
- dup (pipe_stderr[1]);
+ if (dup (pipe_stderr[1]) < 0)
+ {
+ ELEKTRA_SET_ERROR (ELEKTRA_ERROR_CRYPTO_GPG, errorKey, "failed to redirect stderr.");
+ return -2;
+ }
close (pipe_stderr[1]);
// finally call the gpg executable
if (execv (argv[0], argv) < 0)
{
ELEKTRA_SET_ERRORF (ELEKTRA_ERROR_CRYPTO_GPG, errorKey, "failed to start the gpg binary: %s", argv[0]);
- return -1;
+ return -2;
}
// end of the child process
}
@@ -813,9 +825,19 @@ int CRYPTO_PLUGIN_FUNCTION (gpgCall) (KeySet * conf, Key * errorKey, Key * msgKe
close (pipe_stderr[1]);
// pass the message to the gpg process
- if (msgKey && keyGetValueSize (msgKey) > 0)
+ const ssize_t sendMessageSize = keyGetValueSize (msgKey);
+ if (msgKey && sendMessageSize > 0)
{
- write (pipe_stdin[1], keyValue (msgKey), keyGetValueSize (msgKey));
+ if (write (pipe_stdin[1], keyValue (msgKey), sendMessageSize) != sendMessageSize)
+ {
+ ELEKTRA_SET_ERROR (ELEKTRA_ERROR_CRYPTO_GPG, errorKey, "The communication with the GPG process failed.");
+ closePipe (pipe_stdin);
+ closePipe (pipe_stdout);
+ closePipe (pipe_stderr);
+ elektraFree (buffer);
+ elektraFree (argv[0]);
+ return -1;
+ }
}
close (pipe_stdin[1]);
@@ -841,6 +863,10 @@ int CRYPTO_PLUGIN_FUNCTION (gpgCall) (KeySet * conf, Key * errorKey, Key * msgKe
ELEKTRA_SET_ERROR (ELEKTRA_ERROR_CRYPTO_GPG, errorKey, "GPG reported a bad signature");
break;
+ case -2:
+ // error has been set to errorKey by the child process
+ break;
+
default:
// other errors
outputLen = read (pipe_stderr[0], errorBuffer, sizeof (errorBuffer));
