From 0d223fa9b0a7cc57a106eccdecd46420ccf3302c Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 22 May 2023 17:00:54 +0200 Subject: [PATCH] sm: Emit STATUS_FAILURE for non-implemented commands. * sm/gpgsm.c (main): Do it here. --- sm/gpgsm.c | 16 ++++++++++++---- sm/server.c | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/sm/gpgsm.c b/sm/gpgsm.c index 51cf42ad9..ffa5a55a7 100644 --- a/sm/gpgsm.c +++ b/sm/gpgsm.c @@ -1837,11 +1837,17 @@ main ( int argc, char **argv) break; case aSignEncr: /* sign and encrypt the given file */ - log_error ("this command has not yet been implemented\n"); + log_error ("the command '%s' has not yet been implemented\n", + "--sign --encrypt"); + gpgsm_status_with_error (&ctrl, STATUS_FAILURE, "option-parser", + gpg_error (GPG_ERR_NOT_IMPLEMENTED)); break; case aClearsign: /* make a clearsig */ - log_error ("this command has not yet been implemented\n"); + log_error ("the command '%s' has not yet been implemented\n", + "--clearsign"); + gpgsm_status_with_error (&ctrl, STATUS_FAILURE, "option-parser", + gpg_error (GPG_ERR_NOT_IMPLEMENTED)); break; case aVerify: @@ -2068,8 +2074,10 @@ main ( int argc, char **argv) default: - log_error (_("invalid command (there is no implicit command)\n")); - break; + log_error (_("invalid command (there is no implicit command)\n")); + gpgsm_status_with_error (&ctrl, STATUS_FAILURE, "option-parser", + gpg_error (GPG_ERR_MISSING_ACTION)); + break; } /* Print the audit result if needed. */ diff --git a/sm/server.c b/sm/server.c index 5341d315a..a0cd652e0 100644 --- a/sm/server.c +++ b/sm/server.c @@ -1474,7 +1474,7 @@ gpgsm_status_with_err_code (ctrl_t ctrl, int no, const char *text, { char buf[30]; - sprintf (buf, "%u", (unsigned int)ec); + snprintf (buf, sizeof buf, "%u", (unsigned int)ec); if (text) return gpgsm_status2 (ctrl, no, text, buf, NULL); else