Browse code

nsq: use snprintf() instead of sprintf()

Daniel-Constantin Mierla authored on 02/12/2019 15:21:25
Showing 1 changed files
... ...
@@ -92,23 +92,23 @@ int nsq_consumer_event(char *payload, char *channel, char *topic)
92 92
 	json_api.extract_field(json_obj, k, &ev_name);
93 93
 	pkg_free(k);
94 94
 
95
-	sprintf(buffer, "nsq:consumer-event-%.*s-%.*s",ev_category.len, ev_category.s, ev_name.len, ev_name.s);
95
+	snprintf(buffer, 512, "nsq:consumer-event-%.*s-%.*s",ev_category.len, ev_category.s, ev_name.len, ev_name.s);
96 96
 	for (p=buffer ; *p; ++p) *p = tolower(*p);
97 97
 	for (p=buffer ; *p; ++p) if(*p == '_') *p = '-';
98 98
 	if (nsq_consumer_fire_event(buffer) != 0) {
99
-		sprintf(buffer, "nsq:consumer-event-%.*s", ev_category.len, ev_category.s);
99
+		snprintf(buffer, 512, "nsq:consumer-event-%.*s", ev_category.len, ev_category.s);
100 100
 		for (p=buffer ; *p; ++p) *p = tolower(*p);
101 101
 		for (p=buffer ; *p; ++p) if(*p == '_') *p = '-';
102 102
 		if (nsq_consumer_fire_event(buffer) != 0) {
103
-			sprintf(buffer, "nsq:consumer-event-%.*s-%.*s", nsq_event_key.len, nsq_event_key.s, nsq_event_sub_key.len, nsq_event_sub_key.s);
103
+			snprintf(buffer, 512, "nsq:consumer-event-%.*s-%.*s", nsq_event_key.len, nsq_event_key.s, nsq_event_sub_key.len, nsq_event_sub_key.s);
104 104
 			for (p=buffer ; *p; ++p) *p = tolower(*p);
105 105
 			for (p=buffer ; *p; ++p) if(*p == '_') *p = '-';
106 106
 			if (nsq_consumer_fire_event(buffer) != 0) {
107
-				sprintf(buffer, "nsq:consumer-event-%.*s", nsq_event_key.len, nsq_event_key.s);
107
+				snprintf(buffer, 512, "nsq:consumer-event-%.*s", nsq_event_key.len, nsq_event_key.s);
108 108
 				for (p=buffer ; *p; ++p) *p = tolower(*p);
109 109
 				for (p=buffer ; *p; ++p) if(*p == '_') *p = '-';
110 110
 				if (nsq_consumer_fire_event(buffer) != 0) {
111
-					sprintf(buffer, "nsq:consumer-event");
111
+					snprintf(buffer, 512, "nsq:consumer-event");
112 112
 					if (nsq_consumer_fire_event(buffer) != 0) {
113 113
 						LM_ERR("nsq:consumer-event not found");
114 114
 					}