Fix unsafe code 68/63368/1 accepted/tizen/ivi/20160323.141145 accepted/tizen/mobile/20160323.135929 accepted/tizen/tv/20160323.140125 accepted/tizen/wearable/20160323.135905 submit/tizen/20160323.104541
authorKichan Kwon <k_c.kwon@samsung.com>
Wed, 23 Mar 2016 10:38:57 +0000 (19:38 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Wed, 23 Mar 2016 10:38:57 +0000 (19:38 +0900)
Change-Id: Ic0aed80868531e64a668469121da9c97e417753c
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/logutil/logutil.c

index 94c083e..7e4f3d6 100755 (executable)
@@ -427,7 +427,6 @@ int main_journal(int argc, char **argv)
        sd_journal *j;
 
        static const char pri_table[DLOG_PRIO_MAX] = {
-               [DLOG_VERBOSE] = 'V',
                [LOG_DEBUG] = 'D',
                [LOG_INFO] = 'I',
                [LOG_WARNING] = 'W',
@@ -437,7 +436,7 @@ int main_journal(int argc, char **argv)
 
        r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
        if (r < 0) {
-               fprintf(stderr, "Failed to open journal: %s\n", strerror(-r));
+               fprintf(stderr, "Failed to open journal (%d)\n", -r);
 
                return 1;
        }
@@ -446,11 +445,18 @@ int main_journal(int argc, char **argv)
        SD_JOURNAL_FOREACH(j) {
                const char *priority, *log_tag, *tid,  *message;
                size_t l;
+               int prio_idx;
 
                r = sd_journal_get_data(j, "PRIORITY", (const void **)&priority, &l);
                if (r < 0)
                        continue;
 
+               prio_idx = atoi(priority+9);
+               if (prio_idx < LOG_CRIT || prio_idx > LOG_DEBUG) {
+                       fprintf(stdout, "Wrong priority");
+                       continue;
+               }
+
                r = sd_journal_get_data(j, "LOG_TAG", (const void **)&log_tag, &l);
                if (r < 0)
                        continue;
@@ -463,13 +469,14 @@ int main_journal(int argc, char **argv)
                if (r < 0)
                        continue;
 
-               fprintf(stdout, "%c/%s(%5d): %s\n", pri_table[atoi(priority+9)], log_tag+8, atoi(tid+4), message+8);
+               fprintf(stdout, "%c/%s(%5d): %s\n", pri_table[prio_idx], log_tag+8, atoi(tid+4), message+8);
        }
 
        fprintf(stderr, "wait\n");
        for (;;) {
                const char *log_tag, *priority, *tid, *message;
                size_t l;
+               int prio_idx;
 
                if (sd_journal_seek_tail(j) < 0) {
                        fprintf(stderr, "Couldn't find journal");
@@ -478,6 +485,12 @@ int main_journal(int argc, char **argv)
                        if (r < 0)
                                continue;
 
+                       prio_idx = atoi(priority+9);
+                       if (prio_idx < LOG_CRIT || prio_idx > LOG_DEBUG) {
+                               fprintf(stdout, "Wrong priority");
+                               continue;
+                       }
+
                        r = sd_journal_get_data(j, "LOG_TAG", (const void **)&log_tag, &l);
                        if (r < 0)
                                continue;
@@ -490,7 +503,7 @@ int main_journal(int argc, char **argv)
                        if (r < 0)
                                continue;
 
-                       fprintf(stdout, "%c/%s(%5d): %s", pri_table[atoi(priority+9)], log_tag+8, atoi(tid+4), message+8);
+                       fprintf(stdout, "%c/%s(%5d): %s", pri_table[prio_idx], log_tag+8, atoi(tid+4), message+8);
                        fprintf(stdout, "\n");
 
                        r = sd_journal_wait(j, (uint64_t) -1);