]> git.proxmox.com Git - mirror_frr.git/blobdiff - nhrpd/vici.c
nhrpd: fix issues found by coverity
[mirror_frr.git] / nhrpd / vici.c
index 18faca2d5a67f8e224a485c60a031403ad4db2c2..a6d835562f4be8e64b54402ffe9b39582ace7d91 100644 (file)
@@ -182,7 +182,8 @@ static void parse_sa_message(
                case 'l':
                        if (blob_equal(key, "local-host") && ctx->nsections == 1) {
                                if (blob2buf(val, buf, sizeof(buf)))
-                                       str2sockunion(buf, &sactx->local.host);
+                                       if (str2sockunion(buf, &sactx->local.host) < 0)
+                                               zlog_err("VICI: bad strongSwan local-host: %s", buf);
                        } else if (blob_equal(key, "local-id") && ctx->nsections == 1) {
                                sactx->local.id = *val;
                        } else if (blob_equal(key, "local-cert-data") && ctx->nsections == 1) {
@@ -192,7 +193,8 @@ static void parse_sa_message(
                case 'r':
                        if (blob_equal(key, "remote-host") && ctx->nsections == 1) {
                                if (blob2buf(val, buf, sizeof(buf)))
-                                       str2sockunion(buf, &sactx->remote.host);
+                                       if (str2sockunion(buf, &sactx->remote.host) < 0)
+                                               zlog_err("VICI: bad strongSwan remote-host: %s", buf);
                        } else if (blob_equal(key, "remote-id") && ctx->nsections == 1) {
                                sactx->remote.id = *val;
                        } else if (blob_equal(key, "remote-cert-data") && ctx->nsections == 1) {
@@ -261,6 +263,7 @@ static void vici_recv_message(struct vici_conn *vici, struct zbuf *msg)
        uint32_t msglen;
        uint8_t msgtype;
        struct blob name;
+       struct vici_message_ctx ctx;
 
        msglen = zbuf_get_be32(msg);
        msgtype = zbuf_get8(msg);
@@ -283,7 +286,7 @@ static void vici_recv_message(struct vici_conn *vici, struct zbuf *msg)
                        vici_recv_sa(vici, msg, 2);
                break;
        case VICI_CMD_RESPONSE:
-               vici_parse_message(vici, msg, parse_cmd_response, 0);
+               vici_parse_message(vici, msg, parse_cmd_response, &ctx);
                break;
        case VICI_EVENT_UNKNOWN:
        case VICI_CMD_UNKNOWN:
@@ -381,8 +384,6 @@ static void vici_submit_request(struct vici_conn *vici, const char *name, ...)
                        zbuf_put_be16(obuf, len);
                        zbuf_put(obuf, va_arg(va, void *), len);
                        break;
-               case VICI_END:
-                       break;
                default:
                        break;
                }
@@ -491,7 +492,7 @@ int sock_open_unix(const char *path)
 
        memset(&addr, 0, sizeof (struct sockaddr_un));
        addr.sun_family = AF_UNIX;
-       strncpy(addr.sun_path, path, strlen (path));
+       strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
 
        ret = connect(fd, (struct sockaddr *) &addr, sizeof(addr.sun_family) + strlen(addr.sun_path));
        if (ret < 0) {
@@ -499,7 +500,11 @@ int sock_open_unix(const char *path)
                return -1;
        }
 
-       fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
+       ret = fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
+       if (ret < 0) {
+               close(fd);
+               return -1;
+       }
 
        return fd;
 }