summaryrefslogtreecommitdiffstats
path: root/g10
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2016-10-21 05:04:46 +0200
committerNIIBE Yutaka <gniibe@fsij.org>2016-10-21 05:04:46 +0200
commit6e85ac77af594035137950d801d8a1bacce548a3 (patch)
tree9886172b88af046b48da1a4be262adc70ded234e /g10
parentagent: Fix saving with FORCE=1. (diff)
downloadgnupg2-6e85ac77af594035137950d801d8a1bacce548a3.tar.xz
gnupg2-6e85ac77af594035137950d801d8a1bacce548a3.zip
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 <gniibe@fsij.org>
Diffstat (limited to 'g10')
-rw-r--r--g10/call-agent.c65
-rw-r--r--g10/cpr.c6
-rw-r--r--g10/keygen.c1
-rw-r--r--g10/openfile.c4
-rw-r--r--g10/passphrase.c4
5 files changed, 32 insertions, 48 deletions
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]),