sbin/hammer: Don't modify buffer_info for config data for no reason
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Wed, 2 Mar 2016 16:32:15 +0000 (01:32 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sat, 5 Mar 2016 09:43:58 +0000 (18:43 +0900)
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

index 1dfa549..820bdb5 100644 (file)
@@ -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: