From: Christian Brauner Date: Fri, 3 Sep 2021 09:41:25 +0000 (+0200) Subject: terminal: fix integer comparisons X-Git-Tag: lxc-5.0.0~92^2~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8703bf5bdbe6e13311e7cf33220211049343b3e9;p=thirdparty%2Flxc.git terminal: fix integer comparisons Signed-off-by: Christian Brauner --- diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c index 543e947bb..a1f974be0 100644 --- a/src/lxc/terminal.c +++ b/src/lxc/terminal.c @@ -270,7 +270,7 @@ static int lxc_terminal_write_log_file(struct lxc_terminal *terminal, char *buf, if (ret < 0) return ret; - if (bytes_read <= terminal->log_size) + if ((uint64_t)bytes_read <= terminal->log_size) return lxc_write_nointr(terminal->log_fd, buf, bytes_read); /* Write as much as we can into the buffer and loose the rest. */ @@ -301,7 +301,7 @@ static int lxc_terminal_write_log_file(struct lxc_terminal *terminal, char *buf, if (ret < 0) return ret; - if (terminal->log_size < bytes_read) { + if (terminal->log_size < (uint64_t)bytes_read) { /* Well, this is unfortunate because it means that there is more * to write than the user has granted us space. There are * multiple ways to handle this but let's use the simplest one: @@ -615,7 +615,7 @@ on_error: int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq) { - int ttynum; + size_t ttynum; int ptxfd = -1; struct lxc_tty_info *ttys = &conf->ttys; struct lxc_terminal *terminal = &conf->console; @@ -632,7 +632,7 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq) } if (*ttyreq > 0) { - if (*ttyreq > ttys->max) + if ((size_t)*ttyreq > ttys->max) goto out; if (ttys->tty[*ttyreq - 1].busy >= 0) @@ -652,7 +652,7 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq) if (ttynum > ttys->max) goto out; - *ttyreq = ttynum; + *ttyreq = (int)ttynum; out_tty: ttys->tty[ttynum - 1].busy = sockfd; @@ -664,11 +664,10 @@ out: void lxc_terminal_free(struct lxc_conf *conf, int fd) { - int i; struct lxc_tty_info *ttys = &conf->ttys; struct lxc_terminal *terminal = &conf->console; - for (i = 0; i < ttys->max; i++) + for (size_t i = 0; i < ttys->max; i++) if (ttys->tty[i].busy == fd) ttys->tty[i].busy = -1;