Whamcloud - gitweb
et_c.awk: Use a dynamically allocated structure in
authorTheodore Ts'o <tytso@mit.edu>
Mon, 20 Jun 2005 20:24:04 +0000 (16:24 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 20 Jun 2005 20:24:04 +0000 (16:24 -0400)
initialize_xxx_error_table(), to prevent segfaults if an
old library calls initialize_xxx_error_table, and another
library/application calls add_error_table() on the same
error table, and then calls remove_error_table().
(Addresses Sourcefroge Bug #1150146)

lib/et/ChangeLog
lib/et/et_c.awk
lib/et/test_cases/continuation.c
lib/et/test_cases/heimdal.c
lib/et/test_cases/heimdal2.c
lib/et/test_cases/heimdal3.c
lib/et/test_cases/imap_err.c
lib/et/test_cases/simple.c

index 4bfb0d3..aa4880f 100644 (file)
@@ -1,3 +1,12 @@
+2005-06-20  Theodore Ts'o  <tytso@mit.edu>
+
+       * et_c.awk: Use a dynamically allocated structure in
+               initialize_xxx_error_table(), to prevent segfaults if an
+               old library calls initialize_xxx_error_table, and another
+               library/application calls add_error_table() on the same
+               error table, and then calls remove_error_table().
+               (Addresses Sourcefroge Bug #1150146)
+
 2005-03-21  Theodore Ts'o  <tytso@mit.edu>
 
        * Release of E2fsprogs 1.37
index 1769b79..407c43c 100644 (file)
@@ -237,19 +237,14 @@ END {
        print "" > outfile
        print "static struct et_list link = { 0, 0 };" > outfile
        print "" > outfile
+       print "void initialize_" table_name "_error_table_r(struct et_list **list);" > outfile
        print "void initialize_" table_name "_error_table(void);" > outfile
        print "" > outfile
        print "void initialize_" table_name "_error_table(void) {" > outfile
-       print "    if (!link.table) {" > outfile
-       print "        link.next = _et_list;" > outfile
-       print "        link.table = &et_" table_name "_error_table;" > outfile
-       print "        _et_list = &link;" > outfile
-       print "    }" > outfile
+       print "    initialize_" table_name "_error_table_r(&_et_list);" > outfile
        print "}" > outfile
        print "" > outfile
        print "/* For Heimdal compatibility */" > outfile
-       print "void initialize_" table_name "_error_table_r(struct et_list **list);" > outfile
-       print "" > outfile
        print "void initialize_" table_name "_error_table_r(struct et_list **list)" > outfile
        print "{" > outfile
        print "    struct et_list *et, **end;" > outfile
@@ -258,8 +253,12 @@ END {
        print "        if (et->table->msgs == text)" > outfile
        print "            return;" > outfile
        print "    et = malloc(sizeof(struct et_list));" > outfile
-       print "    if (et == 0)" > outfile
-       print "        return;" > outfile
+       print "    if (et == 0) {" > outfile
+       print "        if (!link.table)" > outfile
+       print "            et = &link;" > outfile
+       print "        else" > outfile
+       print "            return;" > outfile
+       print "    }" > outfile
        print "    et->table = &et_" table_name "_error_table;" > outfile
        print "    et->next = 0;" > outfile
        print "    *end = et;" > outfile
index d48f1fd..0529dd0 100644 (file)
@@ -25,19 +25,14 @@ const struct error_table et_ovk_error_table = { text, 43787520L, 1 };
 
 static struct et_list link = { 0, 0 };
 
+void initialize_ovk_error_table_r(struct et_list **list);
 void initialize_ovk_error_table(void);
 
 void initialize_ovk_error_table(void) {
-    if (!link.table) {
-        link.next = _et_list;
-        link.table = &et_ovk_error_table;
-        _et_list = &link;
-    }
+    initialize_ovk_error_table_r(&_et_list);
 }
 
 /* For Heimdal compatibility */
-void initialize_ovk_error_table_r(struct et_list **list);
-
 void initialize_ovk_error_table_r(struct et_list **list)
 {
     struct et_list *et, **end;
@@ -46,8 +41,12 @@ void initialize_ovk_error_table_r(struct et_list **list)
         if (et->table->msgs == text)
             return;
     et = malloc(sizeof(struct et_list));
-    if (et == 0)
-        return;
+    if (et == 0) {
+        if (!link.table)
+            et = &link;
+        else
+            return;
+    }
     et->table = &et_ovk_error_table;
     et->next = 0;
     *end = et;
index 3ae62e3..22c7573 100644 (file)
@@ -106,19 +106,14 @@ const struct error_table et_krb_error_table = { text, 39525376L, 82 };
 
 static struct et_list link = { 0, 0 };
 
+void initialize_krb_error_table_r(struct et_list **list);
 void initialize_krb_error_table(void);
 
 void initialize_krb_error_table(void) {
-    if (!link.table) {
-        link.next = _et_list;
-        link.table = &et_krb_error_table;
-        _et_list = &link;
-    }
+    initialize_krb_error_table_r(&_et_list);
 }
 
 /* For Heimdal compatibility */
-void initialize_krb_error_table_r(struct et_list **list);
-
 void initialize_krb_error_table_r(struct et_list **list)
 {
     struct et_list *et, **end;
@@ -127,8 +122,12 @@ void initialize_krb_error_table_r(struct et_list **list)
         if (et->table->msgs == text)
             return;
     et = malloc(sizeof(struct et_list));
-    if (et == 0)
-        return;
+    if (et == 0) {
+        if (!link.table)
+            et = &link;
+        else
+            return;
+    }
     et->table = &et_krb_error_table;
     et->next = 0;
     *end = et;
index 261c852..eba3d62 100644 (file)
@@ -92,19 +92,14 @@ const struct error_table et_kadm_error_table = { text, -1783126272L, 68 };
 
 static struct et_list link = { 0, 0 };
 
+void initialize_kadm_error_table_r(struct et_list **list);
 void initialize_kadm_error_table(void);
 
 void initialize_kadm_error_table(void) {
-    if (!link.table) {
-        link.next = _et_list;
-        link.table = &et_kadm_error_table;
-        _et_list = &link;
-    }
+    initialize_kadm_error_table_r(&_et_list);
 }
 
 /* For Heimdal compatibility */
-void initialize_kadm_error_table_r(struct et_list **list);
-
 void initialize_kadm_error_table_r(struct et_list **list)
 {
     struct et_list *et, **end;
@@ -113,8 +108,12 @@ void initialize_kadm_error_table_r(struct et_list **list)
         if (et->table->msgs == text)
             return;
     et = malloc(sizeof(struct et_list));
-    if (et == 0)
-        return;
+    if (et == 0) {
+        if (!link.table)
+            et = &link;
+        else
+            return;
+    }
     et->table = &et_kadm_error_table;
     et->next = 0;
     *end = et;
index 4c475a2..18a9ccc 100644 (file)
@@ -26,19 +26,14 @@ const struct error_table et_h3test_error_table = { text, 43787520L, 2 };
 
 static struct et_list link = { 0, 0 };
 
+void initialize_h3test_error_table_r(struct et_list **list);
 void initialize_h3test_error_table(void);
 
 void initialize_h3test_error_table(void) {
-    if (!link.table) {
-        link.next = _et_list;
-        link.table = &et_h3test_error_table;
-        _et_list = &link;
-    }
+    initialize_h3test_error_table_r(&_et_list);
 }
 
 /* For Heimdal compatibility */
-void initialize_h3test_error_table_r(struct et_list **list);
-
 void initialize_h3test_error_table_r(struct et_list **list)
 {
     struct et_list *et, **end;
@@ -47,8 +42,12 @@ void initialize_h3test_error_table_r(struct et_list **list)
         if (et->table->msgs == text)
             return;
     et = malloc(sizeof(struct et_list));
-    if (et == 0)
-        return;
+    if (et == 0) {
+        if (!link.table)
+            et = &link;
+        else
+            return;
+    }
     et->table = &et_h3test_error_table;
     et->next = 0;
     *end = et;
index f41227b..82a6ad0 100644 (file)
@@ -54,19 +54,14 @@ const struct error_table et_imap_error_table = { text, -1904809472L, 30 };
 
 static struct et_list link = { 0, 0 };
 
+void initialize_imap_error_table_r(struct et_list **list);
 void initialize_imap_error_table(void);
 
 void initialize_imap_error_table(void) {
-    if (!link.table) {
-        link.next = _et_list;
-        link.table = &et_imap_error_table;
-        _et_list = &link;
-    }
+    initialize_imap_error_table_r(&_et_list);
 }
 
 /* For Heimdal compatibility */
-void initialize_imap_error_table_r(struct et_list **list);
-
 void initialize_imap_error_table_r(struct et_list **list)
 {
     struct et_list *et, **end;
@@ -75,8 +70,12 @@ void initialize_imap_error_table_r(struct et_list **list)
         if (et->table->msgs == text)
             return;
     et = malloc(sizeof(struct et_list));
-    if (et == 0)
-        return;
+    if (et == 0) {
+        if (!link.table)
+            et = &link;
+        else
+            return;
+    }
     et->table = &et_imap_error_table;
     et->next = 0;
     *end = et;
index 94db6a1..f182c6f 100644 (file)
@@ -46,19 +46,14 @@ const struct error_table et_krb_error_table = { text, 39525376L, 22 };
 
 static struct et_list link = { 0, 0 };
 
+void initialize_krb_error_table_r(struct et_list **list);
 void initialize_krb_error_table(void);
 
 void initialize_krb_error_table(void) {
-    if (!link.table) {
-        link.next = _et_list;
-        link.table = &et_krb_error_table;
-        _et_list = &link;
-    }
+    initialize_krb_error_table_r(&_et_list);
 }
 
 /* For Heimdal compatibility */
-void initialize_krb_error_table_r(struct et_list **list);
-
 void initialize_krb_error_table_r(struct et_list **list)
 {
     struct et_list *et, **end;
@@ -67,8 +62,12 @@ void initialize_krb_error_table_r(struct et_list **list)
         if (et->table->msgs == text)
             return;
     et = malloc(sizeof(struct et_list));
-    if (et == 0)
-        return;
+    if (et == 0) {
+        if (!link.table)
+            et = &link;
+        else
+            return;
+    }
     et->table = &et_krb_error_table;
     et->next = 0;
     *end = et;