File: open-fmode.patch

package info (click to toggle)
mdk 1.3.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,016 kB
  • sloc: ansic: 22,682; sh: 6,167; lisp: 1,118; lex: 830; makefile: 582; yacc: 288; python: 124
file content (28 lines) | stat: -rw-r--r-- 791 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Description: Fix two possible segfaults in file mode handling.
Forwarded: not-yet
Author: Peter Pentchev <roam@ringlet.net>
Last-Update: 2015-09-15

--- a/mixlib/mix_file.c
+++ b/mixlib/mix_file.c
@@ -50,6 +50,9 @@
   FILE *file;
   const gchar *fmode = fmode_to_type_ (mode);
 
+  if (fmode == NULL)
+    return NULL;
+
   /* if the read/write file already exists, open in r+ mode */
   if (mode == mix_io_RDWRT && (file = fopen (name, "r")))
     {
--- a/mixlib/xmix_io.h
+++ b/mixlib/xmix_io.h
@@ -35,7 +35,7 @@
 
 extern const char * io_OPENTYPE_[5];
 
-#define fmode_to_type_(mode) ( (mode) < 6 ? io_OPENTYPE_[(mode)]:NULL )
+#define fmode_to_type_(mode) ( (mode) < (sizeof(io_OPENTYPE_) / sizeof(io_OPENTYPE_[0])) ? io_OPENTYPE_[(mode)]:NULL )
 
 /* initialisation */
 extern gboolean