diff options
| author | Ben Kaduk <kaduk@mit.edu> | 2012-06-29 11:35:41 -0400 |
|---|---|---|
| committer | Ben Kaduk <kaduk@mit.edu> | 2012-07-03 00:43:45 -0400 |
| commit | ac94bfad7852075360852fa5602d9ff819b27cf0 (patch) | |
| tree | 9e557403424ad08d703fa26dd27cb2dd8a69580f /src | |
| parent | 9a586c7e0f4f54eb63c53fccb0988dda4c9bc6b8 (diff) | |
| download | krb5-ac94bfad7852075360852fa5602d9ff819b27cf0.tar.gz krb5-ac94bfad7852075360852fa5602d9ff819b27cf0.tar.xz krb5-ac94bfad7852075360852fa5602d9ff819b27cf0.zip | |
Take care with types in process_routing_update()
read(2) returns an ssize_t, not an int. We want to compare this
value against several unsigned size_ts, so make a local copy.
Also cast to int for printing; size_t can be wider than int, but
these values should be small.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/apputils/net-server.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/lib/apputils/net-server.c b/src/lib/apputils/net-server.c index 8b4af14295..0fd08eceea 100644 --- a/src/lib/apputils/net-server.c +++ b/src/lib/apputils/net-server.c @@ -1141,14 +1141,17 @@ routing_update_needed(struct rt_msghdr *rtm) static void process_routing_update(verto_ctx *ctx, verto_ev *ev) { - int n_read, fd; + int fd; + ssize_t n_read; + size_t sz_read; struct rt_msghdr rtm; struct connection *conn; fd = verto_get_fd(ev); conn = verto_get_private(ev); while ((n_read = read(fd, &rtm, sizeof(rtm))) > 0) { - if (n_read < sizeof(rtm)) { + sz_read = (size_t) n_read; /* Safe, since we just checked the sign */ + if (sz_read < sizeof(rtm)) { /* Quick hack to figure out if the interesting fields are present in a short read. @@ -1156,12 +1159,12 @@ process_routing_update(verto_ctx *ctx, verto_ev *ev) Only complain if we don't have the critical initial header fields. */ #define RS(FIELD) (offsetof(struct rt_msghdr, FIELD) + sizeof(rtm.FIELD)) - if (n_read < RS(rtm_type) || - n_read < RS(rtm_version) || - n_read < RS(rtm_msglen)) { + if (sz_read < RS(rtm_type) || + sz_read < RS(rtm_version) || + sz_read < RS(rtm_msglen)) { krb5_klog_syslog(LOG_ERR, _("short read (%d/%d) from routing socket"), - n_read, (int) sizeof(rtm)); + (int)sz_read, (int) sizeof(rtm)); return; } } @@ -1174,10 +1177,10 @@ process_routing_update(verto_ctx *ctx, verto_ev *ev) if (rtm.rtm_msglen > sizeof(rtm)) { /* It appears we get a partial message and the rest is thrown away? */ - } else if (rtm.rtm_msglen != n_read) { + } else if (rtm.rtm_msglen != sz_read) { krb5_klog_syslog(LOG_ERR, _("read %d from routing socket but msglen is %d"), - n_read, rtm.rtm_msglen); + (int)sz_read, rtm.rtm_msglen); } if (routing_update_needed(&rtm)) { |
