diff options
author | Noah Lokocz <nlokocz@mozilla.com> | 2023-03-16 11:54:55 +0000 |
---|---|---|
committer | Noah Lokocz <nlokocz@mozilla.com> | 2023-03-16 11:54:55 +0000 |
commit | 8acd95e85e0da102fc48369fd237c634fe6066ae (patch) | |
tree | 8e1a4dd99d6d370965a7a8a1db41dbde878a0997 /cmd/lib | |
parent | f658c5a831dab0cf861a0c939c0684f0ab012695 (diff) | |
download | nss-hg-8acd95e85e0da102fc48369fd237c634fe6066ae.tar.gz |
Bug 1819958. Removed deprecated sprintf function and replaced with snprintf. r=djackson
Differential Revision: https://phabricator.services.mozilla.com/D171859
Diffstat (limited to 'cmd/lib')
-rw-r--r-- | cmd/lib/basicutil.c | 3 | ||||
-rw-r--r-- | cmd/lib/secutil.c | 45 |
2 files changed, 24 insertions, 24 deletions
diff --git a/cmd/lib/basicutil.c b/cmd/lib/basicutil.c index 476475d90..3ccacd735 100644 --- a/cmd/lib/basicutil.c +++ b/cmd/lib/basicutil.c @@ -679,9 +679,8 @@ SECU_SECItemToHex(const SECItem *item, char *dst) unsigned char *src = item->data; unsigned int len = item->len; for (; len > 0; --len, dst += 2) { - sprintf(dst, "%02x", *src++); + snprintf(dst, 3, "%02x", *src++); } - *dst = '\0'; } } diff --git a/cmd/lib/secutil.c b/cmd/lib/secutil.c index d9270ed92..a290b8f7a 100644 --- a/cmd/lib/secutil.c +++ b/cmd/lib/secutil.c @@ -20,6 +20,7 @@ #include "secpkcs7.h" #include "secpkcs5.h" #include <stdarg.h> +#include <stdio.h> #include <sys/stat.h> #include <errno.h> #include <limits.h> @@ -232,13 +233,13 @@ SECU_GetModulePassword(PK11SlotInfo *slot, PRBool retry, void *arg) switch (pwdata->source) { case PW_NONE: - sprintf(prompt, "Enter Password or Pin for \"%s\":", + snprintf(prompt, sizeof(prompt), "Enter Password or Pin for \"%s\":", PK11_GetTokenName(slot)); return SECU_GetPasswordString(NULL, prompt); case PW_FROMFILE: return SECU_FilePasswd(slot, retry, pwdata->data); case PW_EXTERNAL: - sprintf(prompt, + snprintf(prompt, sizeof(prompt), "Press Enter, then enter PIN for \"%s\" on external device.\n", PK11_GetTokenName(slot)); char *pw = SECU_GetPasswordString(NULL, prompt); @@ -436,7 +437,7 @@ SECU_DefaultSSLDir(void) if (strlen(dir) >= PR_ARRAY_SIZE(sslDir)) { return NULL; } - sprintf(sslDir, "%s", dir); + snprintf(sslDir, sizeof(sslDir), "%s", dir); if (sslDir[strlen(sslDir) - 1] == '/') sslDir[strlen(sslDir) - 1] = 0; @@ -450,9 +451,9 @@ SECU_AppendFilenameToDir(char *dir, char *filename) static char path[1000]; if (dir[strlen(dir) - 1] == '/') - sprintf(path, "%s%s", dir, filename); + snprintf(path, sizeof(path), "%s%s", dir, filename); else - sprintf(path, "%s/%s", dir, filename); + snprintf(path, sizeof(path), "%s/%s", dir, filename); return path; } @@ -473,11 +474,11 @@ SECU_ConfigDirectory(const char *base) home = ""; if (*home && home[strlen(home) - 1] == '/') - sprintf(buf, "%.900s%s", home, dir); + snprintf(buf, sizeof(buf), "%.900s%s", home, dir); else - sprintf(buf, "%.900s/%s", home, dir); + snprintf(buf, sizeof(buf), "%.900s/%s", home, dir); } else { - sprintf(buf, "%.900s", base); + snprintf(buf, sizeof(buf), "%.900s", base); if (buf[strlen(buf) - 1] == '/') buf[strlen(buf) - 1] = 0; } @@ -1419,7 +1420,7 @@ secu_PrintAttribute(FILE *out, SEC_PKCS7Attribute *attr, char *m, int level) if (attr->values != NULL) { i = 0; while ((value = attr->values[i++]) != NULL) { - sprintf(om, "Value (%d)%s", i, attr->encoded ? " (encoded)" : ""); + snprintf(om, sizeof(om), "Value (%d)%s", i, attr->encoded ? " (encoded)" : ""); if (attr->encoded || attr->typeTag == NULL) { SECU_PrintAny(out, value, om, level + 1); } else { @@ -2708,7 +2709,7 @@ secu_PrintSignerInfo(FILE *out, SEC_PKCS7SignerInfo *info, fprintf(out, "Authenticated Attributes:\n"); iv = 0; while ((attr = info->authAttr[iv++]) != NULL) { - sprintf(om, "Attribute (%d)", iv); + snprintf(om, sizeof(om), "Attribute (%d)", iv); secu_PrintAttribute(out, attr, om, level + 2); } } @@ -2723,7 +2724,7 @@ secu_PrintSignerInfo(FILE *out, SEC_PKCS7SignerInfo *info, fprintf(out, "Unauthenticated Attributes:\n"); iv = 0; while ((attr = info->unAuthAttr[iv++]) != NULL) { - sprintf(om, "Attribute (%x)", iv); + snprintf(om, sizeof(om), "Attribute (%x)", iv); secu_PrintAttribute(out, attr, om, level + 2); } } @@ -2757,7 +2758,7 @@ SECU_PrintCRLInfo(FILE *out, CERTCrl *crl, char *m, int level) if (crl->entries != NULL) { iv = 0; while ((entry = crl->entries[iv++]) != NULL) { - sprintf(om, "Entry %d (0x%x):\n", iv, iv); + snprintf(om, sizeof(om), "Entry %d (0x%x):\n", iv, iv); SECU_Indent(out, level + 1); fputs(om, out); SECU_PrintInteger(out, &(entry->serialNumber), "Serial Number", @@ -2796,7 +2797,7 @@ secu_PrintPKCS7Signed(FILE *out, SEC_PKCS7SignedData *src, fprintf(out, "Digest Algorithm List:\n"); iv = 0; while ((digAlg = src->digestAlgorithms[iv++]) != NULL) { - sprintf(om, "Digest Algorithm (%x)", iv); + snprintf(om, sizeof(om), "Digest Algorithm (%x)", iv); SECU_PrintAlgorithmID(out, digAlg, om, level + 2); } } @@ -2813,7 +2814,7 @@ secu_PrintPKCS7Signed(FILE *out, SEC_PKCS7SignedData *src, fprintf(out, "Certificate List:\n"); iv = 0; while ((aCert = src->rawCerts[iv++]) != NULL) { - sprintf(om, "Certificate (%x)", iv); + snprintf(om, sizeof(om), "Certificate (%x)", iv); rv = SECU_PrintSignedData(out, aCert, om, level + 2, (SECU_PPFunc)SECU_PrintCertificate); if (rv) @@ -2827,7 +2828,7 @@ secu_PrintPKCS7Signed(FILE *out, SEC_PKCS7SignedData *src, fprintf(out, "Signed Revocation Lists:\n"); iv = 0; while ((aCrl = src->crls[iv++]) != NULL) { - sprintf(om, "Signed Revocation List (%x)", iv); + snprintf(om, sizeof(om), "Signed Revocation List (%x)", iv); SECU_Indent(out, level + 2); fprintf(out, "%s:\n", om); SECU_PrintAlgorithmID(out, &aCrl->signatureWrap.signatureAlgorithm, @@ -2846,7 +2847,7 @@ secu_PrintPKCS7Signed(FILE *out, SEC_PKCS7SignedData *src, fprintf(out, "Signer Information List:\n"); iv = 0; while ((sigInfo = src->signerInfos[iv++]) != NULL) { - sprintf(om, "Signer Information (%x)", iv); + snprintf(om, sizeof(om), "Signer Information (%x)", iv); secu_PrintSignerInfo(out, sigInfo, om, level + 2); } } @@ -2876,7 +2877,7 @@ secu_PrintPKCS7Enveloped(FILE *out, SEC_PKCS7EnvelopedData *src, fprintf(out, "Recipient Information List:\n"); iv = 0; while ((recInfo = src->recipientInfos[iv++]) != NULL) { - sprintf(om, "Recipient Information (%x)", iv); + snprintf(om, sizeof(om), "Recipient Information (%x)", iv); secu_PrintRecipientInfo(out, recInfo, om, level + 2); } } @@ -2913,7 +2914,7 @@ secu_PrintPKCS7SignedAndEnveloped(FILE *out, fprintf(out, "Recipient Information List:\n"); iv = 0; while ((recInfo = src->recipientInfos[iv++]) != NULL) { - sprintf(om, "Recipient Information (%x)", iv); + snprintf(om, sizeof(om), "Recipient Information (%x)", iv); secu_PrintRecipientInfo(out, recInfo, om, level + 2); } } @@ -2924,7 +2925,7 @@ secu_PrintPKCS7SignedAndEnveloped(FILE *out, fprintf(out, "Digest Algorithm List:\n"); iv = 0; while ((digAlg = src->digestAlgorithms[iv++]) != NULL) { - sprintf(om, "Digest Algorithm (%x)", iv); + snprintf(om, sizeof(om), "Digest Algorithm (%x)", iv); SECU_PrintAlgorithmID(out, digAlg, om, level + 2); } } @@ -2940,7 +2941,7 @@ secu_PrintPKCS7SignedAndEnveloped(FILE *out, fprintf(out, "Certificate List:\n"); iv = 0; while ((aCert = src->rawCerts[iv++]) != NULL) { - sprintf(om, "Certificate (%x)", iv); + snprintf(om, sizeof(om), "Certificate (%x)", iv); rv = SECU_PrintSignedData(out, aCert, om, level + 2, (SECU_PPFunc)SECU_PrintCertificate); if (rv) @@ -2954,7 +2955,7 @@ secu_PrintPKCS7SignedAndEnveloped(FILE *out, fprintf(out, "Signed Revocation Lists:\n"); iv = 0; while ((aCrl = src->crls[iv++]) != NULL) { - sprintf(om, "Signed Revocation List (%x)", iv); + snprintf(om, sizeof(om), "Signed Revocation List (%x)", iv); SECU_Indent(out, level + 2); fprintf(out, "%s:\n", om); SECU_PrintAlgorithmID(out, &aCrl->signatureWrap.signatureAlgorithm, @@ -2973,7 +2974,7 @@ secu_PrintPKCS7SignedAndEnveloped(FILE *out, fprintf(out, "Signer Information List:\n"); iv = 0; while ((sigInfo = src->signerInfos[iv++]) != NULL) { - sprintf(om, "Signer Information (%x)", iv); + snprintf(om, sizeof(om), "Signer Information (%x)", iv); secu_PrintSignerInfo(out, sigInfo, om, level + 2); } } |