From 6e85ac77af594035137950d801d8a1bacce548a3 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 21 Oct 2016 12:04:46 +0900 Subject: [PATCH] Fix use cases of snprintf. * agent/call-pinentry.c, agent/call-scd.c, agent/command.c, build-aux/speedo/w32/g4wihelp.c, common/get-passphrase.c, dirmngr/dirmngr.c, g10/call-agent.c, g10/cpr.c, g10/keygen.c, g10/openfile.c, g10/passphrase.c, scd/app-openpgp.c, scd/scdaemon.c, sm/call-agent.c, sm/call-dirmngr.c, sm/certreqgen.c: Fix assuming C99. -- Signed-off-by: NIIBE Yutaka --- agent/call-pinentry.c | 75 ++++++++++++--------------------- agent/call-scd.c | 12 ++---- agent/command.c | 2 +- build-aux/speedo/w32/g4wihelp.c | 8 ++-- common/get-passphrase.c | 6 +-- dirmngr/dirmngr.c | 3 +- g10/call-agent.c | 65 +++++++++++----------------- g10/cpr.c | 6 +-- g10/keygen.c | 1 - g10/openfile.c | 4 +- g10/passphrase.c | 4 +- scd/app-openpgp.c | 2 +- scd/scdaemon.c | 3 +- sm/call-agent.c | 50 ++++++++-------------- sm/call-dirmngr.c | 11 ++--- sm/certreqgen.c | 2 +- 16 files changed, 97 insertions(+), 157 deletions(-) diff --git a/agent/call-pinentry.c b/agent/call-pinentry.c index 0f240866e..46db9e85e 100644 --- a/agent/call-pinentry.c +++ b/agent/call-pinentry.c @@ -734,8 +734,7 @@ setup_qualitybar (ctrl_t ctrl) /* TRANSLATORS: This string is displayed by Pinentry as the label for the quality bar. */ tmpstr = try_percent_escape (L_("Quality:"), "\t\r\n\f\v"); - snprintf (line, DIM(line)-1, "SETQUALITYBAR %s", tmpstr? tmpstr:""); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETQUALITYBAR %s", tmpstr? tmpstr:""); xfree (tmpstr); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc == 103 /*(Old assuan error code)*/ @@ -763,8 +762,7 @@ setup_qualitybar (ctrl_t ctrl) } tmpstr = try_percent_escape (tooltip, "\t\r\n\f\v"); xfree (tmpstr2); - snprintf (line, DIM(line)-1, "SETQUALITYBAR_TT %s", tmpstr? tmpstr:""); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETQUALITYBAR_TT %s", tmpstr? tmpstr:""); xfree (tmpstr); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc == 103 /*(Old assuan error code)*/ @@ -887,27 +885,25 @@ agent_askpin (ctrl_t ctrl, if (keyinfo && (cache_mode == CACHE_MODE_NORMAL || cache_mode == CACHE_MODE_USER || cache_mode == CACHE_MODE_SSH)) - snprintf (line, DIM(line)-1, "SETKEYINFO %c/%s", + snprintf (line, DIM(line), "SETKEYINFO %c/%s", cache_mode == CACHE_MODE_USER? 'u' : cache_mode == CACHE_MODE_SSH? 's' : 'n', keyinfo); else - snprintf (line, DIM(line)-1, "SETKEYINFO --clear"); + snprintf (line, DIM(line), "SETKEYINFO --clear"); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc && gpg_err_code (rc) != GPG_ERR_ASS_UNKNOWN_CMD) return unlock_pinentry (rc); - snprintf (line, DIM(line)-1, "SETDESC %s", desc_text); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETDESC %s", desc_text); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) return unlock_pinentry (rc); - snprintf (line, DIM(line)-1, "SETPROMPT %s", + snprintf (line, DIM(line), "SETPROMPT %s", prompt_text? prompt_text : is_pin? L_("PIN:") : L_("Passphrase:")); - line[DIM(line)-1] = 0; rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) return unlock_pinentry (rc); @@ -924,8 +920,7 @@ agent_askpin (ctrl_t ctrl, if (initial_errtext) { - snprintf (line, DIM(line)-1, "SETERROR %s", initial_errtext); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETERROR %s", initial_errtext); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) @@ -934,9 +929,8 @@ agent_askpin (ctrl_t ctrl, if (pininfo->with_repeat) { - snprintf (line, DIM(line)-1, "SETREPEATERROR %s", + snprintf (line, DIM(line), "SETREPEATERROR %s", L_("does not match - try again")); - line[DIM(line)-1] = 0; rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) @@ -956,9 +950,8 @@ agent_askpin (ctrl_t ctrl, /* TRANSLATORS: The string is appended to an error message in the pinentry. The %s is the actual error message, the two %d give the current and maximum number of tries. */ - snprintf (line, DIM(line)-1, L_("SETERROR %s (try %d of %d)"), + snprintf (line, DIM(line), L_("SETERROR %s (try %d of %d)"), errtext, pininfo->failed_tries+1, pininfo->max_tries); - line[DIM(line)-1] = 0; rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) @@ -968,8 +961,7 @@ agent_askpin (ctrl_t ctrl, if (pininfo->with_repeat) { - snprintf (line, DIM(line)-1, "SETREPEAT %s", L_("Repeat:")); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETREPEAT %s", L_("Repeat:")); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) @@ -1100,12 +1092,12 @@ agent_get_passphrase (ctrl_t ctrl, if (keyinfo && (cache_mode == CACHE_MODE_NORMAL || cache_mode == CACHE_MODE_USER || cache_mode == CACHE_MODE_SSH)) - snprintf (line, DIM(line)-1, "SETKEYINFO %c/%s", + snprintf (line, DIM(line), "SETKEYINFO %c/%s", cache_mode == CACHE_MODE_USER? 'u' : cache_mode == CACHE_MODE_SSH? 's' : 'n', keyinfo); else - snprintf (line, DIM(line)-1, "SETKEYINFO --clear"); + snprintf (line, DIM(line), "SETKEYINFO --clear"); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); @@ -1114,16 +1106,14 @@ agent_get_passphrase (ctrl_t ctrl, if (desc) - snprintf (line, DIM(line)-1, "SETDESC %s", desc); + snprintf (line, DIM(line), "SETDESC %s", desc); else - snprintf (line, DIM(line)-1, "RESET"); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "RESET"); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) return unlock_pinentry (rc); - snprintf (line, DIM(line)-1, "SETPROMPT %s", prompt); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETPROMPT %s", prompt); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) return unlock_pinentry (rc); @@ -1137,8 +1127,7 @@ agent_get_passphrase (ctrl_t ctrl, if (errtext) { - snprintf (line, DIM(line)-1, "SETERROR %s", errtext); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETERROR %s", errtext); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) return unlock_pinentry (rc); @@ -1205,10 +1194,9 @@ agent_get_confirmation (ctrl_t ctrl, return rc; if (desc) - snprintf (line, DIM(line)-1, "SETDESC %s", desc); + snprintf (line, DIM(line), "SETDESC %s", desc); else - snprintf (line, DIM(line)-1, "RESET"); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "RESET"); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); /* Most pinentries out in the wild return the old Assuan error code for canceled which gets translated to an assuan Cancel error and @@ -1221,8 +1209,7 @@ agent_get_confirmation (ctrl_t ctrl, if (ok) { - snprintf (line, DIM(line)-1, "SETOK %s", ok); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETOK %s", ok); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) @@ -1235,8 +1222,7 @@ agent_get_confirmation (ctrl_t ctrl, the standard cancel. */ if (with_cancel) { - snprintf (line, DIM(line)-1, "SETNOTOK %s", notok); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETNOTOK %s", notok); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); } @@ -1245,8 +1231,7 @@ agent_get_confirmation (ctrl_t ctrl, if (gpg_err_code (rc) == GPG_ERR_ASS_UNKNOWN_CMD) { - snprintf (line, DIM(line)-1, "SETCANCEL %s", notok); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETCANCEL %s", notok); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); } @@ -1282,10 +1267,9 @@ agent_show_message (ctrl_t ctrl, const char *desc, const char *ok_btn) return rc; if (desc) - snprintf (line, DIM(line)-1, "SETDESC %s", desc); + snprintf (line, DIM(line), "SETDESC %s", desc); else - snprintf (line, DIM(line)-1, "RESET"); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "RESET"); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); /* Most pinentries out in the wild return the old Assuan error code for canceled which gets translated to an assuan Cancel error and @@ -1298,8 +1282,7 @@ agent_show_message (ctrl_t ctrl, const char *desc, const char *ok_btn) if (ok_btn) { - snprintf (line, DIM(line)-1, "SETOK %s", ok_btn); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETOK %s", ok_btn); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) @@ -1354,18 +1337,16 @@ agent_popup_message_start (ctrl_t ctrl, const char *desc, const char *ok_btn) return rc; if (desc) - snprintf (line, DIM(line)-1, "SETDESC %s", desc); + snprintf (line, DIM(line), "SETDESC %s", desc); else - snprintf (line, DIM(line)-1, "RESET"); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "RESET"); rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) return unlock_pinentry (rc); if (ok_btn) { - snprintf (line, DIM(line)-1, "SETOK %s", ok_btn); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETOK %s", ok_btn); rc = assuan_transact (entry_ctx, line, NULL,NULL,NULL,NULL,NULL,NULL); if (rc) return unlock_pinentry (rc); @@ -1465,7 +1446,7 @@ agent_clear_passphrase (ctrl_t ctrl, if (rc) return rc; - snprintf (line, DIM(line)-1, "CLEARPASSPHRASE %c/%s", + snprintf (line, DIM(line), "CLEARPASSPHRASE %c/%s", cache_mode == CACHE_MODE_USER? 'u' : cache_mode == CACHE_MODE_SSH? 's' : 'n', keyinfo); diff --git a/agent/call-scd.c b/agent/call-scd.c index 934ab4ca0..0f7d57000 100644 --- a/agent/call-scd.c +++ b/agent/call-scd.c @@ -946,8 +946,7 @@ agent_card_pkdecrypt (ctrl_t ctrl, inqparm.getpin_cb_arg = getpin_cb_arg; inqparm.passthru = 0; inqparm.any_inq_seen = 0; - snprintf (line, DIM(line)-1, "PKDECRYPT %s", keyid); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "PKDECRYPT %s", keyid); rc = assuan_transact (ctrl->scd_local->ctx, line, put_membuf_cb, &data, inq_needpin, &inqparm, @@ -986,8 +985,7 @@ agent_card_readcert (ctrl_t ctrl, return rc; init_membuf (&data, 1024); - snprintf (line, DIM(line)-1, "READCERT %s", id); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "READCERT %s", id); rc = assuan_transact (ctrl->scd_local->ctx, line, put_membuf_cb, &data, NULL, NULL, @@ -1022,8 +1020,7 @@ agent_card_readkey (ctrl_t ctrl, const char *id, unsigned char **r_buf) return rc; init_membuf (&data, 1024); - snprintf (line, DIM(line)-1, "READKEY %s", id); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "READKEY %s", id); rc = assuan_transact (ctrl->scd_local->ctx, line, put_membuf_cb, &data, NULL, NULL, @@ -1088,8 +1085,7 @@ agent_card_writekey (ctrl_t ctrl, int force, const char *serialno, if (rc) return rc; - snprintf (line, DIM(line)-1, "WRITEKEY %s%s", force ? "--force " : "", id); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "WRITEKEY %s%s", force ? "--force " : "", id); parms.ctx = ctrl->scd_local->ctx; parms.getpin_cb = getpin_cb; parms.getpin_cb_arg = getpin_cb_arg; diff --git a/agent/command.c b/agent/command.c index 7d8b4c461..1a13084ed 100644 --- a/agent/command.c +++ b/agent/command.c @@ -369,7 +369,7 @@ agent_inq_pinentry_launched (ctrl_t ctrl, unsigned long pid) if (!ctrl || !ctrl->server_local || !ctrl->server_local->allow_pinentry_notify) return 0; - snprintf (line, DIM(line)-1, "PINENTRY_LAUNCHED %lu", pid); + snprintf (line, DIM(line), "PINENTRY_LAUNCHED %lu", pid); return assuan_inquire (ctrl->server_local->assuan_ctx, line, NULL, NULL, 0); } diff --git a/build-aux/speedo/w32/g4wihelp.c b/build-aux/speedo/w32/g4wihelp.c index d2c93e710..fe903aa57 100644 --- a/build-aux/speedo/w32/g4wihelp.c +++ b/build-aux/speedo/w32/g4wihelp.c @@ -70,12 +70,12 @@ dummy (HWND hwndParent, int string_size, char *variables, // do your stuff here { char buf[1024]; - snprintf (buf, sizeof buf - 1, "$R0=%s\r\n$R1=%s\r\n", + snprintf (buf, sizeof buf, "$R0=%s\r\n$R1=%s\r\n", getuservariable(INST_R0), getuservariable(INST_R1)); MessageBox (g_hwndParent,buf,0,MB_OK); - snprintf (buf, sizeof buf - 1, + snprintf (buf, sizeof buf, "autoclose =%d\r\n" "all_user_var =%d\r\n" "exec_error =%d\r\n" @@ -278,7 +278,7 @@ void service_error (const char *str) { char buf[1024]; - snprintf (buf, sizeof (buf) - 1, "error: %s: ec=%d\r\n", str, + snprintf (buf, sizeof (buf), "error: %s: ec=%d\r\n", str, GetLastError ()); MessageBox(g_hwndParent, buf, 0, MB_OK); @@ -575,7 +575,7 @@ service_stop (HWND hwndParent, int string_size, char *variables, if (GetTickCount () - start_time > timeout) { char buf[1024]; - snprintf (buf, sizeof (buf) - 1, + snprintf (buf, sizeof (buf), "time out waiting for service %s to stop\r\n", service_name); MessageBox (g_hwndParent, buf, 0, MB_OK); diff --git a/common/get-passphrase.c b/common/get-passphrase.c index 68361ec14..25c1602dc 100644 --- a/common/get-passphrase.c +++ b/common/get-passphrase.c @@ -181,7 +181,7 @@ gnupg_get_passphrase (const char *cache_id, if (!(arg4 = percent_plus_escape (desc_msg))) goto no_mem; - snprintf (line, DIM(line)-1, + snprintf (line, DIM(line), "GET_PASSPHRASE --data %s--repeat=%d -- %s %s %s %s", check_quality? "--check ":"", repeat, @@ -189,7 +189,6 @@ gnupg_get_passphrase (const char *cache_id, arg2? arg2:"X", arg3? arg3:"X", arg4? arg4:"X"); - line[DIM(line)-1] = 0; xfree (arg2); xfree (arg3); xfree (arg4); @@ -250,8 +249,7 @@ gnupg_clear_passphrase (const char *cache_id) if (err) return err; - snprintf (line, DIM(line)-1, "CLEAR_PASSPHRASE %s", cache_id); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "CLEAR_PASSPHRASE %s", cache_id); return assuan_transact (agent_ctx, line, NULL, NULL, default_inq_cb, NULL, NULL, NULL); } diff --git a/dirmngr/dirmngr.c b/dirmngr/dirmngr.c index 271360e1f..90eb6d43b 100644 --- a/dirmngr/dirmngr.c +++ b/dirmngr/dirmngr.c @@ -2050,9 +2050,8 @@ handle_connections (assuan_fd_t listen_fd) memset (&argval, 0, sizeof argval); argval.afd = fd; - snprintf (threadname, sizeof threadname-1, + snprintf (threadname, sizeof threadname, "conn fd=%d", FD2INT(fd)); - threadname[sizeof threadname -1] = 0; ret = npth_create (&thread, &tattr, start_connection_thread, argval.aptr); diff --git a/g10/call-agent.c b/g10/call-agent.c index 632cabe8b..c1ad8ddf7 100644 --- a/g10/call-agent.c +++ b/g10/call-agent.c @@ -726,7 +726,7 @@ agent_scd_apdu (const char *hexapdu, unsigned int *r_sw) init_membuf (&mb, 256); - snprintf (line, DIM(line)-1, "SCD APDU %s", hexapdu); + snprintf (line, DIM(line), "SCD APDU %s", hexapdu); err = assuan_transact (agent_ctx, line, put_membuf_cb, &mb, NULL, NULL, NULL, NULL); if (!err) @@ -758,9 +758,8 @@ agent_keytocard (const char *hexgrip, int keyno, int force, memset (&parm, 0, sizeof parm); - snprintf (line, DIM(line)-1, "KEYTOCARD %s%s %s OPENPGP.%d %s", + snprintf (line, DIM(line), "KEYTOCARD %s%s %s OPENPGP.%d %s", force?"--force ": "", hexgrip, serialno, keyno, timestamp); - line[DIM(line)-1] = 0; rc = start_agent (NULL, 1); if (rc) @@ -902,8 +901,7 @@ agent_scd_writecert (const char *certidstr, memset (&parms, 0, sizeof parms); - snprintf (line, DIM(line)-1, "SCD WRITECERT %s", certidstr); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SCD WRITECERT %s", certidstr); dfltparm.ctx = agent_ctx; parms.dflt = &dfltparm; parms.certdata = certdata; @@ -956,8 +954,7 @@ agent_scd_writekey (int keyno, const char *serialno, memset (&parms, 0, sizeof parms); - snprintf (line, DIM(line)-1, "SCD WRITEKEY --force OPENPGP.%d", keyno); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SCD WRITEKEY --force OPENPGP.%d", keyno); dfltparm.ctx = agent_ctx; parms.dflt = &dfltparm; parms.keydata = keydata; @@ -1019,11 +1016,10 @@ agent_scd_genkey (int keyno, int force, u32 *createtime) else *tbuf = 0; - snprintf (line, DIM(line)-1, "SCD GENKEY %s%s %s %d", + snprintf (line, DIM(line), "SCD GENKEY %s%s %s %d", *tbuf? "--timestamp=":"", tbuf, force? "--force":"", keyno); - line[DIM(line)-1] = 0; dfltparm.ctx = agent_ctx; rc = assuan_transact (agent_ctx, line, @@ -1151,8 +1147,7 @@ agent_scd_readcert (const char *certidstr, init_membuf (&data, 2048); - snprintf (line, DIM(line)-1, "SCD READCERT %s", certidstr); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SCD READCERT %s", certidstr); rc = assuan_transact (agent_ctx, line, put_membuf_cb, &data, default_inq_cb, &dfltparm, @@ -1202,8 +1197,7 @@ agent_scd_change_pin (int chvno, const char *serialno) return rc; dfltparm.ctx = agent_ctx; - snprintf (line, DIM(line)-1, "SCD PASSWD %s %d", reset, chvno); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SCD PASSWD %s %d", reset, chvno); rc = assuan_transact (agent_ctx, line, NULL, NULL, default_inq_cb, &dfltparm, @@ -1230,8 +1224,7 @@ agent_scd_checkpin (const char *serialno) return rc; dfltparm.ctx = agent_ctx; - snprintf (line, DIM(line)-1, "SCD CHECKPIN %s", serialno); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SCD CHECKPIN %s", serialno); rc = assuan_transact (agent_ctx, line, NULL, NULL, default_inq_cb, &dfltparm, @@ -1301,7 +1294,7 @@ agent_get_passphrase (const char *cache_id, if (!(arg4 = percent_plus_escape (desc_msg))) goto no_mem; - snprintf (line, DIM(line)-1, + snprintf (line, DIM(line), "GET_PASSPHRASE --data --repeat=%d%s -- %s %s %s %s", repeat, check? " --check --qualitybar":"", @@ -1309,7 +1302,6 @@ agent_get_passphrase (const char *cache_id, arg2? arg2:"X", arg3? arg3:"X", arg4? arg4:"X"); - line[DIM(line)-1] = 0; xfree (arg1); xfree (arg2); xfree (arg3); @@ -1358,8 +1350,7 @@ agent_clear_passphrase (const char *cache_id) return rc; dfltparm.ctx = agent_ctx; - snprintf (line, DIM(line)-1, "CLEAR_PASSPHRASE %s", cache_id); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "CLEAR_PASSPHRASE %s", cache_id); return assuan_transact (agent_ctx, line, NULL, NULL, default_inq_cb, &dfltparm, @@ -1387,8 +1378,7 @@ gpg_agent_get_confirmation (const char *desc) tmp = percent_plus_escape (desc); if (!tmp) return gpg_error_from_syserror (); - snprintf (line, DIM(line)-1, "GET_CONFIRMATION %s", tmp); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "GET_CONFIRMATION %s", tmp); xfree (tmp); rc = assuan_transact (agent_ctx, line, @@ -1574,8 +1564,7 @@ agent_get_keyinfo (ctrl_t ctrl, const char *hexkeygrip, if (!hexkeygrip || strlen (hexkeygrip) != 40) return gpg_error (GPG_ERR_INV_VALUE); - snprintf (line, DIM(line)-1, "KEYINFO %s", hexkeygrip); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "KEYINFO %s", hexkeygrip); err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, keyinfo_status_cb, &keyinfo); @@ -1761,7 +1750,7 @@ agent_readkey (ctrl_t ctrl, int fromcard, const char *hexkeygrip, if (err) return err; - snprintf (line, DIM(line)-1, "READKEY %s%s", fromcard? "--card ":"", + snprintf (line, DIM(line), "READKEY %s%s", fromcard? "--card ":"", hexkeygrip); init_membuf (&data, 1024); @@ -1826,16 +1815,14 @@ agent_pksign (ctrl_t ctrl, const char *cache_nonce, if (err) return err; - snprintf (line, DIM(line)-1, "SIGKEY %s", keygrip); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SIGKEY %s", keygrip); err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err) return err; if (desc) { - snprintf (line, DIM(line)-1, "SETKEYDESC %s", desc); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETKEYDESC %s", desc); err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err) @@ -1966,8 +1953,7 @@ agent_pkdecrypt (ctrl_t ctrl, const char *keygrip, const char *desc, if (desc) { - snprintf (line, DIM(line)-1, "SETKEYDESC %s", desc); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETKEYDESC %s", desc); err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err) @@ -2059,7 +2045,7 @@ agent_keywrap_key (ctrl_t ctrl, int forexport, void **r_kek, size_t *r_keklen) return err; dfltparm.ctx = agent_ctx; - snprintf (line, DIM(line)-1, "KEYWRAP_KEY %s", + snprintf (line, DIM(line), "KEYWRAP_KEY %s", forexport? "--export":"--import"); init_membuf_secure (&data, 64); @@ -2121,8 +2107,7 @@ agent_import_key (ctrl_t ctrl, const char *desc, char **cache_nonce_addr, if (desc) { - snprintf (line, DIM(line)-1, "SETKEYDESC %s", desc); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETKEYDESC %s", desc); err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err) @@ -2182,14 +2167,14 @@ agent_export_key (ctrl_t ctrl, const char *hexkeygrip, const char *desc, if (desc) { - snprintf (line, DIM(line)-1, "SETKEYDESC %s", desc); + snprintf (line, DIM(line), "SETKEYDESC %s", desc); err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err) return err; } - snprintf (line, DIM(line)-1, "EXPORT_KEY %s%s%s %s", + snprintf (line, DIM(line), "EXPORT_KEY %s%s%s %s", openpgp_protected ? "--openpgp ":"", cache_nonce_addr && *cache_nonce_addr? "--cache-nonce=":"", cache_nonce_addr && *cache_nonce_addr? *cache_nonce_addr:"", @@ -2241,14 +2226,14 @@ agent_delete_key (ctrl_t ctrl, const char *hexkeygrip, const char *desc, if (desc) { - snprintf (line, DIM(line)-1, "SETKEYDESC %s", desc); + snprintf (line, DIM(line), "SETKEYDESC %s", desc); err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err) return err; } - snprintf (line, DIM(line)-1, "DELETE_KEY%s %s", + snprintf (line, DIM(line), "DELETE_KEY%s %s", force? " --force":"", hexkeygrip); err = assuan_transact (agent_ctx, line, NULL, NULL, default_inq_cb, &dfltparm, @@ -2287,7 +2272,7 @@ agent_passwd (ctrl_t ctrl, const char *hexkeygrip, const char *desc, int verify, if (desc) { - snprintf (line, DIM(line)-1, "SETKEYDESC %s", desc); + snprintf (line, DIM(line), "SETKEYDESC %s", desc); err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err) @@ -2295,12 +2280,12 @@ agent_passwd (ctrl_t ctrl, const char *hexkeygrip, const char *desc, int verify, } if (verify) - snprintf (line, DIM(line)-1, "PASSWD %s%s --verify %s", + snprintf (line, DIM(line), "PASSWD %s%s --verify %s", cache_nonce_addr && *cache_nonce_addr? "--cache-nonce=":"", cache_nonce_addr && *cache_nonce_addr? *cache_nonce_addr:"", hexkeygrip); else - snprintf (line, DIM(line)-1, "PASSWD %s%s %s%s %s", + snprintf (line, DIM(line), "PASSWD %s%s %s%s %s", cache_nonce_addr && *cache_nonce_addr? "--cache-nonce=":"", cache_nonce_addr && *cache_nonce_addr? *cache_nonce_addr:"", passwd_nonce_addr && *passwd_nonce_addr? "--passwd-nonce=":"", diff --git a/g10/cpr.c b/g10/cpr.c index 80af2c060..9961f927f 100644 --- a/g10/cpr.c +++ b/g10/cpr.c @@ -53,9 +53,9 @@ progress_cb (void *ctx, const char *what, int printchar, (void)ctx; if ( printchar == '\n' && !strcmp (what, "primegen") ) - snprintf (buf, sizeof buf -1, "%.20s X 100 100", what ); + snprintf (buf, sizeof buf, "%.20s X 100 100", what ); else - snprintf (buf, sizeof buf -1, "%.20s %c %d %d", + snprintf (buf, sizeof buf, "%.20s %c %d %d", what, printchar=='\n'?'X':printchar, current, total ); write_status_text (STATUS_PROGRESS, buf); } @@ -356,7 +356,7 @@ write_status_begin_signing (gcry_md_hd_t md) ga = map_md_openpgp_to_gcry (i); if (ga && gcry_md_is_enabled (md, ga) && buflen+10 < DIM(buf)) { - snprintf (buf+buflen, DIM(buf) - buflen - 1, + snprintf (buf+buflen, DIM(buf) - buflen, "%sH%d", buflen? " ":"",i); buflen += strlen (buf+buflen); } diff --git a/g10/keygen.c b/g10/keygen.c index 2115b5aed..5ff89f639 100644 --- a/g10/keygen.c +++ b/g10/keygen.c @@ -4877,7 +4877,6 @@ gen_card_key (int algo, int keyno, int is_primary, kbnode_t pub_root, gcry_sexp_t s_key; snprintf (keyid, DIM(keyid), "OPENPGP.%d", keyno); - keyid[DIM(keyid)-1] = 0; if (algo != PUBKEY_ALGO_RSA) return gpg_error (GPG_ERR_PUBKEY_ALGO); diff --git a/g10/openfile.c b/g10/openfile.c index 006ff35cd..ad256048a 100644 --- a/g10/openfile.c +++ b/g10/openfile.c @@ -148,9 +148,9 @@ ask_outfile_name( const char *name, size_t namelen ) n = strlen(s) + (defname?strlen (defname):0) + 10; prompt = xmalloc (n); if (defname) - snprintf (prompt, n-1, "%s [%s]: ", s, defname ); + snprintf (prompt, n, "%s [%s]: ", s, defname ); else - snprintf (prompt, n-1, "%s: ", s ); + snprintf (prompt, n, "%s: ", s ); tty_enable_completion(NULL); fname = cpr_get ("openfile.askoutname", prompt ); cpr_kill_prompt (); diff --git a/g10/passphrase.c b/g10/passphrase.c index be71b6889..d75d980a1 100644 --- a/g10/passphrase.c +++ b/g10/passphrase.c @@ -347,7 +347,7 @@ passphrase_to_dek (int cipher_algo, STRING2KEY *s2k, { char buf[50]; - snprintf (buf, sizeof buf -1, "%d %d %d", + snprintf (buf, sizeof buf, "%d %d %d", cipher_algo, s2k->mode, s2k->hash_algo ); write_status_text ( STATUS_NEED_PASSPHRASE_SYM, buf ); } @@ -447,7 +447,7 @@ emit_status_need_passphrase (u32 *keyid, u32 *mainkeyid, int pubkey_algo) write_status_text (STATUS_USERID_HINT, us); xfree (us); - snprintf (buf, sizeof buf -1, "%08lX%08lX %08lX%08lX %d 0", + snprintf (buf, sizeof buf, "%08lX%08lX %08lX%08lX %d 0", (ulong)keyid[0], (ulong)keyid[1], (ulong)(mainkeyid? mainkeyid[0]:keyid[0]), diff --git a/scd/app-openpgp.c b/scd/app-openpgp.c index 843fdf0fb..093109501 100644 --- a/scd/app-openpgp.c +++ b/scd/app-openpgp.c @@ -1872,7 +1872,7 @@ verify_a_chv (app_t app, prompt_buffer = xtrymalloc (promptsize); if (!prompt_buffer) return gpg_error_from_syserror (); - snprintf (prompt_buffer, promptsize-1, PROMPTSTRING, sigcount); + snprintf (prompt_buffer, promptsize, PROMPTSTRING, sigcount); prompt = prompt_buffer; #undef PROMPTSTRING } diff --git a/scd/scdaemon.c b/scd/scdaemon.c index df1abe8b7..ab2fadbb3 100644 --- a/scd/scdaemon.c +++ b/scd/scdaemon.c @@ -1292,8 +1292,7 @@ handle_connections (int listen_fd) char threadname[50]; npth_t thread; - snprintf (threadname, sizeof threadname-1, "conn fd=%d", fd); - threadname[sizeof threadname -1] = 0; + snprintf (threadname, sizeof threadname, "conn fd=%d", fd); ctrl->thread_startup.fd = INT2FD (fd); ret = npth_create (&thread, &tattr, start_connection_thread, ctrl); if (ret) diff --git a/sm/call-agent.c b/sm/call-agent.c index 326265063..c0a2081fe 100644 --- a/sm/call-agent.c +++ b/sm/call-agent.c @@ -243,16 +243,14 @@ gpgsm_agent_pksign (ctrl_t ctrl, const char *keygrip, const char *desc, if (rc) return rc; - snprintf (line, DIM(line)-1, "SIGKEY %s", keygrip); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SIGKEY %s", keygrip); rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) return rc; if (desc) { - snprintf (line, DIM(line)-1, "SETKEYDESC %s", desc); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETKEYDESC %s", desc); rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) @@ -335,8 +333,7 @@ gpgsm_scd_pksign (ctrl_t ctrl, const char *keyid, const char *desc, init_membuf (&data, 1024); - snprintf (line, DIM(line)-1, "SCD PKSIGN %s %s", hashopt, keyid); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SCD PKSIGN %s %s", hashopt, keyid); rc = assuan_transact (agent_ctx, line, put_membuf_cb, &data, default_inq_cb, &inq_parm, NULL, NULL); @@ -429,16 +426,14 @@ gpgsm_agent_pkdecrypt (ctrl_t ctrl, const char *keygrip, const char *desc, return rc; assert ( DIM(line) >= 50 ); - snprintf (line, DIM(line)-1, "SETKEY %s", keygrip); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETKEY %s", keygrip); rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) return rc; if (desc) { - snprintf (line, DIM(line)-1, "SETKEYDESC %s", desc); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETKEYDESC %s", desc); rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) @@ -594,9 +589,8 @@ gpgsm_agent_readkey (ctrl_t ctrl, int fromcard, const char *hexkeygrip, if (rc) return rc; - snprintf (line, DIM(line)-1, "%sREADKEY %s", + snprintf (line, DIM(line), "%sREADKEY %s", fromcard? "SCD ":"", hexkeygrip); - line[DIM(line)-1] = 0; init_membuf (&data, 1024); rc = assuan_transact (agent_ctx, line, @@ -810,8 +804,7 @@ gpgsm_agent_istrusted (ctrl_t ctrl, ksba_cert_t cert, const char *hexfpr, if (hexfpr) { - snprintf (line, DIM(line)-1, "ISTRUSTED %s", hexfpr); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "ISTRUSTED %s", hexfpr); } else { @@ -824,8 +817,7 @@ gpgsm_agent_istrusted (ctrl_t ctrl, ksba_cert_t cert, const char *hexfpr, return gpg_error (GPG_ERR_GENERAL); } - snprintf (line, DIM(line)-1, "ISTRUSTED %s", fpr); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "ISTRUSTED %s", fpr); xfree (fpr); } @@ -868,8 +860,7 @@ gpgsm_agent_marktrusted (ctrl_t ctrl, ksba_cert_t cert) xfree (dn); if (!dnfmt) return gpg_error_from_syserror (); - snprintf (line, DIM(line)-1, "MARKTRUSTED %s S %s", fpr, dnfmt); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "MARKTRUSTED %s S %s", fpr, dnfmt); ksba_free (dnfmt); xfree (fpr); @@ -895,8 +886,7 @@ gpgsm_agent_havekey (ctrl_t ctrl, const char *hexkeygrip) if (!hexkeygrip || strlen (hexkeygrip) != 40) return gpg_error (GPG_ERR_INV_VALUE); - snprintf (line, DIM(line)-1, "HAVEKEY %s", hexkeygrip); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "HAVEKEY %s", hexkeygrip); rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); return rc; @@ -1045,16 +1035,14 @@ gpgsm_agent_passwd (ctrl_t ctrl, const char *hexkeygrip, const char *desc) if (desc) { - snprintf (line, DIM(line)-1, "SETKEYDESC %s", desc); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "SETKEYDESC %s", desc); rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) return rc; } - snprintf (line, DIM(line)-1, "PASSWD %s", hexkeygrip); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "PASSWD %s", hexkeygrip); rc = assuan_transact (agent_ctx, line, NULL, NULL, default_inq_cb, &inq_parm, NULL, NULL); @@ -1078,8 +1066,7 @@ gpgsm_agent_get_confirmation (ctrl_t ctrl, const char *desc) inq_parm.ctrl = ctrl; inq_parm.ctx = agent_ctx; - snprintf (line, DIM(line)-1, "GET_CONFIRMATION %s", desc); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "GET_CONFIRMATION %s", desc); rc = assuan_transact (agent_ctx, line, NULL, NULL, default_inq_cb, &inq_parm, NULL, NULL); @@ -1150,8 +1137,7 @@ gpgsm_agent_keyinfo (ctrl_t ctrl, const char *hexkeygrip, char **r_serialno) if (!hexkeygrip || strlen (hexkeygrip) != 40) return gpg_error (GPG_ERR_INV_VALUE); - snprintf (line, DIM(line)-1, "KEYINFO %s", hexkeygrip); - line[DIM(line)-1] = 0; + snprintf (line, DIM(line), "KEYINFO %s", hexkeygrip); err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, keyinfo_status_cb, &serialno); @@ -1196,7 +1182,7 @@ gpgsm_agent_ask_passphrase (ctrl_t ctrl, const char *desc_msg, int repeat, if (desc_msg && *desc_msg && !(arg4 = percent_plus_escape (desc_msg))) return gpg_error_from_syserror (); - snprintf (line, DIM(line)-1, "GET_PASSPHRASE --data%s -- X X X %s", + snprintf (line, DIM(line), "GET_PASSPHRASE --data%s -- X X X %s", repeat? " --repeat=1 --check --qualitybar":"", arg4); xfree (arg4); @@ -1241,7 +1227,7 @@ gpgsm_agent_keywrap_key (ctrl_t ctrl, int forexport, inq_parm.ctrl = ctrl; inq_parm.ctx = agent_ctx; - snprintf (line, DIM(line)-1, "KEYWRAP_KEY %s", + snprintf (line, DIM(line), "KEYWRAP_KEY %s", forexport? "--export":"--import"); init_membuf_secure (&data, 64); @@ -1335,14 +1321,14 @@ gpgsm_agent_export_key (ctrl_t ctrl, const char *keygrip, const char *desc, if (desc) { - snprintf (line, DIM(line)-1, "SETKEYDESC %s", desc); + snprintf (line, DIM(line), "SETKEYDESC %s", desc); err = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (err) return err; } - snprintf (line, DIM(line)-1, "EXPORT_KEY %s", keygrip); + snprintf (line, DIM(line), "EXPORT_KEY %s", keygrip); init_membuf_secure (&data, 1024); err = assuan_transact (agent_ctx, line, diff --git a/sm/call-dirmngr.c b/sm/call-dirmngr.c index f561bb08c..03c9a6833 100644 --- a/sm/call-dirmngr.c +++ b/sm/call-dirmngr.c @@ -215,9 +215,8 @@ prepare_dirmngr (ctrl_t ctrl, assuan_context_t ctx, gpg_error_t err) char *pass = server->pass ? server->pass : ""; char *base = server->base ? server->base : ""; - snprintf (line, DIM (line) - 1, "LDAPSERVER %s:%i:%s:%s:%s", + snprintf (line, DIM (line), "LDAPSERVER %s:%i:%s:%s:%s", server->host, server->port, user, pass, base); - line[DIM (line) - 1] = 0; assuan_transact (ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); /* The code below is not required because we don't return an error. */ @@ -548,10 +547,9 @@ gpgsm_dirmngr_isvalid (ctrl_t ctrl, NULL, NULL, NULL, NULL, NULL, NULL); did_options = 1; } - snprintf (line, DIM(line)-1, "ISVALID%s %s", + snprintf (line, DIM(line), "ISVALID%s %s", use_ocsp == 2? " --only-ocsp --force-default-responder":"", certid); - line[DIM(line)-1] = 0; xfree (certid); rc = assuan_transact (dirmngr_ctx, line, NULL, NULL, @@ -803,9 +801,8 @@ gpgsm_dirmngr_lookup (ctrl_t ctrl, strlist_t names, int cache_only, return out_of_core (); } - snprintf (line, DIM(line)-1, "LOOKUP%s %s", + snprintf (line, DIM(line), "LOOKUP%s %s", cache_only? " --cache-only":"", pattern); - line[DIM(line)-1] = 0; xfree (pattern); parm.ctrl = ctrl; @@ -861,7 +858,7 @@ get_cached_cert (assuan_context_t ctx, *r_cert = NULL; bin2hex (fpr, 20, hexfpr); - snprintf (line, DIM(line)-1, "LOOKUP --single --cache-only 0x%s", hexfpr); + snprintf (line, DIM(line), "LOOKUP --single --cache-only 0x%s", hexfpr); init_membuf (&mb, 4096); err = assuan_transact (ctx, line, get_cached_cert_data_cb, &mb, diff --git a/sm/certreqgen.c b/sm/certreqgen.c index 2c6550c25..4d5027005 100644 --- a/sm/certreqgen.c +++ b/sm/certreqgen.c @@ -719,7 +719,7 @@ proc_parameters (ctrl_t ctrl, struct para_data_s *para, else if (!outctrl->dryrun) /* Generate new key. */ { sprintf (numbuf, "%u", nbits); - snprintf ((char*)keyparms, DIM (keyparms)-1, + snprintf ((char*)keyparms, DIM (keyparms), "(6:genkey(3:rsa(5:nbits%d:%s)))", (int)strlen (numbuf), numbuf); rc = gpgsm_agent_genkey (ctrl, keyparms, &public);