]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/log.c
Merge pull request #2987 from pacovn/Coverity_1473088_ovf_array_index_write
[mirror_frr.git] / lib / log.c
index 1345ff2fd1868718b343675a57f54fb913f6fef1..010b98478699ad082f67979c6702788a280cab58 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
@@ -28,6 +28,8 @@
 #include "log_int.h"
 #include "memory.h"
 #include "command.h"
+#include "lib_errors.h"
+
 #ifndef SUNOS_5
 #include <sys/un.h>
 #endif
@@ -631,7 +633,8 @@ void zlog_backtrace(int priority)
 
        size = backtrace(array, array_size(array));
        if (size <= 0 || (size_t)size > array_size(array)) {
-               zlog_err(
+               flog_err_sys(
+                       LIB_ERR_SYSTEM_CALL,
                        "Cannot get backtrace, returned invalid # of frames %d "
                        "(valid range is between 1 and %lu)",
                        size, (unsigned long)(array_size(array)));
@@ -639,7 +642,8 @@ void zlog_backtrace(int priority)
        }
        zlog(priority, "Backtrace for %d stack frames:", size);
        if (!(strings = backtrace_symbols(array, size))) {
-               zlog_err("Cannot get backtrace symbols (out of memory?)");
+               flog_err_sys(LIB_ERR_SYSTEM_CALL,
+                            "Cannot get backtrace symbols (out of memory?)");
                for (i = 0; i < size; i++)
                        zlog(priority, "[bt %d] %p", i, array[i]);
        } else {
@@ -712,10 +716,10 @@ void _zlog_assert_failed(const char *assertion, const char *file,
 
 void memory_oom(size_t size, const char *name)
 {
-       zlog_err(
-               "out of memory: failed to allocate %zu bytes for %s"
-               "object",
-               size, name);
+       flog_err_sys(LIB_ERR_SYSTEM_CALL,
+                    "out of memory: failed to allocate %zu bytes for %s"
+                    "object",
+                    size, name);
        zlog_backtrace(LOG_ERR);
        abort();
 }
@@ -864,10 +868,16 @@ int zlog_rotate(void)
                save_errno = errno;
                umask(oldumask);
                if (zl->fp == NULL) {
-                       zlog_err(
+
+                       pthread_mutex_unlock(&loglock);
+
+                       flog_err_sys(
+                               LIB_ERR_SYSTEM_CALL,
                                "Log rotate failed: cannot open file %s for append: %s",
                                zl->filename, safe_strerror(save_errno));
                        ret = -1;
+
+                       pthread_mutex_lock(&loglock);
                } else {
                        logfile_fd = fileno(zl->fp);
                        zl->maxlvl[ZLOG_DEST_FILE] = level;
@@ -898,10 +908,6 @@ static const struct zebra_desc_table command_types[] = {
        DESC_ENTRY(ZEBRA_ROUTE_ADD),
        DESC_ENTRY(ZEBRA_ROUTE_DELETE),
        DESC_ENTRY(ZEBRA_ROUTE_NOTIFY_OWNER),
-       DESC_ENTRY(ZEBRA_IPV4_ROUTE_ADD),
-       DESC_ENTRY(ZEBRA_IPV4_ROUTE_DELETE),
-       DESC_ENTRY(ZEBRA_IPV6_ROUTE_ADD),
-       DESC_ENTRY(ZEBRA_IPV6_ROUTE_DELETE),
        DESC_ENTRY(ZEBRA_REDISTRIBUTE_ADD),
        DESC_ENTRY(ZEBRA_REDISTRIBUTE_DELETE),
        DESC_ENTRY(ZEBRA_REDISTRIBUTE_DEFAULT_ADD),
@@ -919,7 +925,6 @@ static const struct zebra_desc_table command_types[] = {
        DESC_ENTRY(ZEBRA_IMPORT_ROUTE_REGISTER),
        DESC_ENTRY(ZEBRA_IMPORT_ROUTE_UNREGISTER),
        DESC_ENTRY(ZEBRA_IMPORT_CHECK_UPDATE),
-       DESC_ENTRY(ZEBRA_IPV4_ROUTE_IPV6_NEXTHOP_ADD),
        DESC_ENTRY(ZEBRA_BFD_DEST_REGISTER),
        DESC_ENTRY(ZEBRA_BFD_DEST_DEREGISTER),
        DESC_ENTRY(ZEBRA_BFD_DEST_UPDATE),
@@ -984,7 +989,8 @@ static const struct zebra_desc_table *zroute_lookup(unsigned int zroute)
        unsigned int i;
 
        if (zroute >= array_size(route_types)) {
-               zlog_err("unknown zebra route type: %u", zroute);
+               flog_err(LIB_ERR_DEVELOPMENT, "unknown zebra route type: %u",
+                         zroute);
                return &unknown;
        }
        if (zroute == route_types[zroute].type)
@@ -998,7 +1004,9 @@ static const struct zebra_desc_table *zroute_lookup(unsigned int zroute)
                        return &route_types[i];
                }
        }
-       zlog_err("internal error: cannot find route type %u in table!", zroute);
+       flog_err(LIB_ERR_DEVELOPMENT,
+                 "internal error: cannot find route type %u in table!",
+                 zroute);
        return &unknown;
 }
 
@@ -1015,7 +1023,8 @@ char zebra_route_char(unsigned int zroute)
 const char *zserv_command_string(unsigned int command)
 {
        if (command >= array_size(command_types)) {
-               zlog_err("unknown zserv command type: %u", command);
+               flog_err(LIB_ERR_DEVELOPMENT, "unknown zserv command type: %u",
+                         command);
                return unknown.string;
        }
        return command_types[command].string;