~ubuntu-branches/ubuntu/lucid/nspr/lucid-updates

« back to all changes in this revision

Viewing changes to debian/patches/CVE-2014-1545.patch

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2014-06-27 11:09:38 UTC
  • Revision ID: package-import@ubuntu.com-20140627110938-6lflaase8nff76t4
Tags: 4.9.5-0ubuntu0.10.04.3
* SECURITY UPDATE: denial of service or arbitrary code execution via
  sprintf
  - debian/patches/CVE-2014-1545.patch: use snprintf and check values
    without using PR_ASSERT in mozilla/nsprpub/pr/src/io/prprf.c, added
    tests to mozilla/nsprpub/pr/tests/{Makefile.in,prfdbl.c}.
  - CVE-2014-1545

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Description: fix denial of service or arbitrary code execution via sprintf
 
2
Origin: upstream, https://hg.mozilla.org/projects/nspr/rev/74eb616c618e
 
3
 
 
4
Index: nspr-4.9.5/mozilla/nsprpub/pr/src/io/prprf.c
 
5
===================================================================
 
6
--- nspr-4.9.5.orig/mozilla/nsprpub/pr/src/io/prprf.c   2012-05-08 18:55:12.000000000 -0400
 
7
+++ nspr-4.9.5/mozilla/nsprpub/pr/src/io/prprf.c        2014-06-27 11:06:26.430686964 -0400
 
8
@@ -304,7 +304,7 @@
 
9
 ** Convert a double precision floating point number into its printable
 
10
 ** form.
 
11
 **
 
12
-** XXX stop using sprintf to convert floating point
 
13
+** XXX stop using snprintf to convert floating point
 
14
 */
 
15
 static int cvt_f(SprintfState *ss, double d, const char *fmt0, const char *fmt1)
 
16
 {
 
17
@@ -312,15 +312,14 @@
 
18
     char fout[300];
 
19
     int amount = fmt1 - fmt0;
 
20
 
 
21
-    PR_ASSERT((amount > 0) && (amount < sizeof(fin)));
 
22
-    if (amount >= sizeof(fin)) {
 
23
-       /* Totally bogus % command to sprintf. Just ignore it */
 
24
+    if (amount <= 0 || amount >= sizeof(fin)) {
 
25
+       /* Totally bogus % command to snprintf. Just ignore it */
 
26
        return 0;
 
27
     }
 
28
     memcpy(fin, fmt0, amount);
 
29
     fin[amount] = 0;
 
30
 
 
31
-    /* Convert floating point using the native sprintf code */
 
32
+    /* Convert floating point using the native snprintf code */
 
33
 #ifdef DEBUG
 
34
     {
 
35
         const char *p = fin;
 
36
@@ -330,14 +329,11 @@
 
37
         }
 
38
     }
 
39
 #endif
 
40
-    sprintf(fout, fin, d);
 
41
-
 
42
-    /*
 
43
-    ** This assert will catch overflow's of fout, when building with
 
44
-    ** debugging on. At least this way we can track down the evil piece
 
45
-    ** of calling code and fix it!
 
46
-    */
 
47
-    PR_ASSERT(strlen(fout) < sizeof(fout));
 
48
+    memset(fout, 0, sizeof(fout));
 
49
+    snprintf(fout, sizeof(fout), fin, d);
 
50
+    /* Explicitly null-terminate fout because on Windows snprintf doesn't
 
51
+     * append a null-terminator if the buffer is too small. */
 
52
+    fout[sizeof(fout) - 1] = '\0';
 
53
 
 
54
     return (*ss->stuff)(ss, fout, strlen(fout));
 
55
 }
 
56
Index: nspr-4.9.5/mozilla/nsprpub/pr/tests/Makefile.in
 
57
===================================================================
 
58
--- nspr-4.9.5.orig/mozilla/nsprpub/pr/tests/Makefile.in        2012-11-13 18:18:00.000000000 -0500
 
59
+++ nspr-4.9.5/mozilla/nsprpub/pr/tests/Makefile.in     2014-06-27 11:06:26.430686964 -0400
 
60
@@ -106,6 +106,7 @@
 
61
        poll_nm.c               \
 
62
        poll_to.c               \
 
63
        pollable.c              \
 
64
+       prfdbl.c                \
 
65
        prftest.c               \
 
66
        prftest1.c              \
 
67
        prftest2.c              \
 
68
Index: nspr-4.9.5/mozilla/nsprpub/pr/tests/prfdbl.c
 
69
===================================================================
 
70
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
71
+++ nspr-4.9.5/mozilla/nsprpub/pr/tests/prfdbl.c        2014-06-27 11:06:26.430686964 -0400
 
72
@@ -0,0 +1,28 @@
 
73
+/* This Source Code Form is subject to the terms of the Mozilla Public
 
74
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
 
75
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
76
+
 
77
+/*
 
78
+ * This is a simple test of the PR_fprintf() function for doubles.
 
79
+ */
 
80
+
 
81
+#include "prprf.h"
 
82
+
 
83
+int main()
 
84
+{
 
85
+    double pi = 3.1415926;
 
86
+    double e = 2.71828;
 
87
+    double root2 = 1.414;
 
88
+    double nan = 0.0 / 0.0;
 
89
+
 
90
+    PR_fprintf(PR_STDOUT, "pi is %f.\n", pi);
 
91
+    PR_fprintf(PR_STDOUT, "e is %f.\n", e);
 
92
+    PR_fprintf(PR_STDOUT, "The square root of 2 is %f.\n", root2);
 
93
+    PR_fprintf(PR_STDOUT, "NaN is %f.\n", nan);
 
94
+
 
95
+    PR_fprintf(PR_STDOUT, "pi is %301f.\n", pi);
 
96
+    PR_fprintf(PR_STDOUT, "e is %65416.123f.\n", e);
 
97
+    PR_fprintf(PR_STDOUT, "e is %0000000000000000000065416.123f.\n", e);
 
98
+    PR_fprintf(PR_STDOUT, "NaN is %1024.1f.\n", nan);
 
99
+    return 0;
 
100
+}