diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2017-02-10 15:04:06 +0100 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2017-02-10 15:04:06 +0100 |
commit | 148781210fbcb1b26d5df678a400fa5dd8549e42 (patch) | |
tree | 78d57b0b68c54d029e47fdc834aacb0bc3815715 | |
parent | Merge pull request #192 from donaldsharp/snmp1 (diff) | |
download | frr-148781210fbcb1b26d5df678a400fa5dd8549e42.tar.xz frr-148781210fbcb1b26d5df678a400fa5dd8549e42.zip |
lib: fix remaining coverity issues
Reported-by: Coverity
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
-rw-r--r-- | lib/command.c | 9 | ||||
-rw-r--r-- | lib/csv.c | 6 | ||||
-rw-r--r-- | lib/grammar_sandbox.c | 16 | ||||
-rw-r--r-- | lib/mpls.h | 45 | ||||
-rw-r--r-- | lib/skiplist.c | 3 | ||||
-rw-r--r-- | lib/vty.c | 2 | ||||
-rw-r--r-- | lib/zclient.c | 5 |
7 files changed, 44 insertions, 42 deletions
diff --git a/lib/command.c b/lib/command.c index 4a8438685..d1e11f061 100644 --- a/lib/command.c +++ b/lib/command.c @@ -1450,7 +1450,8 @@ DEFUN (config_write, VTY_NEWLINE); goto finished; } - fsync (dirfd); + if (dirfd >= 0) + fsync (dirfd); } if (rename (config_file_tmp, config_file) != 0) { @@ -1458,7 +1459,8 @@ DEFUN (config_write, VTY_NEWLINE); goto finished; } - fsync (dirfd); + if (dirfd >= 0) + fsync (dirfd); vty_out (vty, "Configuration saved to %s%s", config_file, VTY_NEWLINE); @@ -1467,7 +1469,8 @@ DEFUN (config_write, finished: if (ret != CMD_SUCCESS) unlink (config_file_tmp); - close (dirfd); + if (dirfd >= 0) + close (dirfd); XFREE (MTYPE_TMP, config_file_tmp); XFREE (MTYPE_TMP, config_file_sav); return ret; @@ -177,8 +177,11 @@ csv_decode_record(csv_record_t *rec) field = strpbrk(curr, ","); } field = strstr(curr, "\n"); + if (!field) + return; + fld = malloc(sizeof(csv_field_t)); - if (field && fld) { + if (fld) { fld->field = curr; fld->field_len = field-curr; TAILQ_INSERT_TAIL(&(rec->fields), fld, next_field); @@ -420,6 +423,7 @@ csv_clone_record (csv_t *csv, csv_record_t *in_rec, csv_record_t **out_rec) curr = calloc(1, csv->buflen); if (!curr) { log_error("field str malloc failed\n"); + free(rec); return; } rec->record = curr; diff --git a/lib/grammar_sandbox.c b/lib/grammar_sandbox.c index 315bd4d59..08f012f8a 100644 --- a/lib/grammar_sandbox.c +++ b/lib/grammar_sandbox.c @@ -86,6 +86,11 @@ DEFUN (grammar_test_complete, return CMD_SUCCESS; vector command = cmd_make_strvec (cmdstr); + if (!command) + { + XFREE (MTYPE_TMP, cmdstr); + return CMD_SUCCESS; + } // generate completions of user input struct list *completions; @@ -121,7 +126,7 @@ DEFUN (grammar_test_complete, // free resources list_delete (completions); cmd_free_strvec (command); - free (cmdstr); + XFREE (MTYPE_TMP, cmdstr); return CMD_SUCCESS; } @@ -138,7 +143,14 @@ DEFUN (grammar_test_match, return CMD_SUCCESS; char *cmdstr = argv_concat(argv, argc, idx_command); + if (!cmdstr) + return CMD_SUCCESS; vector command = cmd_make_strvec (cmdstr); + if (!command) + { + XFREE (MTYPE_TMP, cmdstr); + return CMD_SUCCESS; + } struct list *argvv = NULL; const struct cmd_element *element = NULL; @@ -177,7 +189,7 @@ DEFUN (grammar_test_match, // free resources cmd_free_strvec (command); - free (cmdstr); + XFREE (MTYPE_TMP, cmdstr); return CMD_SUCCESS; } diff --git a/lib/mpls.h b/lib/mpls.h index 1f77aaa53..b5c1a653b 100644 --- a/lib/mpls.h +++ b/lib/mpls.h @@ -123,59 +123,40 @@ mpls_lse_decode (mpls_lse_t lse, mpls_label_t *label, /* Printable string for labels (with consideration for reserved values). */ static inline char * -label2str (mpls_label_t label, char *buf, int len) +label2str (mpls_label_t label, char *buf, size_t len) { switch(label) { case MPLS_V4_EXP_NULL_LABEL: - strncpy(buf, "IPv4 Explicit Null", len); + strlcpy(buf, "IPv4 Explicit Null", len); return(buf); - break; case MPLS_RA_LABEL: - strncpy(buf, "Router Alert", len); + strlcpy(buf, "Router Alert", len); return(buf); - break; case MPLS_V6_EXP_NULL_LABEL: - strncpy(buf, "IPv6 Explict Null", len); + strlcpy(buf, "IPv6 Explict Null", len); return(buf); - break; case MPLS_IMP_NULL_LABEL: - strncpy(buf, "implicit-null", len); + strlcpy(buf, "implicit-null", len); return(buf); - break; case MPLS_ENTROPY_LABEL_INDICATOR: - strncpy(buf, "Entropy Label Indicator", len); + strlcpy(buf, "Entropy Label Indicator", len); return(buf); - break; case MPLS_GAL_LABEL: - strncpy(buf, "Generic Associated Channel", len); + strlcpy(buf, "Generic Associated Channel", len); return(buf); - break; case MPLS_OAM_ALERT_LABEL: - strncpy(buf, "OAM Alert", len); + strlcpy(buf, "OAM Alert", len); return(buf); - break; case MPLS_EXTENSION_LABEL: - strncpy(buf, "Extension", len); + strlcpy(buf, "Extension", len); return(buf); - break; - case 4: - case 5: - case 6: - case 8: - case 9: - case 10: - case 11: - case 12: - strncpy(buf, "Reserved", len); - return(buf); - break; default: - sprintf(buf, "%u", label); + if (label < 16) + snprintf(buf, len, "Reserved (%u)", label); + else + snprintf(buf, len, "%u", label); return(buf); } - - strncpy(buf, "Error", len); - return(buf); } /* constants used by ldpd */ diff --git a/lib/skiplist.c b/lib/skiplist.c index 2a90b2c7c..05f489c90 100644 --- a/lib/skiplist.c +++ b/lib/skiplist.c @@ -439,7 +439,8 @@ skiplist_next_value( return -1; *valuePointer = q->value; - *cursor = q; + if (cursor) + *cursor = q; CHECKLAST(l); return 0; } @@ -1993,7 +1993,7 @@ vty_serv_un (const char *path) /* Make server socket. */ memset (&serv, 0, sizeof (struct sockaddr_un)); serv.sun_family = AF_UNIX; - strncpy (serv.sun_path, path, strlen (path)); + strlcpy (serv.sun_path, path, sizeof (serv.sun_path)); #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN len = serv.sun_len = SUN_LEN(&serv); #else diff --git a/lib/zclient.c b/lib/zclient.c index cea4b098f..859751deb 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -35,6 +35,7 @@ #include "nexthop.h" DEFINE_MTYPE_STATIC(LIB, ZCLIENT, "Zclient") +DEFINE_MTYPE_STATIC(LIB, REDIST_INST, "Redistribution instance IDs") /* Zebra client events. */ enum event {ZCLIENT_SCHEDULE, ZCLIENT_READ, ZCLIENT_CONNECT}; @@ -106,7 +107,7 @@ redist_add_instance (struct redist_proto *red, u_short instance) if (!red->instances) red->instances = list_new(); - in = calloc (1, sizeof(u_short)); + in = XMALLOC (MTYPE_REDIST_INST, sizeof(u_short)); *in = instance; listnode_add (red->instances, in); } @@ -121,7 +122,7 @@ redist_del_instance (struct redist_proto *red, u_short instance) return; listnode_delete(red->instances, id); - free (id); + XFREE (MTYPE_REDIST_INST, id); if (!red->instances->count) { red->enabled = 0; |