Fix segmentation fault (#6011)
* Fix segmentation fault * Make system info printing safe * Fix quotes for OS name
Vladimir Kobal committed
May 14, 2019 at 18:35 UTC
0d5fa83e224afa6d530ed6a5e6e6fe35a8af955e
3 files changed
+53
-40
database/rrdhost.c
+26
-13
@@ -825,19 +825,32 @@ struct rrdhost_system_info *rrdhost_system_info_dup(struct rrdhost_system_info *
825
struct rrdhost_system_info *ret = callocz(1, sizeof(struct rrdhost_system_info));
826
827
if(likely(system_info)) {
828
- ret->os_name = strdupz(system_info->os_name);
829
- ret->os_id = strdupz(system_info->os_id);
830
- ret->os_id_like = strdupz(system_info->os_id_like);
831
- ret->os_version = strdupz(system_info->os_version);
832
- ret->os_version_id = strdupz(system_info->os_version_id);
833
- ret->os_detection = strdupz(system_info->os_detection);
834
- ret->kernel_name = strdupz(system_info->kernel_name);
835
- ret->kernel_version = strdupz(system_info->kernel_version);
836
- ret->architecture = strdupz(system_info->architecture);
837
- ret->virtualization = strdupz(system_info->virtualization);
838
- ret->virt_detection = strdupz(system_info->virt_detection);
839
- ret->container = strdupz(system_info->container);
840
- ret->container_detection = strdupz(system_info->container_detection);
828
+ if(system_info->os_name)
829
+ ret->os_name = strdupz(system_info->os_name);
830
+ if(system_info->os_id)
831
+ ret->os_id = strdupz(system_info->os_id);
832
+ if(system_info->os_id_like)
833
+ ret->os_id_like = strdupz(system_info->os_id_like);
834
+ if(system_info->os_version)
835
+ ret->os_version = strdupz(system_info->os_version);
836
+ if(system_info->os_version_id)
837
+ ret->os_version_id = strdupz(system_info->os_version_id);
838
+ if(system_info->os_detection)
839
+ ret->os_detection = strdupz(system_info->os_detection);
840
+ if(system_info->kernel_name)
841
+ ret->kernel_name = strdupz(system_info->kernel_name);
842
+ if(system_info->kernel_version)
843
+ ret->kernel_version = strdupz(system_info->kernel_version);
844
+ if(system_info->architecture)
845
+ ret->architecture = strdupz(system_info->architecture);
846
+ if(system_info->virtualization)
847
+ ret->virtualization = strdupz(system_info->virtualization);
848
+ if(system_info->virt_detection)
849
+ ret->virt_detection = strdupz(system_info->virt_detection);
850
+ if(system_info->container)
851
+ ret->container = strdupz(system_info->container);
852
+ if(system_info->container_detection)
853
+ ret->container_detection = strdupz(system_info->container_detection);
854
}
855
856
return ret;
streaming/rrdpush.c
+14
-14
@@ -469,20 +469,20 @@ static int rrdpush_sender_thread_connect_to_master(RRDHOST *host, int default_po
469
, default_rrd_update_every
470
, host->os
471
, host->timezone
472
- , (host->tags)?host->tags:""
473
- , host->system_info->os_name
474
- , host->system_info->os_id
475
- , host->system_info->os_id_like
476
- , host->system_info->os_version
477
- , host->system_info->os_version_id
478
- , host->system_info->os_detection
479
- , host->system_info->kernel_name
480
- , host->system_info->kernel_version
481
- , host->system_info->architecture
482
- , host->system_info->virtualization
483
- , host->system_info->virt_detection
484
- , host->system_info->container
485
- , host->system_info->container_detection
472
+ , (host->tags) ? host->tags : ""
473
+ , (host->system_info->os_name) ? host->system_info->os_name : ""
474
+ , (host->system_info->os_id) ? host->system_info->os_id : ""
475
+ , (host->system_info->os_id_like) ? host->system_info->os_id_like : ""
476
+ , (host->system_info->os_version) ? host->system_info->os_version : ""
477
+ , (host->system_info->os_version_id) ? host->system_info->os_version_id : ""
478
+ , (host->system_info->os_detection) ? host->system_info->os_detection : ""
479
+ , (host->system_info->kernel_name) ? host->system_info->kernel_name : ""
480
+ , (host->system_info->kernel_version) ? host->system_info->kernel_version : ""
481
+ , (host->system_info->architecture) ? host->system_info->architecture : ""
482
+ , (host->system_info->virtualization) ? host->system_info->virtualization : ""
483
+ , (host->system_info->virt_detection) ? host->system_info->virt_detection : ""
484
+ , (host->system_info->container) ? host->system_info->container : ""
485
+ , (host->system_info->container_detection) ? host->system_info->container_detection : ""
486
, host->program_name
487
, host->program_version
488
);
web/api/web_api_v1.c
+13
-13
@@ -736,19 +736,19 @@ inline int web_client_api_request_v1_info(RRDHOST *host, struct web_client *w, c
736
web_client_api_request_v1_info_summary_alarm_statuses(host, wb);
737
buffer_strcat(wb, "\t},\n");
738
739
- buffer_sprintf(wb, "\t\"os_name\": %s,\n", host->system_info->os_name);
740
- buffer_sprintf(wb, "\t\"os_id\": \"%s\",\n", host->system_info->os_id);
741
- buffer_sprintf(wb, "\t\"os_id_like\": \"%s\",\n", host->system_info->os_id_like);
742
- buffer_sprintf(wb, "\t\"os_version\": \"%s\",\n", host->system_info->os_version);
743
- buffer_sprintf(wb, "\t\"os_version_id\": \"%s\",\n", host->system_info->os_version_id);
744
- buffer_sprintf(wb, "\t\"os_detection\": \"%s\",\n", host->system_info->os_detection);
745
- buffer_sprintf(wb, "\t\"kernel_name\": \"%s\",\n", host->system_info->kernel_name);
746
- buffer_sprintf(wb, "\t\"kernel_version\": \"%s\",\n", host->system_info->kernel_version);
747
- buffer_sprintf(wb, "\t\"architecture\": \"%s\",\n", host->system_info->architecture);
748
- buffer_sprintf(wb, "\t\"virtualization\": \"%s\",\n", host->system_info->virtualization);
749
- buffer_sprintf(wb, "\t\"virt_detection\": \"%s\",\n", host->system_info->virt_detection);
750
- buffer_sprintf(wb, "\t\"container\": \"%s\",\n", host->system_info->container);
751
- buffer_sprintf(wb, "\t\"container_detection\": \"%s\",\n", host->system_info->container_detection);
739
+ buffer_sprintf(wb, "\t\"os_name\": %s,\n", (host->system_info->os_name) ? host->system_info->os_name : "\"\"");
740
+ buffer_sprintf(wb, "\t\"os_id\": \"%s\",\n", (host->system_info->os_id) ? host->system_info->os_id : "");
741
+ buffer_sprintf(wb, "\t\"os_id_like\": \"%s\",\n", (host->system_info->os_id_like) ? host->system_info->os_id_like : "");
742
+ buffer_sprintf(wb, "\t\"os_version\": \"%s\",\n", (host->system_info->os_version) ? host->system_info->os_version : "");
743
+ buffer_sprintf(wb, "\t\"os_version_id\": \"%s\",\n", (host->system_info->os_version_id) ? host->system_info->os_version_id : "");
744
+ buffer_sprintf(wb, "\t\"os_detection\": \"%s\",\n", (host->system_info->os_detection) ? host->system_info->os_detection : "");
745
+ buffer_sprintf(wb, "\t\"kernel_name\": \"%s\",\n", (host->system_info->kernel_name) ? host->system_info->kernel_name : "");
746
+ buffer_sprintf(wb, "\t\"kernel_version\": \"%s\",\n", (host->system_info->kernel_version) ? host->system_info->kernel_version : "");
747
+ buffer_sprintf(wb, "\t\"architecture\": \"%s\",\n", (host->system_info->architecture) ? host->system_info->architecture : "");
748
+ buffer_sprintf(wb, "\t\"virtualization\": \"%s\",\n", (host->system_info->virtualization) ? host->system_info->virtualization : "");
749
+ buffer_sprintf(wb, "\t\"virt_detection\": \"%s\",\n", (host->system_info->virt_detection) ? host->system_info->virt_detection : "");
750
+ buffer_sprintf(wb, "\t\"container\": \"%s\",\n", (host->system_info->container) ? host->system_info->container : "");
751
+ buffer_sprintf(wb, "\t\"container_detection\": \"%s\",\n", (host->system_info->container_detection) ? host->system_info->container_detection : "");
752
753
buffer_strcat(wb, "\t\"collectors\": [");
754
chartcollectors2json(host, wb);