author | Lukas Fleischer <cgit@cryptocrack.de> | 2011-04-05 08:35:43 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2011-05-23 20:58:35 (UTC) |
commit | a0bf375a1a9b74056a913f3687c6f5b42ad4acf6 (patch) (unidiff) | |
tree | d8845fbb7fcf73da11f29673081ed2ca31964e2e | |
parent | 070e109c1413d28b54eb6123a9fd24ac98897554 (diff) | |
download | cgit-a0bf375a1a9b74056a913f3687c6f5b42ad4acf6.zip cgit-a0bf375a1a9b74056a913f3687c6f5b42ad4acf6.tar.gz cgit-a0bf375a1a9b74056a913f3687c6f5b42ad4acf6.tar.bz2 |
Avoid null pointer dereference in reencode().
Returning "*txt" if "txt" is a null pointer is a bad thing. Spotted with
clang-analyzer.
Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | parsing.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -82,49 +82,52 @@ char *parse_user(char *t, char **name, char **email, unsigned long *date) | |||
82 | mode++; | 82 | mode++; |
83 | } else if (mode == 2 && *p == '\n') { | 83 | } else if (mode == 2 && *p == '\n') { |
84 | *email = substr(t, p); | 84 | *email = substr(t, p); |
85 | p++; | 85 | p++; |
86 | break; | 86 | break; |
87 | } else if (mode == 3 && isdigit(*p)) { | 87 | } else if (mode == 3 && isdigit(*p)) { |
88 | *date = atol(p); | 88 | *date = atol(p); |
89 | mode++; | 89 | mode++; |
90 | } else if (*p == '\n') { | 90 | } else if (*p == '\n') { |
91 | p++; | 91 | p++; |
92 | break; | 92 | break; |
93 | } | 93 | } |
94 | p++; | 94 | p++; |
95 | } | 95 | } |
96 | return p; | 96 | return p; |
97 | } | 97 | } |
98 | 98 | ||
99 | #ifdef NO_ICONV | 99 | #ifdef NO_ICONV |
100 | #define reencode(a, b, c) | 100 | #define reencode(a, b, c) |
101 | #else | 101 | #else |
102 | const char *reencode(char **txt, const char *src_enc, const char *dst_enc) | 102 | const char *reencode(char **txt, const char *src_enc, const char *dst_enc) |
103 | { | 103 | { |
104 | char *tmp; | 104 | char *tmp; |
105 | 105 | ||
106 | if (!txt || !*txt || !src_enc || !dst_enc) | 106 | if (!txt) |
107 | return NULL; | ||
108 | |||
109 | if (!*txt || !src_enc || !dst_enc) | ||
107 | return *txt; | 110 | return *txt; |
108 | 111 | ||
109 | /* no encoding needed if src_enc equals dst_enc */ | 112 | /* no encoding needed if src_enc equals dst_enc */ |
110 | if(!strcasecmp(src_enc, dst_enc)) | 113 | if(!strcasecmp(src_enc, dst_enc)) |
111 | return *txt; | 114 | return *txt; |
112 | 115 | ||
113 | tmp = reencode_string(*txt, dst_enc, src_enc); | 116 | tmp = reencode_string(*txt, dst_enc, src_enc); |
114 | if (tmp) { | 117 | if (tmp) { |
115 | free(*txt); | 118 | free(*txt); |
116 | *txt = tmp; | 119 | *txt = tmp; |
117 | } | 120 | } |
118 | return *txt; | 121 | return *txt; |
119 | } | 122 | } |
120 | #endif | 123 | #endif |
121 | 124 | ||
122 | struct commitinfo *cgit_parse_commit(struct commit *commit) | 125 | struct commitinfo *cgit_parse_commit(struct commit *commit) |
123 | { | 126 | { |
124 | struct commitinfo *ret; | 127 | struct commitinfo *ret; |
125 | char *p = commit->buffer, *t = commit->buffer; | 128 | char *p = commit->buffer, *t = commit->buffer; |
126 | 129 | ||
127 | ret = xmalloc(sizeof(*ret)); | 130 | ret = xmalloc(sizeof(*ret)); |
128 | ret->commit = commit; | 131 | ret->commit = commit; |
129 | ret->author = NULL; | 132 | ret->author = NULL; |
130 | ret->author_email = NULL; | 133 | ret->author_email = NULL; |