(strobj_len,print_string): Extra safety not to dereference NULL pointer.
Showing
1 changed file
with
16 additions
and
4 deletions
... | @@ -66,7 +66,7 @@ strobj_free (strobj_t *obj) | ... | @@ -66,7 +66,7 @@ strobj_free (strobj_t *obj) |
66 | } | 66 | } |
67 | 67 | ||
68 | #define strobj_ptr(p) ((p)->ptr ? (p)->ptr : "") | 68 | #define strobj_ptr(p) ((p)->ptr ? (p)->ptr : "") |
69 | #define strobj_len(p) strlen((p)->ptr) | 69 | #define strobj_len(p) (strobj_is_null(p) ? 0 : strlen((p)->ptr)) |
70 | #define strobj_is_null(p) ((p)->ptr == NULL) | 70 | #define strobj_is_null(p) ((p)->ptr == NULL) |
71 | #define strobj_is_static(p) ((p)->size == 0) | 71 | #define strobj_is_static(p) ((p)->size == 0) |
72 | 72 | ||
... | @@ -167,8 +167,15 @@ compress_ws (char *str, size_t *size) | ... | @@ -167,8 +167,15 @@ compress_ws (char *str, size_t *size) |
167 | static void | 167 | static void |
168 | print_string (struct mh_machine *mach, size_t width, char *str, size_t len) | 168 | print_string (struct mh_machine *mach, size_t width, char *str, size_t len) |
169 | { | 169 | { |
170 | size_t rest = strlen (str); | 170 | size_t rest; |
171 | 171 | ||
172 | if (!str) | ||
173 | { | ||
174 | str = ""; | ||
175 | len = 0; | ||
176 | } | ||
177 | |||
178 | rest = strlen (str); | ||
172 | if (len > rest) | 179 | if (len > rest) |
173 | len = rest; | 180 | len = rest; |
174 | if (!width) | 181 | if (!width) |
... | @@ -864,9 +871,14 @@ _parse_date (struct mh_machine *mach, struct tm *tm, mu_timezone *tz) | ... | @@ -864,9 +871,14 @@ _parse_date (struct mh_machine *mach, struct tm *tm, mu_timezone *tz) |
864 | 871 | ||
865 | if (parse822_date_time (&p, date+strlen(date), tm, tz)) | 872 | if (parse822_date_time (&p, date+strlen(date), tm, tz)) |
866 | { | 873 | { |
867 | mh_error ("can't parse date: [%s]", date); | 874 | time_t t; |
868 | return -1; | 875 | |
876 | /*mh_error ("can't parse date: [%s]", date);*/ | ||
877 | time (&t); | ||
878 | *tm = *localtime (&t); | ||
879 | tz->utc_offset = mu_utc_offset (); | ||
869 | } | 880 | } |
881 | |||
870 | return 0; | 882 | return 0; |
871 | } | 883 | } |
872 | 884 | ... | ... |
-
Please register or sign in to post a comment