diff options
author | Russ White <russ@riw.us> | 2018-06-20 13:41:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-20 13:41:06 +0200 |
commit | 480f71f6a8cd0cd2ca40afd3c3a48f35ae3347f6 (patch) | |
tree | 9c204b6e07606bbc9dad5ef4f6ddcf097c283505 /bgpd | |
parent | Merge pull request #2495 from pacovn/fixme_all_digit (diff) | |
parent | bgpd: Untrusted argument (Coverity 1399380) (diff) | |
download | frr-480f71f6a8cd0cd2ca40afd3c3a48f35ae3347f6.tar.xz frr-480f71f6a8cd0cd2ca40afd3c3a48f35ae3347f6.zip |
Merge pull request #2461 from pacovn/Coverity_1399380_Untrusted_value_as_argument
bgpd: Untrusted argument (Coverity 1399380)
Diffstat (limited to 'bgpd')
-rw-r--r-- | bgpd/bgp_btoa.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/bgpd/bgp_btoa.c b/bgpd/bgp_btoa.c index bf2607f2e..cc37e352e 100644 --- a/bgpd/bgp_btoa.c +++ b/bgpd/bgp_btoa.c @@ -122,7 +122,7 @@ static int attr_parse(struct stream *s, uint16_t len) int main(int argc, char **argv) { int ret; - FILE *fp; + int fd; struct stream *s; time_t now; int type; @@ -143,8 +143,8 @@ int main(int argc, char **argv) fprintf(stderr, "Usage: %s FILENAME\n", argv[0]); exit(1); } - fp = fopen(argv[1], "r"); - if (!fp) { + fd = open(argv[1], O_RDONLY); + if (fd < 0) { fprintf(stdout, "%% Can't open configuration file %s due to '%s'.\n", argv[1], safe_strerror(errno)); @@ -154,13 +154,14 @@ int main(int argc, char **argv) while (1) { stream_reset(s); - ret = fread(s->data, 12, 1, fp); - if (!ret || feof(fp)) { - printf("END OF FILE\n"); - break; - } - if (ferror(fp)) { - printf("ERROR OF FREAD\n"); + ret = stream_read(s, fd, 12); + if (ret != 12) { + if (!ret) + printf("END OF FILE\n"); + else if (ret < 0) + printf("ERROR OF READ\n"); + else + printf("UNDERFLOW\n"); break; } @@ -217,13 +218,14 @@ int main(int argc, char **argv) printf("len: %zd\n", len); - fread(s->data + 12, len, 1, fp); - if (feof(fp)) { - printf("ENDOF FILE 2\n"); - break; - } - if (ferror(fp)) { - printf("ERROR OF FREAD 2\n"); + ret = stream_read(s, fd, len); + if (ret != (int)len) { + if (!ret) + printf("END OF FILE 2\n"); + else if (ret < 0) + printf("ERROR OF READ 2\n"); + else + printf("UNDERFLOW 2\n"); break; } @@ -284,6 +286,6 @@ int main(int argc, char **argv) printf("\n"); } } - fclose(fp); + close(fd); return 0; } |