snprintf() can return numers of characters that "would have been
written if buffer would be large enough", not actual characters
written.
This commits reworks logger request command construction to
avoid snprintf().
Problem pointed out by κΉμμ <won0.kim@samsung.com> (thank you!)
Change-Id: I664cc0ce779eaff3c004e47fd5102b0576295630
int len = strlen(request_string);
for (int i = 1; i < argc; i++) {
- int r = snprintf(request_string + len, sizeof(request_string) - len, " %s", argv[i]);
- if (r > 0)
- len += r;
- else
+ int arglen = strnlen(argv[i], MAX_LOGGER_REQUEST_LEN);
+ int needed = arglen + 1 /* space */ + 1 /* null byte */;
+ if (len + needed > sizeof(request_string))
return 0;
- }
- len += 1; // for terminating null byte
+ strncat(request_string, " ", 1);
+ strncat(request_string, argv[i], arglen + 1);
+ len += needed;
+ }
ctrl.length += len;
iov[1].iov_len = len;