diagnostics: Fix errors found via static analysis 37/318137/1 accepted/tizen/7.0/unified/20250115.045312
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 16 Aug 2023 12:23:04 +0000 (14:23 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Mon, 13 Jan 2025 09:46:53 +0000 (10:46 +0100)
Change-Id: Iad3f8e31e62d5a0fe2d87a98e9fdbfe26359a4e0

packaging/crash-worker.spec
src/bugreport-service/diagnostics/diagnostics_dump.c

index 3f771be54ab61813be21ea9af046889e10252c3f..3ae4dd4051c2bb05f48f5919282b042acbb0bb0f 100644 (file)
@@ -16,7 +16,7 @@
 
 Name:           crash-worker
 Summary:        Coredump handler and report generator for Tizen
-Version:        7.0.4
+Version:        7.0.5
 Release:        1
 Group:          Framework/system
 License:        MIT
index c4455916a70f436cba73d22404de1570104db18e..cc79e42fbe3403bb48b2d622644a389dbe2b3aed 100644 (file)
@@ -309,14 +309,15 @@ static struct report_file *find_report_file(const char *ident, struct report_fil
        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) {
@@ -330,19 +331,29 @@ static bool parse_pid_from_report_file(int report_fd, char *str)
        }
        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;
        }