Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit fbfba7a

Browse files
sunshinecogitster
authored andcommitted
mailmap: debug: avoid passing NULL to fprintf() '%s' conversion specification
POSIX does not state the behavior of '%s' conversion when passed a NULL pointer. Some implementations interpolate literal "(null)"; others may crash. Callers of debug_mm() often pass NULL as indication of either a missing name or email address. Instead, let's always supply a proper string pointer, and make it a bit more descriptive: "(none)" Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a8002a5 commit fbfba7a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

mailmap.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
#define DEBUG_MAILMAP 0
66
#if DEBUG_MAILMAP
77
#define debug_mm(...) fprintf(stderr, __VA_ARGS__)
8+
#define debug_str(X) ((X) ? (X) : "(none)")
89
#else
910
static inline void debug_mm(const char *format, ...) {}
11+
static inline const char *debug_str(const char *s) { return s; }
1012
#endif
1113

1214
const char *git_mailmap_file;
@@ -29,7 +31,7 @@ struct mailmap_entry {
2931
static void free_mailmap_info(void *p, const char *s)
3032
{
3133
struct mailmap_info *mi = (struct mailmap_info *)p;
32-
debug_mm("mailmap: -- complex: '%s' -> '%s' <%s>\n", s, mi->name, mi->email);
34+
debug_mm("mailmap: -- complex: '%s' -> '%s' <%s>\n", s, debug_str(mi->name), debug_str(mi->email));
3335
free(mi->name);
3436
free(mi->email);
3537
}
@@ -38,7 +40,8 @@ static void free_mailmap_entry(void *p, const char *s)
3840
{
3941
struct mailmap_entry *me = (struct mailmap_entry *)p;
4042
debug_mm("mailmap: removing entries for <%s>, with %d sub-entries\n", s, me->namemap.nr);
41-
debug_mm("mailmap: - simple: '%s' <%s>\n", me->name, me->email);
43+
debug_mm("mailmap: - simple: '%s' <%s>\n", debug_str(me->name), debug_str(me->email));
44+
4245
free(me->name);
4346
free(me->email);
4447

@@ -94,7 +97,7 @@ static void add_mapping(struct string_list *map,
9497
}
9598

9699
debug_mm("mailmap: '%s' <%s> -> '%s' <%s>\n",
97-
old_name, old_email, new_name, new_email);
100+
debug_str(old_name), old_email, debug_str(new_name), debug_str(new_email));
98101
}
99102

100103
static char *parse_name_and_email(char *buffer, char **name,
@@ -309,7 +312,7 @@ int map_user(struct string_list *map,
309312
struct mailmap_entry *me;
310313

311314
debug_mm("map_user: map '%.*s' <%.*s>\n",
312-
(int)*namelen, *name, (int)*emaillen, *email);
315+
(int)*namelen, debug_str(*name), (int)*emaillen, debug_str(*email));
313316

314317
item = lookup_prefix(map, *email, *emaillen);
315318
if (item != NULL) {
@@ -337,8 +340,8 @@ int map_user(struct string_list *map,
337340
*name = mi->name;
338341
*namelen = strlen(*name);
339342
}
340-
debug_mm("map_user: to '%.*s' <%.*s>\n", (int)*namelen, *name,
341-
(int)*emaillen, *email);
343+
debug_mm("map_user: to '%.*s' <%.*s>\n", (int)*namelen, debug_str(*name),
344+
(int)*emaillen, debug_str(*email));
342345
return 1;
343346
}
344347
debug_mm("map_user: --\n");

0 commit comments

Comments
 (0)