rwrap: Don't dereference NULL when skipping broken records
[resolv_wrapper.git] / src / resolv_wrapper.c
index a0b28211597a49f49d4b882165c0c4710247ed49..7211ad087a4bcb286a4cc162aee465d53748e849 100644 (file)
@@ -678,12 +678,6 @@ static int rwrap_get_record(const char *hostfile, unsigned recursion,
                NEXT_KEY(rec_type, key);
                NEXT_KEY(key, value);
 
-               q = value;
-               while(q[0] != '\n' && q[0] != '\0') {
-                       q++;
-               }
-               q[0] = '\0';
-
                if (key == NULL || value == NULL) {
                        RWRAP_LOG(RWRAP_LOG_WARN,
                                "Malformed line: not enough parts, use \"rec_type key data\n"
@@ -691,6 +685,12 @@ static int rwrap_get_record(const char *hostfile, unsigned recursion,
                        continue;
                }
 
+               q = value;
+               while(q[0] != '\n' && q[0] != '\0') {
+                       q++;
+               }
+               q[0] = '\0';
+
                if (TYPE_MATCH(type, ns_t_a, rec_type, "A", key, query)) {
                        rc = rwrap_create_fake_a_rr(key, value, rr);
                        break;