Просмотр исходного кода

Fix pack settings.hash starting with \0 even though it's a valid hash.

Bryan Drewery 7 лет назад
Родитель
Сommit
a7b5169241
4 измененных файлов с 18 добавлено и 6 удалено
  1. 2 1
      doc/UPDATES.md
  2. 1 1
      src/binary.cc
  3. 2 2
      src/main.cc
  4. 13 2
      src/settings.h

+ 2 - 1
doc/UPDATES.md

@@ -2,7 +2,8 @@
   * Clear FiSH keys when a client quits.
   * Fix crash when clearing last botset entry for a bot.
   * Bots now share channel key to other bots even if not opped.
-  * Some small performance improvements
+  * Some small performance improvements.
+  * Fix rare issue with writing binary config.
 
 # 1.4.9
   * Fix various compile warnings and spam

+ 1 - 1
src/binary.cc

@@ -639,7 +639,7 @@ tellconfig(settings_t *incfg)
 void
 check_sum(const char *fname, const char *cfgfile, bool read_stdin)
 {
-   if (!settings.hash[0]) {
+   if (!settings_initialized()) {
 
     if (!cfgfile && !read_stdin)
       fatal(STR("Binary not initialized."), 0);

+ 2 - 2
src/main.cc

@@ -744,11 +744,11 @@ int main(int argc, char **argv)
 //  if (!(argc == 2 && (!strcmp(argv[1], "-2") || !strcmp(argv[1], "0")))) {
 //  doesn't work correctly yet, if we don't go in here, our settings stay encrypted
   if (argc == 2 && !strcmp(argv[1], STR("-q"))) {
-    if (settings.hash[0]) exit(4);	/* initialized */
+    if (settings_initialized()) exit(4);	/* initialized */
     exit(5);				/* not initialized */
   }
   if (argc == 2 && !strcmp(argv[1], STR("-p"))) {
-    if (settings.hash[0]) exit(4);	/* initialized */
+    if (settings_initialized()) exit(4);	/* initialized */
     exit(5);				/* not initialized */
   }
 

+ 13 - 2
src/settings.h

@@ -1,6 +1,8 @@
 #ifndef _SETTINGS_H
 #define _SETTINGS_H
 
+#include <string.h>
+
 // If changing this, need to also change the usage in main.c which assumes all of it is \200
 #define SETTINGS_HEADER "\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200"
 #define PREFIXLEN sizeof(SETTINGS_HEADER)
@@ -10,7 +12,7 @@
 
 #define DYNAMIC_HEADER dynamic_initialized
 
-typedef struct settings_struct {
+struct settings_struct {
   char prefix[PREFIXLEN];
   /* -- STATIC -- */
 //  char hash[33];
@@ -37,7 +39,8 @@ typedef struct settings_struct {
   char portmax[17];       /* for hubs, the reserved port range for incoming connections */
   /* -- PADDING -- */
   char padding[6];        // (16 - (sizeof(settings_t) % 16)) % 16]
-} settings_t;
+} __attribute__((packed, aligned(16)));
+typedef struct settings_struct settings_t;
 
 #define SALT1 {s1_1[0],s1_1[1],s1_5[0],s1_5[1],s1_8[0],s1_8[1],s1_4[0],s1_9[1],s1_2[0],s1_13[0],s1_6[0],s1_6[1],s1_7[0],s1_7[1],s1_3[0],s1_13[1],s1_16[1],s1_4[1],s1_15[0],s1_10[1],s1_14[0],s1_14[1],s1_12[0],s1_12[1],s1_2[1],s1_3[1],s1_11[0],s1_11[1],s1_10[0],s1_15[1],s1_16[0],s1_9[0],'\0'}
 #define SALT2 {s2_5[0],s2_5[1],s2_2[0],s2_2[1],s2_8[1],s2_4[0],s2_7[1],s2_4[1],s2_1[0],s2_6[0],s2_1[1],s2_6[1],s2_3[0],s2_3[1],s2_8[0],s2_7[0],'\0'}
@@ -64,4 +67,12 @@ sizeof(settings.portmin) + sizeof(settings.portmin) + sizeof(settings.datadir)
 
 extern settings_t       settings;
 
+static inline bool
+__attribute__((pure))
+settings_initialized(void)
+{
+  static const char p[sizeof(settings.hash)] = "";
+  return memcmp(settings.hash, p, sizeof(settings.hash)) != 0;
+}
+
 #endif /* !_SETTINGS_H */