Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1 | From 6f7d7be9997ba6727a5ad7c3800df9051160dc12 Mon Sep 17 00:00:00 2001 |
| 2 | From: Martin Thomson <martin.thomson@gmail.com> |
| 3 | Date: Tue, 13 Feb 2018 12:30:58 +1100 |
| 4 | Subject: [PATCH] Bug 1437734 - Use snprintf in sign.c, r=ttaubert |
| 5 | |
| 6 | --HG-- |
| 7 | extra : rebase_source : 97921ece71ff86b18d32b891591608290eed4d83 |
| 8 | --- |
| 9 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 10 | Upstream-Status: Backport [https://github.com/nss-dev/nss/commit/0a9078b3cde97add7c825c9d13467a8401ad0c88#diff-b42512151dc137537091f823f7701804.patch] |
| 11 | |
| 12 | nss/cmd/signtool/sign.c | 58 ++++++++++++++++++++++++++++++++++++++++--------- |
| 13 | 1 file changed, 48 insertions(+), 10 deletions(-) |
| 14 | |
| 15 | diff --git a/nss/cmd/signtool/sign.c b/nss/cmd/signtool/sign.c |
| 16 | index 6e776069a..6f8e43946 100644 |
| 17 | --- a/nss/cmd/signtool/sign.c |
| 18 | +++ b/nss/cmd/signtool/sign.c |
| 19 | @@ -43,6 +43,7 @@ SignArchive(char *tree, char *keyName, char *zip_file, int javascript, |
| 20 | int status; |
| 21 | char tempfn[FNSIZE], fullfn[FNSIZE]; |
| 22 | int keyType = rsaKey; |
| 23 | + int count; |
| 24 | |
| 25 | metafile = meta_file; |
| 26 | optimize = _optimize; |
| 27 | @@ -81,9 +82,18 @@ SignArchive(char *tree, char *keyName, char *zip_file, int javascript, |
| 28 | } |
| 29 | |
| 30 | /* rsa/dsa to zip */ |
| 31 | - sprintf(tempfn, "META-INF/%s.%s", base, (keyType == dsaKey ? "dsa" |
| 32 | - : "rsa")); |
| 33 | - sprintf(fullfn, "%s/%s", tree, tempfn); |
| 34 | + count = snprintf(tempfn, sizeof(tempfn), "META-INF/%s.%s", base, (keyType == dsaKey ? "dsa" : "rsa")); |
| 35 | + if (count >= sizeof(tempfn)) { |
| 36 | + PR_fprintf(errorFD, "unable to write key metadata\n"); |
| 37 | + errorCount++; |
| 38 | + exit(ERRX); |
| 39 | + } |
| 40 | + count = snprintf(fullfn, sizeof(fullfn), "%s/%s", tree, tempfn); |
| 41 | + if (count >= sizeof(fullfn)) { |
| 42 | + PR_fprintf(errorFD, "unable to write key metadata\n"); |
| 43 | + errorCount++; |
| 44 | + exit(ERRX); |
| 45 | + } |
| 46 | JzipAdd(fullfn, tempfn, zipfile, compression_level); |
| 47 | |
| 48 | /* Loop through all files & subdirectories, add to archive */ |
| 49 | @@ -93,20 +103,44 @@ SignArchive(char *tree, char *keyName, char *zip_file, int javascript, |
| 50 | } |
| 51 | /* mf to zip */ |
| 52 | strcpy(tempfn, "META-INF/manifest.mf"); |
| 53 | - sprintf(fullfn, "%s/%s", tree, tempfn); |
| 54 | + count = snprintf(fullfn, sizeof(fullfn), "%s/%s", tree, tempfn); |
| 55 | + if (count >= sizeof(fullfn)) { |
| 56 | + PR_fprintf(errorFD, "unable to write manifest\n"); |
| 57 | + errorCount++; |
| 58 | + exit(ERRX); |
| 59 | + } |
| 60 | JzipAdd(fullfn, tempfn, zipfile, compression_level); |
| 61 | |
| 62 | /* sf to zip */ |
| 63 | - sprintf(tempfn, "META-INF/%s.sf", base); |
| 64 | - sprintf(fullfn, "%s/%s", tree, tempfn); |
| 65 | + count = snprintf(tempfn, sizeof(tempfn), "META-INF/%s.sf", base); |
| 66 | + if (count >= sizeof(tempfn)) { |
| 67 | + PR_fprintf(errorFD, "unable to write sf metadata\n"); |
| 68 | + errorCount++; |
| 69 | + exit(ERRX); |
| 70 | + } |
| 71 | + count = snprintf(fullfn, sizeof(fullfn), "%s/%s", tree, tempfn); |
| 72 | + if (count >= sizeof(fullfn)) { |
| 73 | + PR_fprintf(errorFD, "unable to write sf metadata\n"); |
| 74 | + errorCount++; |
| 75 | + exit(ERRX); |
| 76 | + } |
| 77 | JzipAdd(fullfn, tempfn, zipfile, compression_level); |
| 78 | |
| 79 | /* Add the rsa/dsa file to the zip archive normally */ |
| 80 | if (!xpi_arc) { |
| 81 | /* rsa/dsa to zip */ |
| 82 | - sprintf(tempfn, "META-INF/%s.%s", base, (keyType == dsaKey ? "dsa" |
| 83 | - : "rsa")); |
| 84 | - sprintf(fullfn, "%s/%s", tree, tempfn); |
| 85 | + count = snprintf(tempfn, sizeof(tempfn), "META-INF/%s.%s", base, (keyType == dsaKey ? "dsa" : "rsa")); |
| 86 | + if (count >= sizeof(tempfn)) { |
| 87 | + PR_fprintf(errorFD, "unable to write key metadata\n"); |
| 88 | + errorCount++; |
| 89 | + exit(ERRX); |
| 90 | + } |
| 91 | + count = snprintf(fullfn, sizeof(fullfn), "%s/%s", tree, tempfn); |
| 92 | + if (count >= sizeof(fullfn)) { |
| 93 | + PR_fprintf(errorFD, "unable to write key metadata\n"); |
| 94 | + errorCount++; |
| 95 | + exit(ERRX); |
| 96 | + } |
| 97 | JzipAdd(fullfn, tempfn, zipfile, compression_level); |
| 98 | } |
| 99 | |
| 100 | @@ -408,6 +442,7 @@ static int |
| 101 | manifesto_xpi_fn(char *relpath, char *basedir, char *reldir, char *filename, void *arg) |
| 102 | { |
| 103 | char fullname[FNSIZE]; |
| 104 | + int count; |
| 105 | |
| 106 | if (verbosity >= 0) { |
| 107 | PR_fprintf(outputFD, "--> %s\n", relpath); |
| 108 | @@ -421,7 +456,10 @@ manifesto_xpi_fn(char *relpath, char *basedir, char *reldir, char *filename, voi |
| 109 | if (!PL_HashTableLookup(extensions, ext)) |
| 110 | return 0; |
| 111 | } |
| 112 | - sprintf(fullname, "%s/%s", basedir, relpath); |
| 113 | + count = snprintf(fullname, sizeof(fullname), "%s/%s", basedir, relpath); |
| 114 | + if (count >= sizeof(fullname)) { |
| 115 | + return 1; |
| 116 | + } |
| 117 | JzipAdd(fullname, relpath, zipfile, compression_level); |
| 118 | |
| 119 | return 0; |