From d604bad632f50ffa1ffd0a470b01825b4b162ab7 Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Thu, 3 Mar 2016 01:32:15 +0900 Subject: [PATCH] sbin/hammer: Don't modify buffer_info for config data for no reason print_config() introduced by bc5af92e modifies the data part of buffer_info via strsep(3). No other part of hammer show modifies data read from block devices obviously because the command is supposed to be a read-only command. Although it's still safe to modify the data part as long as modified flag isn't set to 1, it's just safer to strdup(3) the data part before calling print_config(). If someone ever sets modified flag for some reason, calling print_config() will break the filesystem. --- sbin/hammer/cmd_show.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sbin/hammer/cmd_show.c b/sbin/hammer/cmd_show.c index 1dfa549a89..820bdb5b24 100644 --- a/sbin/hammer/cmd_show.c +++ b/sbin/hammer/cmd_show.c @@ -634,8 +634,9 @@ print_config(char *cfgtxt) printf("\n%17s", ""); printf("config stext=\"\n"); - while((token = strsep(&cfgtxt, "\r\n")) != NULL) { - printf("%17s %s\n", "", token); + if (cfgtxt != NULL) { + while((token = strsep(&cfgtxt, "\r\n")) != NULL) + printf("%17s %s\n", "", token); } printf("%17s\"", ""); } @@ -735,7 +736,9 @@ print_record(hammer_btree_elm_t elm) break; case HAMMER_RECTYPE_CONFIG: if (VerboseOpt > 2) { - print_config(data->config.text); + char *p = strdup(data->config.text); + print_config(p); + free(p); } break; case HAMMER_RECTYPE_DATA: -- 2.41.0