return NULL;
}
-static bool parse_pid_from_report_file(int report_fd, char *str)
+static bool parse_pid_from_report_file(int report_fd, char *str, size_t strsize)
{
- FILE *fp;
+ assert(str);
+ assert(strsize > 0);
+
+ FILE *fp = NULL;
char buff[1024];
int pid = -1;
-
- if (!str)
- return false;
+ bool ret = false;
fp = fdopen(report_fd, "r");
if (!fp) {
}
if (pid < 0) {
_E("There is no PID information in the report file");
- return false;
+ goto out;
+ }
+
+ int r = snprintf(str, strsize, "%d", pid);
+ if (r < 0 || r >= strsize) {
+ _E("Internal error: Unable to store PID parsed from report file - increase pid[n] size");
+ goto out;
}
- sprintf(str, "%d", pid);
+ ret = true;
- return true;
+out:
+ if (fp)
+ fclose(fp);
+
+ return ret;
}
static bool write_pid(int fd, int in_fd)
{
char pid[10];
- if (!parse_pid_from_report_file(in_fd, pid)) {
+ if (!parse_pid_from_report_file(in_fd, pid, sizeof(pid))) {
dprintf(fd, "Internal error\n");
return false;
}