idx
int64
func_before
string
Vulnerability Classification
string
vul
int64
func_after
string
patch
string
CWE ID
string
lines_before
string
lines_after
string
6,100
static ssize_t handle_pwritev(FsContext *ctx, V9fsFidOpenState *fs, const struct iovec *iov, int iovcnt, off_t offset) { ssize_t ret; #ifdef CONFIG_PREADV ret = pwritev(fs->fd, iov, iovcnt, offset); #else int err = lseek(fs->fd, offset, SEEK_SET); if (err == -1) { return err; } else { ret = writev(fs->fd, iov, iovcnt); } #endif #ifdef CONFIG_SYNC_FILE_RANGE if (ret > 0 && ctx->export_flags & V9FS_IMMEDIATE_WRITEOUT) { /* * Initiate a writeback. This is not a data integrity sync. * We want to ensure that we don't leave dirty pages in the cache * after write when writeout=immediate is sepcified. */ sync_file_range(fs->fd, offset, ret, SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE); } #endif return ret; }
DoS
0
static ssize_t handle_pwritev(FsContext *ctx, V9fsFidOpenState *fs, const struct iovec *iov, int iovcnt, off_t offset) { ssize_t ret; #ifdef CONFIG_PREADV ret = pwritev(fs->fd, iov, iovcnt, offset); #else int err = lseek(fs->fd, offset, SEEK_SET); if (err == -1) { return err; } else { ret = writev(fs->fd, iov, iovcnt); } #endif #ifdef CONFIG_SYNC_FILE_RANGE if (ret > 0 && ctx->export_flags & V9FS_IMMEDIATE_WRITEOUT) { /* * Initiate a writeback. This is not a data integrity sync. * We want to ensure that we don't leave dirty pages in the cache * after write when writeout=immediate is sepcified. */ sync_file_range(fs->fd, offset, ret, SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE); } #endif return ret; }
@@ -649,6 +649,14 @@ out: return ret; } +static void handle_cleanup(FsContext *ctx) +{ + struct handle_data *data = ctx->private; + + close(data->mountfd); + g_free(data); +} + static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) { const char *sec_model = qemu_opt_get(opts, "security_model"); @@ -671,6 +679,7 @@ static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) FileOperations handle_ops = { .parse_opts = handle_parse_opts, .init = handle_init, + .cleanup = handle_cleanup, .lstat = handle_lstat, .readlink = handle_readlink, .close = handle_close,
CWE-400
null
null
6,101
static struct dirent *handle_readdir(FsContext *ctx, V9fsFidOpenState *fs) { return readdir(fs->dir.stream); }
DoS
0
static struct dirent *handle_readdir(FsContext *ctx, V9fsFidOpenState *fs) { return readdir(fs->dir.stream); }
@@ -649,6 +649,14 @@ out: return ret; } +static void handle_cleanup(FsContext *ctx) +{ + struct handle_data *data = ctx->private; + + close(data->mountfd); + g_free(data); +} + static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) { const char *sec_model = qemu_opt_get(opts, "security_model"); @@ -671,6 +679,7 @@ static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) FileOperations handle_ops = { .parse_opts = handle_parse_opts, .init = handle_init, + .cleanup = handle_cleanup, .lstat = handle_lstat, .readlink = handle_readlink, .close = handle_close,
CWE-400
null
null
6,102
static ssize_t handle_readlink(FsContext *fs_ctx, V9fsPath *fs_path, char *buf, size_t bufsz) { int fd, ret; struct handle_data *data = (struct handle_data *)fs_ctx->private; fd = open_by_handle(data->mountfd, fs_path->data, O_PATH); if (fd < 0) { return fd; } ret = readlinkat(fd, "", buf, bufsz); close(fd); return ret; }
DoS
0
static ssize_t handle_readlink(FsContext *fs_ctx, V9fsPath *fs_path, char *buf, size_t bufsz) { int fd, ret; struct handle_data *data = (struct handle_data *)fs_ctx->private; fd = open_by_handle(data->mountfd, fs_path->data, O_PATH); if (fd < 0) { return fd; } ret = readlinkat(fd, "", buf, bufsz); close(fd); return ret; }
@@ -649,6 +649,14 @@ out: return ret; } +static void handle_cleanup(FsContext *ctx) +{ + struct handle_data *data = ctx->private; + + close(data->mountfd); + g_free(data); +} + static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) { const char *sec_model = qemu_opt_get(opts, "security_model"); @@ -671,6 +679,7 @@ static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) FileOperations handle_ops = { .parse_opts = handle_parse_opts, .init = handle_init, + .cleanup = handle_cleanup, .lstat = handle_lstat, .readlink = handle_readlink, .close = handle_close,
CWE-400
null
null
6,103
static int handle_remove(FsContext *ctx, const char *path) { errno = EOPNOTSUPP; return -1; }
DoS
0
static int handle_remove(FsContext *ctx, const char *path) { errno = EOPNOTSUPP; return -1; }
@@ -649,6 +649,14 @@ out: return ret; } +static void handle_cleanup(FsContext *ctx) +{ + struct handle_data *data = ctx->private; + + close(data->mountfd); + g_free(data); +} + static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) { const char *sec_model = qemu_opt_get(opts, "security_model"); @@ -671,6 +679,7 @@ static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) FileOperations handle_ops = { .parse_opts = handle_parse_opts, .init = handle_init, + .cleanup = handle_cleanup, .lstat = handle_lstat, .readlink = handle_readlink, .close = handle_close,
CWE-400
null
null
6,104
static int handle_rename(FsContext *ctx, const char *oldpath, const char *newpath) { errno = EOPNOTSUPP; return -1; }
DoS
0
static int handle_rename(FsContext *ctx, const char *oldpath, const char *newpath) { errno = EOPNOTSUPP; return -1; }
@@ -649,6 +649,14 @@ out: return ret; } +static void handle_cleanup(FsContext *ctx) +{ + struct handle_data *data = ctx->private; + + close(data->mountfd); + g_free(data); +} + static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) { const char *sec_model = qemu_opt_get(opts, "security_model"); @@ -671,6 +679,7 @@ static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) FileOperations handle_ops = { .parse_opts = handle_parse_opts, .init = handle_init, + .cleanup = handle_cleanup, .lstat = handle_lstat, .readlink = handle_readlink, .close = handle_close,
CWE-400
null
null
6,105
static int handle_renameat(FsContext *ctx, V9fsPath *olddir, const char *old_name, V9fsPath *newdir, const char *new_name) { int olddirfd, newdirfd, ret; struct handle_data *data = (struct handle_data *)ctx->private; olddirfd = open_by_handle(data->mountfd, olddir->data, O_PATH); if (olddirfd < 0) { return olddirfd; } newdirfd = open_by_handle(data->mountfd, newdir->data, O_PATH); if (newdirfd < 0) { close(olddirfd); return newdirfd; } ret = renameat(olddirfd, old_name, newdirfd, new_name); close(newdirfd); close(olddirfd); return ret; }
DoS
0
static int handle_renameat(FsContext *ctx, V9fsPath *olddir, const char *old_name, V9fsPath *newdir, const char *new_name) { int olddirfd, newdirfd, ret; struct handle_data *data = (struct handle_data *)ctx->private; olddirfd = open_by_handle(data->mountfd, olddir->data, O_PATH); if (olddirfd < 0) { return olddirfd; } newdirfd = open_by_handle(data->mountfd, newdir->data, O_PATH); if (newdirfd < 0) { close(olddirfd); return newdirfd; } ret = renameat(olddirfd, old_name, newdirfd, new_name); close(newdirfd); close(olddirfd); return ret; }
@@ -649,6 +649,14 @@ out: return ret; } +static void handle_cleanup(FsContext *ctx) +{ + struct handle_data *data = ctx->private; + + close(data->mountfd); + g_free(data); +} + static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) { const char *sec_model = qemu_opt_get(opts, "security_model"); @@ -671,6 +679,7 @@ static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) FileOperations handle_ops = { .parse_opts = handle_parse_opts, .init = handle_init, + .cleanup = handle_cleanup, .lstat = handle_lstat, .readlink = handle_readlink, .close = handle_close,
CWE-400
null
null
6,106
static void handle_rewinddir(FsContext *ctx, V9fsFidOpenState *fs) { rewinddir(fs->dir.stream); }
DoS
0
static void handle_rewinddir(FsContext *ctx, V9fsFidOpenState *fs) { rewinddir(fs->dir.stream); }
@@ -649,6 +649,14 @@ out: return ret; } +static void handle_cleanup(FsContext *ctx) +{ + struct handle_data *data = ctx->private; + + close(data->mountfd); + g_free(data); +} + static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) { const char *sec_model = qemu_opt_get(opts, "security_model"); @@ -671,6 +679,7 @@ static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) FileOperations handle_ops = { .parse_opts = handle_parse_opts, .init = handle_init, + .cleanup = handle_cleanup, .lstat = handle_lstat, .readlink = handle_readlink, .close = handle_close,
CWE-400
null
null
6,107
static void handle_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off) { seekdir(fs->dir.stream, off); }
DoS
0
static void handle_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off) { seekdir(fs->dir.stream, off); }
@@ -649,6 +649,14 @@ out: return ret; } +static void handle_cleanup(FsContext *ctx) +{ + struct handle_data *data = ctx->private; + + close(data->mountfd); + g_free(data); +} + static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) { const char *sec_model = qemu_opt_get(opts, "security_model"); @@ -671,6 +679,7 @@ static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) FileOperations handle_ops = { .parse_opts = handle_parse_opts, .init = handle_init, + .cleanup = handle_cleanup, .lstat = handle_lstat, .readlink = handle_readlink, .close = handle_close,
CWE-400
null
null
6,108
static int handle_statfs(FsContext *ctx, V9fsPath *fs_path, struct statfs *stbuf) { int fd, ret; struct handle_data *data = (struct handle_data *)ctx->private; fd = open_by_handle(data->mountfd, fs_path->data, O_NONBLOCK); if (fd < 0) { return fd; } ret = fstatfs(fd, stbuf); close(fd); return ret; }
DoS
0
static int handle_statfs(FsContext *ctx, V9fsPath *fs_path, struct statfs *stbuf) { int fd, ret; struct handle_data *data = (struct handle_data *)ctx->private; fd = open_by_handle(data->mountfd, fs_path->data, O_NONBLOCK); if (fd < 0) { return fd; } ret = fstatfs(fd, stbuf); close(fd); return ret; }
@@ -649,6 +649,14 @@ out: return ret; } +static void handle_cleanup(FsContext *ctx) +{ + struct handle_data *data = ctx->private; + + close(data->mountfd); + g_free(data); +} + static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) { const char *sec_model = qemu_opt_get(opts, "security_model"); @@ -671,6 +679,7 @@ static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) FileOperations handle_ops = { .parse_opts = handle_parse_opts, .init = handle_init, + .cleanup = handle_cleanup, .lstat = handle_lstat, .readlink = handle_readlink, .close = handle_close,
CWE-400
null
null
6,109
static int handle_symlink(FsContext *fs_ctx, const char *oldpath, V9fsPath *dir_path, const char *name, FsCred *credp) { int fd, dirfd, ret; struct handle_data *data = (struct handle_data *)fs_ctx->private; dirfd = open_by_handle(data->mountfd, dir_path->data, O_PATH); if (dirfd < 0) { return dirfd; } ret = symlinkat(oldpath, dirfd, name); if (!ret) { fd = openat(dirfd, name, O_PATH | O_NOFOLLOW); if (fd < 0) { ret = fd; goto err_out; } ret = fchownat(fd, "", credp->fc_uid, credp->fc_gid, AT_EMPTY_PATH); close(fd); } err_out: close(dirfd); return ret; }
DoS
0
static int handle_symlink(FsContext *fs_ctx, const char *oldpath, V9fsPath *dir_path, const char *name, FsCred *credp) { int fd, dirfd, ret; struct handle_data *data = (struct handle_data *)fs_ctx->private; dirfd = open_by_handle(data->mountfd, dir_path->data, O_PATH); if (dirfd < 0) { return dirfd; } ret = symlinkat(oldpath, dirfd, name); if (!ret) { fd = openat(dirfd, name, O_PATH | O_NOFOLLOW); if (fd < 0) { ret = fd; goto err_out; } ret = fchownat(fd, "", credp->fc_uid, credp->fc_gid, AT_EMPTY_PATH); close(fd); } err_out: close(dirfd); return ret; }
@@ -649,6 +649,14 @@ out: return ret; } +static void handle_cleanup(FsContext *ctx) +{ + struct handle_data *data = ctx->private; + + close(data->mountfd); + g_free(data); +} + static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) { const char *sec_model = qemu_opt_get(opts, "security_model"); @@ -671,6 +679,7 @@ static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) FileOperations handle_ops = { .parse_opts = handle_parse_opts, .init = handle_init, + .cleanup = handle_cleanup, .lstat = handle_lstat, .readlink = handle_readlink, .close = handle_close,
CWE-400
null
null
6,110
static int handle_utimensat(FsContext *ctx, V9fsPath *fs_path, const struct timespec *buf) { int ret; #ifdef CONFIG_UTIMENSAT int fd; struct handle_data *data = (struct handle_data *)ctx->private; fd = open_by_handle(data->mountfd, fs_path->data, O_NONBLOCK); if (fd < 0) { return fd; } ret = futimens(fd, buf); close(fd); #else ret = -1; errno = ENOSYS; #endif return ret; }
DoS
0
static int handle_utimensat(FsContext *ctx, V9fsPath *fs_path, const struct timespec *buf) { int ret; #ifdef CONFIG_UTIMENSAT int fd; struct handle_data *data = (struct handle_data *)ctx->private; fd = open_by_handle(data->mountfd, fs_path->data, O_NONBLOCK); if (fd < 0) { return fd; } ret = futimens(fd, buf); close(fd); #else ret = -1; errno = ENOSYS; #endif return ret; }
@@ -649,6 +649,14 @@ out: return ret; } +static void handle_cleanup(FsContext *ctx) +{ + struct handle_data *data = ctx->private; + + close(data->mountfd); + g_free(data); +} + static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) { const char *sec_model = qemu_opt_get(opts, "security_model"); @@ -671,6 +679,7 @@ static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) FileOperations handle_ops = { .parse_opts = handle_parse_opts, .init = handle_init, + .cleanup = handle_cleanup, .lstat = handle_lstat, .readlink = handle_readlink, .close = handle_close,
CWE-400
null
null
6,111
static inline int name_to_handle(int dirfd, const char *name, struct file_handle *fh, int *mnt_id, int flags) { return name_to_handle_at(dirfd, name, fh, mnt_id, flags); }
DoS
0
static inline int name_to_handle(int dirfd, const char *name, struct file_handle *fh, int *mnt_id, int flags) { return name_to_handle_at(dirfd, name, fh, mnt_id, flags); }
@@ -649,6 +649,14 @@ out: return ret; } +static void handle_cleanup(FsContext *ctx) +{ + struct handle_data *data = ctx->private; + + close(data->mountfd); + g_free(data); +} + static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) { const char *sec_model = qemu_opt_get(opts, "security_model"); @@ -671,6 +679,7 @@ static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) FileOperations handle_ops = { .parse_opts = handle_parse_opts, .init = handle_init, + .cleanup = handle_cleanup, .lstat = handle_lstat, .readlink = handle_readlink, .close = handle_close,
CWE-400
null
null
6,112
static inline int open_by_handle(int mountfd, const char *fh, int flags) { return open_by_handle_at(mountfd, (struct file_handle *)fh, flags); }
DoS
0
static inline int open_by_handle(int mountfd, const char *fh, int flags) { return open_by_handle_at(mountfd, (struct file_handle *)fh, flags); }
@@ -649,6 +649,14 @@ out: return ret; } +static void handle_cleanup(FsContext *ctx) +{ + struct handle_data *data = ctx->private; + + close(data->mountfd); + g_free(data); +} + static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) { const char *sec_model = qemu_opt_get(opts, "security_model"); @@ -671,6 +679,7 @@ static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) FileOperations handle_ops = { .parse_opts = handle_parse_opts, .init = handle_init, + .cleanup = handle_cleanup, .lstat = handle_lstat, .readlink = handle_readlink, .close = handle_close,
CWE-400
null
null
6,113
static int dotl_to_open_flags(int flags) { int i; /* * We have same bits for P9_DOTL_READONLY, P9_DOTL_WRONLY * and P9_DOTL_NOACCESS */ int oflags = flags & O_ACCMODE; struct dotl_openflag_map dotl_oflag_map[] = { { P9_DOTL_CREATE, O_CREAT }, { P9_DOTL_EXCL, O_EXCL }, { P9_DOTL_NOCTTY , O_NOCTTY }, { P9_DOTL_TRUNC, O_TRUNC }, { P9_DOTL_APPEND, O_APPEND }, { P9_DOTL_NONBLOCK, O_NONBLOCK } , { P9_DOTL_DSYNC, O_DSYNC }, { P9_DOTL_FASYNC, FASYNC }, { P9_DOTL_DIRECT, O_DIRECT }, { P9_DOTL_LARGEFILE, O_LARGEFILE }, { P9_DOTL_DIRECTORY, O_DIRECTORY }, { P9_DOTL_NOFOLLOW, O_NOFOLLOW }, { P9_DOTL_NOATIME, O_NOATIME }, { P9_DOTL_SYNC, O_SYNC }, }; for (i = 0; i < ARRAY_SIZE(dotl_oflag_map); i++) { if (flags & dotl_oflag_map[i].dotl_flag) { oflags |= dotl_oflag_map[i].open_flag; } } return oflags; }
DoS
0
static int dotl_to_open_flags(int flags) { int i; /* * We have same bits for P9_DOTL_READONLY, P9_DOTL_WRONLY * and P9_DOTL_NOACCESS */ int oflags = flags & O_ACCMODE; struct dotl_openflag_map dotl_oflag_map[] = { { P9_DOTL_CREATE, O_CREAT }, { P9_DOTL_EXCL, O_EXCL }, { P9_DOTL_NOCTTY , O_NOCTTY }, { P9_DOTL_TRUNC, O_TRUNC }, { P9_DOTL_APPEND, O_APPEND }, { P9_DOTL_NONBLOCK, O_NONBLOCK } , { P9_DOTL_DSYNC, O_DSYNC }, { P9_DOTL_FASYNC, FASYNC }, { P9_DOTL_DIRECT, O_DIRECT }, { P9_DOTL_LARGEFILE, O_LARGEFILE }, { P9_DOTL_DIRECTORY, O_DIRECTORY }, { P9_DOTL_NOFOLLOW, O_NOFOLLOW }, { P9_DOTL_NOATIME, O_NOATIME }, { P9_DOTL_SYNC, O_SYNC }, }; for (i = 0; i < ARRAY_SIZE(dotl_oflag_map); i++) { if (flags & dotl_oflag_map[i].dotl_flag) { oflags |= dotl_oflag_map[i].open_flag; } } return oflags; }
@@ -3521,6 +3521,9 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { + if (s->ops->cleanup && s->ctx.private) { + s->ops->cleanup(&s->ctx); + } g_free(s->tag); g_free(s->ctx.fs_root); v9fs_path_free(&path); @@ -3530,6 +3533,9 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { + if (s->ops->cleanup) { + s->ops->cleanup(&s->ctx); + } g_free(s->tag); g_free(s->ctx.fs_root); }
CWE-400
null
null
6,114
ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...) { ssize_t ret; va_list ap; va_start(ap, fmt); ret = virtio_pdu_vmarshal(pdu, offset, fmt, ap); va_end(ap); return ret; }
DoS
0
ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...) { ssize_t ret; va_list ap; va_start(ap, fmt); ret = virtio_pdu_vmarshal(pdu, offset, fmt, ap); va_end(ap); return ret; }
@@ -3521,6 +3521,9 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { + if (s->ops->cleanup && s->ctx.private) { + s->ops->cleanup(&s->ctx); + } g_free(s->tag); g_free(s->ctx.fs_root); v9fs_path_free(&path); @@ -3530,6 +3533,9 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { + if (s->ops->cleanup) { + s->ops->cleanup(&s->ctx); + } g_free(s->tag); g_free(s->ctx.fs_root); }
CWE-400
null
null
6,115
static void pdu_push_and_notify(V9fsPDU *pdu) { virtio_9p_push_and_notify(pdu); }
DoS
0
static void pdu_push_and_notify(V9fsPDU *pdu) { virtio_9p_push_and_notify(pdu); }
@@ -3521,6 +3521,9 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { + if (s->ops->cleanup && s->ctx.private) { + s->ops->cleanup(&s->ctx); + } g_free(s->tag); g_free(s->ctx.fs_root); v9fs_path_free(&path); @@ -3530,6 +3533,9 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { + if (s->ops->cleanup) { + s->ops->cleanup(&s->ctx); + } g_free(s->tag); g_free(s->ctx.fs_root); }
CWE-400
null
null
6,116
void pdu_submit(V9fsPDU *pdu) { Coroutine *co; CoroutineEntry *handler; V9fsState *s = pdu->s; if (pdu->id >= ARRAY_SIZE(pdu_co_handlers) || (pdu_co_handlers[pdu->id] == NULL)) { handler = v9fs_op_not_supp; } else { handler = pdu_co_handlers[pdu->id]; } if (is_ro_export(&s->ctx) && !is_read_only_op(pdu)) { handler = v9fs_fs_ro; } co = qemu_coroutine_create(handler, pdu); qemu_coroutine_enter(co); }
DoS
0
void pdu_submit(V9fsPDU *pdu) { Coroutine *co; CoroutineEntry *handler; V9fsState *s = pdu->s; if (pdu->id >= ARRAY_SIZE(pdu_co_handlers) || (pdu_co_handlers[pdu->id] == NULL)) { handler = v9fs_op_not_supp; } else { handler = pdu_co_handlers[pdu->id]; } if (is_ro_export(&s->ctx) && !is_read_only_op(pdu)) { handler = v9fs_fs_ro; } co = qemu_coroutine_create(handler, pdu); qemu_coroutine_enter(co); }
@@ -3521,6 +3521,9 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { + if (s->ops->cleanup && s->ctx.private) { + s->ops->cleanup(&s->ctx); + } g_free(s->tag); g_free(s->ctx.fs_root); v9fs_path_free(&path); @@ -3530,6 +3533,9 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { + if (s->ops->cleanup) { + s->ops->cleanup(&s->ctx); + } g_free(s->tag); g_free(s->ctx.fs_root); }
CWE-400
null
null
6,117
ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...) { ssize_t ret; va_list ap; va_start(ap, fmt); ret = virtio_pdu_vunmarshal(pdu, offset, fmt, ap); va_end(ap); return ret; }
DoS
0
ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...) { ssize_t ret; va_list ap; va_start(ap, fmt); ret = virtio_pdu_vunmarshal(pdu, offset, fmt, ap); va_end(ap); return ret; }
@@ -3521,6 +3521,9 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { + if (s->ops->cleanup && s->ctx.private) { + s->ops->cleanup(&s->ctx); + } g_free(s->tag); g_free(s->ctx.fs_root); v9fs_path_free(&path); @@ -3530,6 +3533,9 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { + if (s->ops->cleanup) { + s->ops->cleanup(&s->ctx); + } g_free(s->tag); g_free(s->ctx.fs_root); }
CWE-400
null
null
6,118
static int coroutine_fn v9fs_complete_rename(V9fsPDU *pdu, V9fsFidState *fidp, int32_t newdirfid, V9fsString *name) { char *end; int err = 0; V9fsPath new_path; V9fsFidState *tfidp; V9fsState *s = pdu->s; V9fsFidState *dirfidp = NULL; char *old_name, *new_name; v9fs_path_init(&new_path); if (newdirfid != -1) { dirfidp = get_fid(pdu, newdirfid); if (dirfidp == NULL) { err = -ENOENT; goto out_nofid; } if (fidp->fid_type != P9_FID_NONE) { err = -EINVAL; goto out; } v9fs_co_name_to_path(pdu, &dirfidp->path, name->data, &new_path); } else { old_name = fidp->path.data; end = strrchr(old_name, '/'); if (end) { end++; } else { end = old_name; } new_name = g_malloc0(end - old_name + name->size + 1); strncat(new_name, old_name, end - old_name); strncat(new_name + (end - old_name), name->data, name->size); v9fs_co_name_to_path(pdu, NULL, new_name, &new_path); g_free(new_name); } err = v9fs_co_rename(pdu, &fidp->path, &new_path); if (err < 0) { goto out; } /* * Fixup fid's pointing to the old name to * start pointing to the new name */ for (tfidp = s->fid_list; tfidp; tfidp = tfidp->next) { if (v9fs_path_is_ancestor(&fidp->path, &tfidp->path)) { /* replace the name */ v9fs_fix_path(&tfidp->path, &new_path, strlen(fidp->path.data)); } } out: if (dirfidp) { put_fid(pdu, dirfidp); } v9fs_path_free(&new_path); out_nofid: return err; }
DoS
0
static int coroutine_fn v9fs_complete_rename(V9fsPDU *pdu, V9fsFidState *fidp, int32_t newdirfid, V9fsString *name) { char *end; int err = 0; V9fsPath new_path; V9fsFidState *tfidp; V9fsState *s = pdu->s; V9fsFidState *dirfidp = NULL; char *old_name, *new_name; v9fs_path_init(&new_path); if (newdirfid != -1) { dirfidp = get_fid(pdu, newdirfid); if (dirfidp == NULL) { err = -ENOENT; goto out_nofid; } if (fidp->fid_type != P9_FID_NONE) { err = -EINVAL; goto out; } v9fs_co_name_to_path(pdu, &dirfidp->path, name->data, &new_path); } else { old_name = fidp->path.data; end = strrchr(old_name, '/'); if (end) { end++; } else { end = old_name; } new_name = g_malloc0(end - old_name + name->size + 1); strncat(new_name, old_name, end - old_name); strncat(new_name + (end - old_name), name->data, name->size); v9fs_co_name_to_path(pdu, NULL, new_name, &new_path); g_free(new_name); } err = v9fs_co_rename(pdu, &fidp->path, &new_path); if (err < 0) { goto out; } /* * Fixup fid's pointing to the old name to * start pointing to the new name */ for (tfidp = s->fid_list; tfidp; tfidp = tfidp->next) { if (v9fs_path_is_ancestor(&fidp->path, &tfidp->path)) { /* replace the name */ v9fs_fix_path(&tfidp->path, &new_path, strlen(fidp->path.data)); } } out: if (dirfidp) { put_fid(pdu, dirfidp); } v9fs_path_free(&new_path); out_nofid: return err; }
@@ -3521,6 +3521,9 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { + if (s->ops->cleanup && s->ctx.private) { + s->ops->cleanup(&s->ctx); + } g_free(s->tag); g_free(s->ctx.fs_root); v9fs_path_free(&path); @@ -3530,6 +3533,9 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { + if (s->ops->cleanup) { + s->ops->cleanup(&s->ctx); + } g_free(s->tag); g_free(s->ctx.fs_root); }
CWE-400
null
null
6,119
static int coroutine_fn v9fs_complete_renameat(V9fsPDU *pdu, int32_t olddirfid, V9fsString *old_name, int32_t newdirfid, V9fsString *new_name) { int err = 0; V9fsState *s = pdu->s; V9fsFidState *newdirfidp = NULL, *olddirfidp = NULL; olddirfidp = get_fid(pdu, olddirfid); if (olddirfidp == NULL) { err = -ENOENT; goto out; } if (newdirfid != -1) { newdirfidp = get_fid(pdu, newdirfid); if (newdirfidp == NULL) { err = -ENOENT; goto out; } } else { newdirfidp = get_fid(pdu, olddirfid); } err = v9fs_co_renameat(pdu, &olddirfidp->path, old_name, &newdirfidp->path, new_name); if (err < 0) { goto out; } if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) { /* Only for path based fid we need to do the below fixup */ v9fs_fix_fid_paths(pdu, &olddirfidp->path, old_name, &newdirfidp->path, new_name); } out: if (olddirfidp) { put_fid(pdu, olddirfidp); } if (newdirfidp) { put_fid(pdu, newdirfidp); } return err; }
DoS
0
static int coroutine_fn v9fs_complete_renameat(V9fsPDU *pdu, int32_t olddirfid, V9fsString *old_name, int32_t newdirfid, V9fsString *new_name) { int err = 0; V9fsState *s = pdu->s; V9fsFidState *newdirfidp = NULL, *olddirfidp = NULL; olddirfidp = get_fid(pdu, olddirfid); if (olddirfidp == NULL) { err = -ENOENT; goto out; } if (newdirfid != -1) { newdirfidp = get_fid(pdu, newdirfid); if (newdirfidp == NULL) { err = -ENOENT; goto out; } } else { newdirfidp = get_fid(pdu, olddirfid); } err = v9fs_co_renameat(pdu, &olddirfidp->path, old_name, &newdirfidp->path, new_name); if (err < 0) { goto out; } if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) { /* Only for path based fid we need to do the below fixup */ v9fs_fix_fid_paths(pdu, &olddirfidp->path, old_name, &newdirfidp->path, new_name); } out: if (olddirfidp) { put_fid(pdu, olddirfidp); } if (newdirfidp) { put_fid(pdu, newdirfidp); } return err; }
@@ -3521,6 +3521,9 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { + if (s->ops->cleanup && s->ctx.private) { + s->ops->cleanup(&s->ctx); + } g_free(s->tag); g_free(s->ctx.fs_root); v9fs_path_free(&path); @@ -3530,6 +3533,9 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { + if (s->ops->cleanup) { + s->ops->cleanup(&s->ctx); + } g_free(s->tag); g_free(s->ctx.fs_root); }
CWE-400
null
null
6,120
static void coroutine_fn v9fs_create(void *opaque) { int32_t fid; int err = 0; size_t offset = 7; V9fsFidState *fidp; V9fsQID qid; int32_t perm; int8_t mode; V9fsPath path; struct stat stbuf; V9fsString name; V9fsString extension; int iounit; V9fsPDU *pdu = opaque; v9fs_path_init(&path); v9fs_string_init(&name); v9fs_string_init(&extension); err = pdu_unmarshal(pdu, offset, "dsdbs", &fid, &name, &perm, &mode, &extension); if (err < 0) { goto out_nofid; } trace_v9fs_create(pdu->tag, pdu->id, fid, name.data, perm, mode); if (name_is_illegal(name.data)) { err = -ENOENT; goto out_nofid; } if (!strcmp(".", name.data) || !strcmp("..", name.data)) { err = -EEXIST; goto out_nofid; } fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -EINVAL; goto out_nofid; } if (perm & P9_STAT_MODE_DIR) { err = v9fs_co_mkdir(pdu, fidp, &name, perm & 0777, fidp->uid, -1, &stbuf); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { goto out; } v9fs_path_copy(&fidp->path, &path); err = v9fs_co_opendir(pdu, fidp); if (err < 0) { goto out; } fidp->fid_type = P9_FID_DIR; } else if (perm & P9_STAT_MODE_SYMLINK) { err = v9fs_co_symlink(pdu, fidp, &name, extension.data, -1 , &stbuf); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { goto out; } v9fs_path_copy(&fidp->path, &path); } else if (perm & P9_STAT_MODE_LINK) { int32_t ofid = atoi(extension.data); V9fsFidState *ofidp = get_fid(pdu, ofid); if (ofidp == NULL) { err = -EINVAL; goto out; } err = v9fs_co_link(pdu, ofidp, fidp, &name); put_fid(pdu, ofidp); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { fidp->fid_type = P9_FID_NONE; goto out; } v9fs_path_copy(&fidp->path, &path); err = v9fs_co_lstat(pdu, &fidp->path, &stbuf); if (err < 0) { fidp->fid_type = P9_FID_NONE; goto out; } } else if (perm & P9_STAT_MODE_DEVICE) { char ctype; uint32_t major, minor; mode_t nmode = 0; if (sscanf(extension.data, "%c %u %u", &ctype, &major, &minor) != 3) { err = -errno; goto out; } switch (ctype) { case 'c': nmode = S_IFCHR; break; case 'b': nmode = S_IFBLK; break; default: err = -EIO; goto out; } nmode |= perm & 0777; err = v9fs_co_mknod(pdu, fidp, &name, fidp->uid, -1, makedev(major, minor), nmode, &stbuf); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { goto out; } v9fs_path_copy(&fidp->path, &path); } else if (perm & P9_STAT_MODE_NAMED_PIPE) { err = v9fs_co_mknod(pdu, fidp, &name, fidp->uid, -1, 0, S_IFIFO | (perm & 0777), &stbuf); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { goto out; } v9fs_path_copy(&fidp->path, &path); } else if (perm & P9_STAT_MODE_SOCKET) { err = v9fs_co_mknod(pdu, fidp, &name, fidp->uid, -1, 0, S_IFSOCK | (perm & 0777), &stbuf); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { goto out; } v9fs_path_copy(&fidp->path, &path); } else { err = v9fs_co_open2(pdu, fidp, &name, -1, omode_to_uflags(mode)|O_CREAT, perm, &stbuf); if (err < 0) { goto out; } fidp->fid_type = P9_FID_FILE; fidp->open_flags = omode_to_uflags(mode); if (fidp->open_flags & O_EXCL) { /* * We let the host file system do O_EXCL check * We should not reclaim such fd */ fidp->flags |= FID_NON_RECLAIMABLE; } } iounit = get_iounit(pdu, &fidp->path); stat_to_qid(&stbuf, &qid); err = pdu_marshal(pdu, offset, "Qd", &qid, iounit); if (err < 0) { goto out; } err += offset; trace_v9fs_create_return(pdu->tag, pdu->id, qid.type, qid.version, qid.path, iounit); out: put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); v9fs_string_free(&name); v9fs_string_free(&extension); v9fs_path_free(&path); }
DoS
0
static void coroutine_fn v9fs_create(void *opaque) { int32_t fid; int err = 0; size_t offset = 7; V9fsFidState *fidp; V9fsQID qid; int32_t perm; int8_t mode; V9fsPath path; struct stat stbuf; V9fsString name; V9fsString extension; int iounit; V9fsPDU *pdu = opaque; v9fs_path_init(&path); v9fs_string_init(&name); v9fs_string_init(&extension); err = pdu_unmarshal(pdu, offset, "dsdbs", &fid, &name, &perm, &mode, &extension); if (err < 0) { goto out_nofid; } trace_v9fs_create(pdu->tag, pdu->id, fid, name.data, perm, mode); if (name_is_illegal(name.data)) { err = -ENOENT; goto out_nofid; } if (!strcmp(".", name.data) || !strcmp("..", name.data)) { err = -EEXIST; goto out_nofid; } fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -EINVAL; goto out_nofid; } if (perm & P9_STAT_MODE_DIR) { err = v9fs_co_mkdir(pdu, fidp, &name, perm & 0777, fidp->uid, -1, &stbuf); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { goto out; } v9fs_path_copy(&fidp->path, &path); err = v9fs_co_opendir(pdu, fidp); if (err < 0) { goto out; } fidp->fid_type = P9_FID_DIR; } else if (perm & P9_STAT_MODE_SYMLINK) { err = v9fs_co_symlink(pdu, fidp, &name, extension.data, -1 , &stbuf); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { goto out; } v9fs_path_copy(&fidp->path, &path); } else if (perm & P9_STAT_MODE_LINK) { int32_t ofid = atoi(extension.data); V9fsFidState *ofidp = get_fid(pdu, ofid); if (ofidp == NULL) { err = -EINVAL; goto out; } err = v9fs_co_link(pdu, ofidp, fidp, &name); put_fid(pdu, ofidp); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { fidp->fid_type = P9_FID_NONE; goto out; } v9fs_path_copy(&fidp->path, &path); err = v9fs_co_lstat(pdu, &fidp->path, &stbuf); if (err < 0) { fidp->fid_type = P9_FID_NONE; goto out; } } else if (perm & P9_STAT_MODE_DEVICE) { char ctype; uint32_t major, minor; mode_t nmode = 0; if (sscanf(extension.data, "%c %u %u", &ctype, &major, &minor) != 3) { err = -errno; goto out; } switch (ctype) { case 'c': nmode = S_IFCHR; break; case 'b': nmode = S_IFBLK; break; default: err = -EIO; goto out; } nmode |= perm & 0777; err = v9fs_co_mknod(pdu, fidp, &name, fidp->uid, -1, makedev(major, minor), nmode, &stbuf); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { goto out; } v9fs_path_copy(&fidp->path, &path); } else if (perm & P9_STAT_MODE_NAMED_PIPE) { err = v9fs_co_mknod(pdu, fidp, &name, fidp->uid, -1, 0, S_IFIFO | (perm & 0777), &stbuf); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { goto out; } v9fs_path_copy(&fidp->path, &path); } else if (perm & P9_STAT_MODE_SOCKET) { err = v9fs_co_mknod(pdu, fidp, &name, fidp->uid, -1, 0, S_IFSOCK | (perm & 0777), &stbuf); if (err < 0) { goto out; } err = v9fs_co_name_to_path(pdu, &fidp->path, name.data, &path); if (err < 0) { goto out; } v9fs_path_copy(&fidp->path, &path); } else { err = v9fs_co_open2(pdu, fidp, &name, -1, omode_to_uflags(mode)|O_CREAT, perm, &stbuf); if (err < 0) { goto out; } fidp->fid_type = P9_FID_FILE; fidp->open_flags = omode_to_uflags(mode); if (fidp->open_flags & O_EXCL) { /* * We let the host file system do O_EXCL check * We should not reclaim such fd */ fidp->flags |= FID_NON_RECLAIMABLE; } } iounit = get_iounit(pdu, &fidp->path); stat_to_qid(&stbuf, &qid); err = pdu_marshal(pdu, offset, "Qd", &qid, iounit); if (err < 0) { goto out; } err += offset; trace_v9fs_create_return(pdu->tag, pdu->id, qid.type, qid.version, qid.path, iounit); out: put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); v9fs_string_free(&name); v9fs_string_free(&extension); v9fs_path_free(&path); }
@@ -3521,6 +3521,9 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { + if (s->ops->cleanup && s->ctx.private) { + s->ops->cleanup(&s->ctx); + } g_free(s->tag); g_free(s->ctx.fs_root); v9fs_path_free(&path); @@ -3530,6 +3533,9 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { + if (s->ops->cleanup) { + s->ops->cleanup(&s->ctx); + } g_free(s->tag); g_free(s->ctx.fs_root); }
CWE-400
null
null
6,121
static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu, V9fsFidState *fidp, uint32_t max_count) { V9fsPath path; V9fsStat v9stat; int len, err = 0; int32_t count = 0; struct stat stbuf; off_t saved_dir_pos; struct dirent *dent; /* save the directory position */ saved_dir_pos = v9fs_co_telldir(pdu, fidp); if (saved_dir_pos < 0) { return saved_dir_pos; } while (1) { v9fs_path_init(&path); v9fs_readdir_lock(&fidp->fs.dir); err = v9fs_co_readdir(pdu, fidp, &dent); if (err || !dent) { break; } err = v9fs_co_name_to_path(pdu, &fidp->path, dent->d_name, &path); if (err < 0) { break; } err = v9fs_co_lstat(pdu, &path, &stbuf); if (err < 0) { break; } err = stat_to_v9stat(pdu, &path, &stbuf, &v9stat); if (err < 0) { break; } /* 11 = 7 + 4 (7 = start offset, 4 = space for storing count) */ len = pdu_marshal(pdu, 11 + count, "S", &v9stat); v9fs_readdir_unlock(&fidp->fs.dir); if ((len != (v9stat.size + 2)) || ((count + len) > max_count)) { /* Ran out of buffer. Set dir back to old position and return */ v9fs_co_seekdir(pdu, fidp, saved_dir_pos); v9fs_stat_free(&v9stat); v9fs_path_free(&path); return count; } count += len; v9fs_stat_free(&v9stat); v9fs_path_free(&path); saved_dir_pos = dent->d_off; } v9fs_readdir_unlock(&fidp->fs.dir); v9fs_path_free(&path); if (err < 0) { return err; } return count; }
DoS
0
static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu, V9fsFidState *fidp, uint32_t max_count) { V9fsPath path; V9fsStat v9stat; int len, err = 0; int32_t count = 0; struct stat stbuf; off_t saved_dir_pos; struct dirent *dent; /* save the directory position */ saved_dir_pos = v9fs_co_telldir(pdu, fidp); if (saved_dir_pos < 0) { return saved_dir_pos; } while (1) { v9fs_path_init(&path); v9fs_readdir_lock(&fidp->fs.dir); err = v9fs_co_readdir(pdu, fidp, &dent); if (err || !dent) { break; } err = v9fs_co_name_to_path(pdu, &fidp->path, dent->d_name, &path); if (err < 0) { break; } err = v9fs_co_lstat(pdu, &path, &stbuf); if (err < 0) { break; } err = stat_to_v9stat(pdu, &path, &stbuf, &v9stat); if (err < 0) { break; } /* 11 = 7 + 4 (7 = start offset, 4 = space for storing count) */ len = pdu_marshal(pdu, 11 + count, "S", &v9stat); v9fs_readdir_unlock(&fidp->fs.dir); if ((len != (v9stat.size + 2)) || ((count + len) > max_count)) { /* Ran out of buffer. Set dir back to old position and return */ v9fs_co_seekdir(pdu, fidp, saved_dir_pos); v9fs_stat_free(&v9stat); v9fs_path_free(&path); return count; } count += len; v9fs_stat_free(&v9stat); v9fs_path_free(&path); saved_dir_pos = dent->d_off; } v9fs_readdir_unlock(&fidp->fs.dir); v9fs_path_free(&path); if (err < 0) { return err; } return count; }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,122
static int v9fs_fill_statfs(V9fsState *s, V9fsPDU *pdu, struct statfs *stbuf) { uint32_t f_type; uint32_t f_bsize; uint64_t f_blocks; uint64_t f_bfree; uint64_t f_bavail; uint64_t f_files; uint64_t f_ffree; uint64_t fsid_val; uint32_t f_namelen; size_t offset = 7; int32_t bsize_factor; /* * compute bsize factor based on host file system block size * and client msize */ bsize_factor = (s->msize - P9_IOHDRSZ)/stbuf->f_bsize; if (!bsize_factor) { bsize_factor = 1; } f_type = stbuf->f_type; f_bsize = stbuf->f_bsize; f_bsize *= bsize_factor; /* * f_bsize is adjusted(multiplied) by bsize factor, so we need to * adjust(divide) the number of blocks, free blocks and available * blocks by bsize factor */ f_blocks = stbuf->f_blocks/bsize_factor; f_bfree = stbuf->f_bfree/bsize_factor; f_bavail = stbuf->f_bavail/bsize_factor; f_files = stbuf->f_files; f_ffree = stbuf->f_ffree; fsid_val = (unsigned int) stbuf->f_fsid.__val[0] | (unsigned long long)stbuf->f_fsid.__val[1] << 32; f_namelen = stbuf->f_namelen; return pdu_marshal(pdu, offset, "ddqqqqqqd", f_type, f_bsize, f_blocks, f_bfree, f_bavail, f_files, f_ffree, fsid_val, f_namelen); }
DoS
0
static int v9fs_fill_statfs(V9fsState *s, V9fsPDU *pdu, struct statfs *stbuf) { uint32_t f_type; uint32_t f_bsize; uint64_t f_blocks; uint64_t f_bfree; uint64_t f_bavail; uint64_t f_files; uint64_t f_ffree; uint64_t fsid_val; uint32_t f_namelen; size_t offset = 7; int32_t bsize_factor; /* * compute bsize factor based on host file system block size * and client msize */ bsize_factor = (s->msize - P9_IOHDRSZ)/stbuf->f_bsize; if (!bsize_factor) { bsize_factor = 1; } f_type = stbuf->f_type; f_bsize = stbuf->f_bsize; f_bsize *= bsize_factor; /* * f_bsize is adjusted(multiplied) by bsize factor, so we need to * adjust(divide) the number of blocks, free blocks and available * blocks by bsize factor */ f_blocks = stbuf->f_blocks/bsize_factor; f_bfree = stbuf->f_bfree/bsize_factor; f_bavail = stbuf->f_bavail/bsize_factor; f_files = stbuf->f_files; f_ffree = stbuf->f_ffree; fsid_val = (unsigned int) stbuf->f_fsid.__val[0] | (unsigned long long)stbuf->f_fsid.__val[1] << 32; f_namelen = stbuf->f_namelen; return pdu_marshal(pdu, offset, "ddqqqqqqd", f_type, f_bsize, f_blocks, f_bfree, f_bavail, f_files, f_ffree, fsid_val, f_namelen); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,123
static void coroutine_fn v9fs_fix_fid_paths(V9fsPDU *pdu, V9fsPath *olddir, V9fsString *old_name, V9fsPath *newdir, V9fsString *new_name) { V9fsFidState *tfidp; V9fsPath oldpath, newpath; V9fsState *s = pdu->s; v9fs_path_init(&oldpath); v9fs_path_init(&newpath); v9fs_co_name_to_path(pdu, olddir, old_name->data, &oldpath); v9fs_co_name_to_path(pdu, newdir, new_name->data, &newpath); /* * Fixup fid's pointing to the old name to * start pointing to the new name */ for (tfidp = s->fid_list; tfidp; tfidp = tfidp->next) { if (v9fs_path_is_ancestor(&oldpath, &tfidp->path)) { /* replace the name */ v9fs_fix_path(&tfidp->path, &newpath, strlen(oldpath.data)); } } v9fs_path_free(&oldpath); v9fs_path_free(&newpath); }
DoS
0
static void coroutine_fn v9fs_fix_fid_paths(V9fsPDU *pdu, V9fsPath *olddir, V9fsString *old_name, V9fsPath *newdir, V9fsString *new_name) { V9fsFidState *tfidp; V9fsPath oldpath, newpath; V9fsState *s = pdu->s; v9fs_path_init(&oldpath); v9fs_path_init(&newpath); v9fs_co_name_to_path(pdu, olddir, old_name->data, &oldpath); v9fs_co_name_to_path(pdu, newdir, new_name->data, &newpath); /* * Fixup fid's pointing to the old name to * start pointing to the new name */ for (tfidp = s->fid_list; tfidp; tfidp = tfidp->next) { if (v9fs_path_is_ancestor(&oldpath, &tfidp->path)) { /* replace the name */ v9fs_fix_path(&tfidp->path, &newpath, strlen(oldpath.data)); } } v9fs_path_free(&oldpath); v9fs_path_free(&newpath); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,124
static void v9fs_flush(void *opaque) { ssize_t err; int16_t tag; size_t offset = 7; V9fsPDU *cancel_pdu; V9fsPDU *pdu = opaque; V9fsState *s = pdu->s; err = pdu_unmarshal(pdu, offset, "w", &tag); if (err < 0) { pdu_complete(pdu, err); return; } trace_v9fs_flush(pdu->tag, pdu->id, tag); QLIST_FOREACH(cancel_pdu, &s->active_list, next) { if (cancel_pdu->tag == tag) { break; } } if (cancel_pdu) { cancel_pdu->cancelled = 1; /* * Wait for pdu to complete. */ qemu_co_queue_wait(&cancel_pdu->complete); cancel_pdu->cancelled = 0; pdu_free(cancel_pdu); } pdu_complete(pdu, 7); }
DoS
0
static void v9fs_flush(void *opaque) { ssize_t err; int16_t tag; size_t offset = 7; V9fsPDU *cancel_pdu; V9fsPDU *pdu = opaque; V9fsState *s = pdu->s; err = pdu_unmarshal(pdu, offset, "w", &tag); if (err < 0) { pdu_complete(pdu, err); return; } trace_v9fs_flush(pdu->tag, pdu->id, tag); QLIST_FOREACH(cancel_pdu, &s->active_list, next) { if (cancel_pdu->tag == tag) { break; } } if (cancel_pdu) { cancel_pdu->cancelled = 1; /* * Wait for pdu to complete. */ qemu_co_queue_wait(&cancel_pdu->complete); cancel_pdu->cancelled = 0; pdu_free(cancel_pdu); } pdu_complete(pdu, 7); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,125
static void coroutine_fn v9fs_fs_ro(void *opaque) { V9fsPDU *pdu = opaque; pdu_complete(pdu, -EROFS); }
DoS
0
static void coroutine_fn v9fs_fs_ro(void *opaque) { V9fsPDU *pdu = opaque; pdu_complete(pdu, -EROFS); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,126
static void v9fs_fsync(void *opaque) { int err; int32_t fid; int datasync; size_t offset = 7; V9fsFidState *fidp; V9fsPDU *pdu = opaque; err = pdu_unmarshal(pdu, offset, "dd", &fid, &datasync); if (err < 0) { goto out_nofid; } trace_v9fs_fsync(pdu->tag, pdu->id, fid, datasync); fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } err = v9fs_co_fsync(pdu, fidp, datasync); if (!err) { err = offset; } put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); }
DoS
0
static void v9fs_fsync(void *opaque) { int err; int32_t fid; int datasync; size_t offset = 7; V9fsFidState *fidp; V9fsPDU *pdu = opaque; err = pdu_unmarshal(pdu, offset, "dd", &fid, &datasync); if (err < 0) { goto out_nofid; } trace_v9fs_fsync(pdu->tag, pdu->id, fid, datasync); fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } err = v9fs_co_fsync(pdu, fidp, datasync); if (!err) { err = offset; } put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,127
static void v9fs_init_qiov_from_pdu(QEMUIOVector *qiov, V9fsPDU *pdu, size_t skip, size_t size, bool is_write) { QEMUIOVector elem; struct iovec *iov; unsigned int niov; virtio_init_iov_from_pdu(pdu, &iov, &niov, is_write); qemu_iovec_init_external(&elem, iov, niov); qemu_iovec_init(qiov, niov); qemu_iovec_concat(qiov, &elem, skip, size); }
DoS
0
static void v9fs_init_qiov_from_pdu(QEMUIOVector *qiov, V9fsPDU *pdu, size_t skip, size_t size, bool is_write) { QEMUIOVector elem; struct iovec *iov; unsigned int niov; virtio_init_iov_from_pdu(pdu, &iov, &niov, is_write); qemu_iovec_init_external(&elem, iov, niov); qemu_iovec_init(qiov, niov); qemu_iovec_concat(qiov, &elem, skip, size); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,128
static void coroutine_fn v9fs_lcreate(void *opaque) { int32_t dfid, flags, mode; gid_t gid; ssize_t err = 0; ssize_t offset = 7; V9fsString name; V9fsFidState *fidp; struct stat stbuf; V9fsQID qid; int32_t iounit; V9fsPDU *pdu = opaque; v9fs_string_init(&name); err = pdu_unmarshal(pdu, offset, "dsddd", &dfid, &name, &flags, &mode, &gid); if (err < 0) { goto out_nofid; } trace_v9fs_lcreate(pdu->tag, pdu->id, dfid, flags, mode, gid); if (name_is_illegal(name.data)) { err = -ENOENT; goto out_nofid; } if (!strcmp(".", name.data) || !strcmp("..", name.data)) { err = -EEXIST; goto out_nofid; } fidp = get_fid(pdu, dfid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } flags = get_dotl_openflags(pdu->s, flags); err = v9fs_co_open2(pdu, fidp, &name, gid, flags | O_CREAT, mode, &stbuf); if (err < 0) { goto out; } fidp->fid_type = P9_FID_FILE; fidp->open_flags = flags; if (flags & O_EXCL) { /* * We let the host file system do O_EXCL check * We should not reclaim such fd */ fidp->flags |= FID_NON_RECLAIMABLE; } iounit = get_iounit(pdu, &fidp->path); stat_to_qid(&stbuf, &qid); err = pdu_marshal(pdu, offset, "Qd", &qid, iounit); if (err < 0) { goto out; } err += offset; trace_v9fs_lcreate_return(pdu->tag, pdu->id, qid.type, qid.version, qid.path, iounit); out: put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); v9fs_string_free(&name); }
DoS
0
static void coroutine_fn v9fs_lcreate(void *opaque) { int32_t dfid, flags, mode; gid_t gid; ssize_t err = 0; ssize_t offset = 7; V9fsString name; V9fsFidState *fidp; struct stat stbuf; V9fsQID qid; int32_t iounit; V9fsPDU *pdu = opaque; v9fs_string_init(&name); err = pdu_unmarshal(pdu, offset, "dsddd", &dfid, &name, &flags, &mode, &gid); if (err < 0) { goto out_nofid; } trace_v9fs_lcreate(pdu->tag, pdu->id, dfid, flags, mode, gid); if (name_is_illegal(name.data)) { err = -ENOENT; goto out_nofid; } if (!strcmp(".", name.data) || !strcmp("..", name.data)) { err = -EEXIST; goto out_nofid; } fidp = get_fid(pdu, dfid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } flags = get_dotl_openflags(pdu->s, flags); err = v9fs_co_open2(pdu, fidp, &name, gid, flags | O_CREAT, mode, &stbuf); if (err < 0) { goto out; } fidp->fid_type = P9_FID_FILE; fidp->open_flags = flags; if (flags & O_EXCL) { /* * We let the host file system do O_EXCL check * We should not reclaim such fd */ fidp->flags |= FID_NON_RECLAIMABLE; } iounit = get_iounit(pdu, &fidp->path); stat_to_qid(&stbuf, &qid); err = pdu_marshal(pdu, offset, "Qd", &qid, iounit); if (err < 0) { goto out; } err += offset; trace_v9fs_lcreate_return(pdu->tag, pdu->id, qid.type, qid.version, qid.path, iounit); out: put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); v9fs_string_free(&name); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,129
static void coroutine_fn v9fs_lock(void *opaque) { int8_t status; V9fsFlock flock; size_t offset = 7; struct stat stbuf; V9fsFidState *fidp; int32_t fid, err = 0; V9fsPDU *pdu = opaque; status = P9_LOCK_ERROR; v9fs_string_init(&flock.client_id); err = pdu_unmarshal(pdu, offset, "dbdqqds", &fid, &flock.type, &flock.flags, &flock.start, &flock.length, &flock.proc_id, &flock.client_id); if (err < 0) { goto out_nofid; } trace_v9fs_lock(pdu->tag, pdu->id, fid, flock.type, flock.start, flock.length); /* We support only block flag now (that too ignored currently) */ if (flock.flags & ~P9_LOCK_FLAGS_BLOCK) { err = -EINVAL; goto out_nofid; } fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } err = v9fs_co_fstat(pdu, fidp, &stbuf); if (err < 0) { goto out; } status = P9_LOCK_SUCCESS; out: put_fid(pdu, fidp); out_nofid: err = pdu_marshal(pdu, offset, "b", status); if (err > 0) { err += offset; } trace_v9fs_lock_return(pdu->tag, pdu->id, status); pdu_complete(pdu, err); v9fs_string_free(&flock.client_id); }
DoS
0
static void coroutine_fn v9fs_lock(void *opaque) { int8_t status; V9fsFlock flock; size_t offset = 7; struct stat stbuf; V9fsFidState *fidp; int32_t fid, err = 0; V9fsPDU *pdu = opaque; status = P9_LOCK_ERROR; v9fs_string_init(&flock.client_id); err = pdu_unmarshal(pdu, offset, "dbdqqds", &fid, &flock.type, &flock.flags, &flock.start, &flock.length, &flock.proc_id, &flock.client_id); if (err < 0) { goto out_nofid; } trace_v9fs_lock(pdu->tag, pdu->id, fid, flock.type, flock.start, flock.length); /* We support only block flag now (that too ignored currently) */ if (flock.flags & ~P9_LOCK_FLAGS_BLOCK) { err = -EINVAL; goto out_nofid; } fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } err = v9fs_co_fstat(pdu, fidp, &stbuf); if (err < 0) { goto out; } status = P9_LOCK_SUCCESS; out: put_fid(pdu, fidp); out_nofid: err = pdu_marshal(pdu, offset, "b", status); if (err > 0) { err += offset; } trace_v9fs_lock_return(pdu->tag, pdu->id, status); pdu_complete(pdu, err); v9fs_string_free(&flock.client_id); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,130
static int coroutine_fn v9fs_mark_fids_unreclaim(V9fsPDU *pdu, V9fsPath *path) { int err; V9fsState *s = pdu->s; V9fsFidState *fidp, head_fid; head_fid.next = s->fid_list; for (fidp = s->fid_list; fidp; fidp = fidp->next) { if (fidp->path.size != path->size) { continue; } if (!memcmp(fidp->path.data, path->data, path->size)) { /* Mark the fid non reclaimable. */ fidp->flags |= FID_NON_RECLAIMABLE; /* reopen the file/dir if already closed */ err = v9fs_reopen_fid(pdu, fidp); if (err < 0) { return -1; } /* * Go back to head of fid list because * the list could have got updated when * switched to the worker thread */ if (err == 0) { fidp = &head_fid; } } } return 0; }
DoS
0
static int coroutine_fn v9fs_mark_fids_unreclaim(V9fsPDU *pdu, V9fsPath *path) { int err; V9fsState *s = pdu->s; V9fsFidState *fidp, head_fid; head_fid.next = s->fid_list; for (fidp = s->fid_list; fidp; fidp = fidp->next) { if (fidp->path.size != path->size) { continue; } if (!memcmp(fidp->path.data, path->data, path->size)) { /* Mark the fid non reclaimable. */ fidp->flags |= FID_NON_RECLAIMABLE; /* reopen the file/dir if already closed */ err = v9fs_reopen_fid(pdu, fidp); if (err < 0) { return -1; } /* * Go back to head of fid list because * the list could have got updated when * switched to the worker thread */ if (err == 0) { fidp = &head_fid; } } } return 0; }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,131
static void coroutine_fn v9fs_mkdir(void *opaque) { V9fsPDU *pdu = opaque; size_t offset = 7; int32_t fid; struct stat stbuf; V9fsQID qid; V9fsString name; V9fsFidState *fidp; gid_t gid; int mode; int err = 0; v9fs_string_init(&name); err = pdu_unmarshal(pdu, offset, "dsdd", &fid, &name, &mode, &gid); if (err < 0) { goto out_nofid; } trace_v9fs_mkdir(pdu->tag, pdu->id, fid, name.data, mode, gid); if (name_is_illegal(name.data)) { err = -ENOENT; goto out_nofid; } if (!strcmp(".", name.data) || !strcmp("..", name.data)) { err = -EEXIST; goto out_nofid; } fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } err = v9fs_co_mkdir(pdu, fidp, &name, mode, fidp->uid, gid, &stbuf); if (err < 0) { goto out; } stat_to_qid(&stbuf, &qid); err = pdu_marshal(pdu, offset, "Q", &qid); if (err < 0) { goto out; } err += offset; trace_v9fs_mkdir_return(pdu->tag, pdu->id, qid.type, qid.version, qid.path, err); out: put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); v9fs_string_free(&name); }
DoS
0
static void coroutine_fn v9fs_mkdir(void *opaque) { V9fsPDU *pdu = opaque; size_t offset = 7; int32_t fid; struct stat stbuf; V9fsQID qid; V9fsString name; V9fsFidState *fidp; gid_t gid; int mode; int err = 0; v9fs_string_init(&name); err = pdu_unmarshal(pdu, offset, "dsdd", &fid, &name, &mode, &gid); if (err < 0) { goto out_nofid; } trace_v9fs_mkdir(pdu->tag, pdu->id, fid, name.data, mode, gid); if (name_is_illegal(name.data)) { err = -ENOENT; goto out_nofid; } if (!strcmp(".", name.data) || !strcmp("..", name.data)) { err = -EEXIST; goto out_nofid; } fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } err = v9fs_co_mkdir(pdu, fidp, &name, mode, fidp->uid, gid, &stbuf); if (err < 0) { goto out; } stat_to_qid(&stbuf, &qid); err = pdu_marshal(pdu, offset, "Q", &qid); if (err < 0) { goto out; } err += offset; trace_v9fs_mkdir_return(pdu->tag, pdu->id, qid.type, qid.version, qid.path, err); out: put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); v9fs_string_free(&name); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,132
static void coroutine_fn v9fs_mknod(void *opaque) { int mode; gid_t gid; int32_t fid; V9fsQID qid; int err = 0; int major, minor; size_t offset = 7; V9fsString name; struct stat stbuf; V9fsFidState *fidp; V9fsPDU *pdu = opaque; v9fs_string_init(&name); err = pdu_unmarshal(pdu, offset, "dsdddd", &fid, &name, &mode, &major, &minor, &gid); if (err < 0) { goto out_nofid; } trace_v9fs_mknod(pdu->tag, pdu->id, fid, mode, major, minor); if (name_is_illegal(name.data)) { err = -ENOENT; goto out_nofid; } if (!strcmp(".", name.data) || !strcmp("..", name.data)) { err = -EEXIST; goto out_nofid; } fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } err = v9fs_co_mknod(pdu, fidp, &name, fidp->uid, gid, makedev(major, minor), mode, &stbuf); if (err < 0) { goto out; } stat_to_qid(&stbuf, &qid); err = pdu_marshal(pdu, offset, "Q", &qid); if (err < 0) { goto out; } err += offset; trace_v9fs_mknod_return(pdu->tag, pdu->id, qid.type, qid.version, qid.path); out: put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); v9fs_string_free(&name); }
DoS
0
static void coroutine_fn v9fs_mknod(void *opaque) { int mode; gid_t gid; int32_t fid; V9fsQID qid; int err = 0; int major, minor; size_t offset = 7; V9fsString name; struct stat stbuf; V9fsFidState *fidp; V9fsPDU *pdu = opaque; v9fs_string_init(&name); err = pdu_unmarshal(pdu, offset, "dsdddd", &fid, &name, &mode, &major, &minor, &gid); if (err < 0) { goto out_nofid; } trace_v9fs_mknod(pdu->tag, pdu->id, fid, mode, major, minor); if (name_is_illegal(name.data)) { err = -ENOENT; goto out_nofid; } if (!strcmp(".", name.data) || !strcmp("..", name.data)) { err = -EEXIST; goto out_nofid; } fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } err = v9fs_co_mknod(pdu, fidp, &name, fidp->uid, gid, makedev(major, minor), mode, &stbuf); if (err < 0) { goto out; } stat_to_qid(&stbuf, &qid); err = pdu_marshal(pdu, offset, "Q", &qid); if (err < 0) { goto out; } err += offset; trace_v9fs_mknod_return(pdu->tag, pdu->id, qid.type, qid.version, qid.path); out: put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); v9fs_string_free(&name); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,133
static void coroutine_fn v9fs_op_not_supp(void *opaque) { V9fsPDU *pdu = opaque; pdu_complete(pdu, -EOPNOTSUPP); }
DoS
0
static void coroutine_fn v9fs_op_not_supp(void *opaque) { V9fsPDU *pdu = opaque; pdu_complete(pdu, -EOPNOTSUPP); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,134
void v9fs_path_copy(V9fsPath *lhs, V9fsPath *rhs) { v9fs_path_free(lhs); lhs->data = g_malloc(rhs->size); memcpy(lhs->data, rhs->data, rhs->size); lhs->size = rhs->size; }
DoS
0
void v9fs_path_copy(V9fsPath *lhs, V9fsPath *rhs) { v9fs_path_free(lhs); lhs->data = g_malloc(rhs->size); memcpy(lhs->data, rhs->data, rhs->size); lhs->size = rhs->size; }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,135
static void coroutine_fn v9fs_readlink(void *opaque) { V9fsPDU *pdu = opaque; size_t offset = 7; V9fsString target; int32_t fid; int err = 0; V9fsFidState *fidp; err = pdu_unmarshal(pdu, offset, "d", &fid); if (err < 0) { goto out_nofid; } trace_v9fs_readlink(pdu->tag, pdu->id, fid); fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } v9fs_string_init(&target); err = v9fs_co_readlink(pdu, &fidp->path, &target); if (err < 0) { goto out; } err = pdu_marshal(pdu, offset, "s", &target); if (err < 0) { v9fs_string_free(&target); goto out; } err += offset; trace_v9fs_readlink_return(pdu->tag, pdu->id, target.data); v9fs_string_free(&target); out: put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); }
DoS
0
static void coroutine_fn v9fs_readlink(void *opaque) { V9fsPDU *pdu = opaque; size_t offset = 7; V9fsString target; int32_t fid; int err = 0; V9fsFidState *fidp; err = pdu_unmarshal(pdu, offset, "d", &fid); if (err < 0) { goto out_nofid; } trace_v9fs_readlink(pdu->tag, pdu->id, fid); fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } v9fs_string_init(&target); err = v9fs_co_readlink(pdu, &fidp->path, &target); if (err < 0) { goto out; } err = pdu_marshal(pdu, offset, "s", &target); if (err < 0) { v9fs_string_free(&target); goto out; } err += offset; trace_v9fs_readlink_return(pdu->tag, pdu->id, target.data); v9fs_string_free(&target); out: put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,136
void v9fs_reset(V9fsState *s) { VirtfsCoResetData data = { .pdu = { .s = s }, .done = false }; Coroutine *co; while (!QLIST_EMPTY(&s->active_list)) { aio_poll(qemu_get_aio_context(), true); } co = qemu_coroutine_create(virtfs_co_reset, &data); qemu_coroutine_enter(co); while (!data.done) { aio_poll(qemu_get_aio_context(), true); } }
DoS
0
void v9fs_reset(V9fsState *s) { VirtfsCoResetData data = { .pdu = { .s = s }, .done = false }; Coroutine *co; while (!QLIST_EMPTY(&s->active_list)) { aio_poll(qemu_get_aio_context(), true); } co = qemu_coroutine_create(virtfs_co_reset, &data); qemu_coroutine_enter(co); while (!data.done) { aio_poll(qemu_get_aio_context(), true); } }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,137
static void __attribute__((__constructor__)) v9fs_set_fd_limit(void) { struct rlimit rlim; if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) { error_report("Failed to get the resource limit"); exit(1); } open_fd_hw = rlim.rlim_cur - MIN(400, rlim.rlim_cur/3); open_fd_rc = rlim.rlim_cur/2; }
DoS
0
static void __attribute__((__constructor__)) v9fs_set_fd_limit(void) { struct rlimit rlim; if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) { error_report("Failed to get the resource limit"); exit(1); } open_fd_hw = rlim.rlim_cur - MIN(400, rlim.rlim_cur/3); open_fd_rc = rlim.rlim_cur/2; }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,138
static void coroutine_fn v9fs_setattr(void *opaque) { int err = 0; int32_t fid; V9fsFidState *fidp; size_t offset = 7; V9fsIattr v9iattr; V9fsPDU *pdu = opaque; err = pdu_unmarshal(pdu, offset, "dI", &fid, &v9iattr); if (err < 0) { goto out_nofid; } fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -EINVAL; goto out_nofid; } if (v9iattr.valid & P9_ATTR_MODE) { err = v9fs_co_chmod(pdu, &fidp->path, v9iattr.mode); if (err < 0) { goto out; } } if (v9iattr.valid & (P9_ATTR_ATIME | P9_ATTR_MTIME)) { struct timespec times[2]; if (v9iattr.valid & P9_ATTR_ATIME) { if (v9iattr.valid & P9_ATTR_ATIME_SET) { times[0].tv_sec = v9iattr.atime_sec; times[0].tv_nsec = v9iattr.atime_nsec; } else { times[0].tv_nsec = UTIME_NOW; } } else { times[0].tv_nsec = UTIME_OMIT; } if (v9iattr.valid & P9_ATTR_MTIME) { if (v9iattr.valid & P9_ATTR_MTIME_SET) { times[1].tv_sec = v9iattr.mtime_sec; times[1].tv_nsec = v9iattr.mtime_nsec; } else { times[1].tv_nsec = UTIME_NOW; } } else { times[1].tv_nsec = UTIME_OMIT; } err = v9fs_co_utimensat(pdu, &fidp->path, times); if (err < 0) { goto out; } } /* * If the only valid entry in iattr is ctime we can call * chown(-1,-1) to update the ctime of the file */ if ((v9iattr.valid & (P9_ATTR_UID | P9_ATTR_GID)) || ((v9iattr.valid & P9_ATTR_CTIME) && !((v9iattr.valid & P9_ATTR_MASK) & ~P9_ATTR_CTIME))) { if (!(v9iattr.valid & P9_ATTR_UID)) { v9iattr.uid = -1; } if (!(v9iattr.valid & P9_ATTR_GID)) { v9iattr.gid = -1; } err = v9fs_co_chown(pdu, &fidp->path, v9iattr.uid, v9iattr.gid); if (err < 0) { goto out; } } if (v9iattr.valid & (P9_ATTR_SIZE)) { err = v9fs_co_truncate(pdu, &fidp->path, v9iattr.size); if (err < 0) { goto out; } } err = offset; out: put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); }
DoS
0
static void coroutine_fn v9fs_setattr(void *opaque) { int err = 0; int32_t fid; V9fsFidState *fidp; size_t offset = 7; V9fsIattr v9iattr; V9fsPDU *pdu = opaque; err = pdu_unmarshal(pdu, offset, "dI", &fid, &v9iattr); if (err < 0) { goto out_nofid; } fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -EINVAL; goto out_nofid; } if (v9iattr.valid & P9_ATTR_MODE) { err = v9fs_co_chmod(pdu, &fidp->path, v9iattr.mode); if (err < 0) { goto out; } } if (v9iattr.valid & (P9_ATTR_ATIME | P9_ATTR_MTIME)) { struct timespec times[2]; if (v9iattr.valid & P9_ATTR_ATIME) { if (v9iattr.valid & P9_ATTR_ATIME_SET) { times[0].tv_sec = v9iattr.atime_sec; times[0].tv_nsec = v9iattr.atime_nsec; } else { times[0].tv_nsec = UTIME_NOW; } } else { times[0].tv_nsec = UTIME_OMIT; } if (v9iattr.valid & P9_ATTR_MTIME) { if (v9iattr.valid & P9_ATTR_MTIME_SET) { times[1].tv_sec = v9iattr.mtime_sec; times[1].tv_nsec = v9iattr.mtime_nsec; } else { times[1].tv_nsec = UTIME_NOW; } } else { times[1].tv_nsec = UTIME_OMIT; } err = v9fs_co_utimensat(pdu, &fidp->path, times); if (err < 0) { goto out; } } /* * If the only valid entry in iattr is ctime we can call * chown(-1,-1) to update the ctime of the file */ if ((v9iattr.valid & (P9_ATTR_UID | P9_ATTR_GID)) || ((v9iattr.valid & P9_ATTR_CTIME) && !((v9iattr.valid & P9_ATTR_MASK) & ~P9_ATTR_CTIME))) { if (!(v9iattr.valid & P9_ATTR_UID)) { v9iattr.uid = -1; } if (!(v9iattr.valid & P9_ATTR_GID)) { v9iattr.gid = -1; } err = v9fs_co_chown(pdu, &fidp->path, v9iattr.uid, v9iattr.gid); if (err < 0) { goto out; } } if (v9iattr.valid & (P9_ATTR_SIZE)) { err = v9fs_co_truncate(pdu, &fidp->path, v9iattr.size); if (err < 0) { goto out; } } err = offset; out: put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,139
static void coroutine_fn v9fs_stat(void *opaque) { int32_t fid; V9fsStat v9stat; ssize_t err = 0; size_t offset = 7; struct stat stbuf; V9fsFidState *fidp; V9fsPDU *pdu = opaque; err = pdu_unmarshal(pdu, offset, "d", &fid); if (err < 0) { goto out_nofid; } trace_v9fs_stat(pdu->tag, pdu->id, fid); fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } err = v9fs_co_lstat(pdu, &fidp->path, &stbuf); if (err < 0) { goto out; } err = stat_to_v9stat(pdu, &fidp->path, &stbuf, &v9stat); if (err < 0) { goto out; } err = pdu_marshal(pdu, offset, "wS", 0, &v9stat); if (err < 0) { v9fs_stat_free(&v9stat); goto out; } trace_v9fs_stat_return(pdu->tag, pdu->id, v9stat.mode, v9stat.atime, v9stat.mtime, v9stat.length); err += offset; v9fs_stat_free(&v9stat); out: put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); }
DoS
0
static void coroutine_fn v9fs_stat(void *opaque) { int32_t fid; V9fsStat v9stat; ssize_t err = 0; size_t offset = 7; struct stat stbuf; V9fsFidState *fidp; V9fsPDU *pdu = opaque; err = pdu_unmarshal(pdu, offset, "d", &fid); if (err < 0) { goto out_nofid; } trace_v9fs_stat(pdu->tag, pdu->id, fid); fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } err = v9fs_co_lstat(pdu, &fidp->path, &stbuf); if (err < 0) { goto out; } err = stat_to_v9stat(pdu, &fidp->path, &stbuf, &v9stat); if (err < 0) { goto out; } err = pdu_marshal(pdu, offset, "wS", 0, &v9stat); if (err < 0) { v9fs_stat_free(&v9stat); goto out; } trace_v9fs_stat_return(pdu->tag, pdu->id, v9stat.mode, v9stat.atime, v9stat.mtime, v9stat.length); err += offset; v9fs_stat_free(&v9stat); out: put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,140
static void coroutine_fn v9fs_version(void *opaque) { ssize_t err; V9fsPDU *pdu = opaque; V9fsState *s = pdu->s; V9fsString version; size_t offset = 7; v9fs_string_init(&version); err = pdu_unmarshal(pdu, offset, "ds", &s->msize, &version); if (err < 0) { offset = err; goto out; } trace_v9fs_version(pdu->tag, pdu->id, s->msize, version.data); virtfs_reset(pdu); if (!strcmp(version.data, "9P2000.u")) { s->proto_version = V9FS_PROTO_2000U; } else if (!strcmp(version.data, "9P2000.L")) { s->proto_version = V9FS_PROTO_2000L; } else { v9fs_string_sprintf(&version, "unknown"); } err = pdu_marshal(pdu, offset, "ds", s->msize, &version); if (err < 0) { offset = err; goto out; } offset += err; trace_v9fs_version_return(pdu->tag, pdu->id, s->msize, version.data); out: pdu_complete(pdu, offset); v9fs_string_free(&version); }
DoS
0
static void coroutine_fn v9fs_version(void *opaque) { ssize_t err; V9fsPDU *pdu = opaque; V9fsState *s = pdu->s; V9fsString version; size_t offset = 7; v9fs_string_init(&version); err = pdu_unmarshal(pdu, offset, "ds", &s->msize, &version); if (err < 0) { offset = err; goto out; } trace_v9fs_version(pdu->tag, pdu->id, s->msize, version.data); virtfs_reset(pdu); if (!strcmp(version.data, "9P2000.u")) { s->proto_version = V9FS_PROTO_2000U; } else if (!strcmp(version.data, "9P2000.L")) { s->proto_version = V9FS_PROTO_2000L; } else { v9fs_string_sprintf(&version, "unknown"); } err = pdu_marshal(pdu, offset, "ds", s->msize, &version); if (err < 0) { offset = err; goto out; } offset += err; trace_v9fs_version_return(pdu->tag, pdu->id, s->msize, version.data); out: pdu_complete(pdu, offset); v9fs_string_free(&version); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,141
static void coroutine_fn v9fs_walk(void *opaque) { int name_idx; V9fsQID *qids = NULL; int i, err = 0; V9fsPath dpath, path; uint16_t nwnames; struct stat stbuf; size_t offset = 7; int32_t fid, newfid; V9fsString *wnames = NULL; V9fsFidState *fidp; V9fsFidState *newfidp = NULL; V9fsPDU *pdu = opaque; V9fsState *s = pdu->s; V9fsQID qid; err = pdu_unmarshal(pdu, offset, "ddw", &fid, &newfid, &nwnames); if (err < 0) { pdu_complete(pdu, err); return ; } offset += err; trace_v9fs_walk(pdu->tag, pdu->id, fid, newfid, nwnames); if (nwnames && nwnames <= P9_MAXWELEM) { wnames = g_malloc0(sizeof(wnames[0]) * nwnames); qids = g_malloc0(sizeof(qids[0]) * nwnames); for (i = 0; i < nwnames; i++) { err = pdu_unmarshal(pdu, offset, "s", &wnames[i]); if (err < 0) { goto out_nofid; } if (name_is_illegal(wnames[i].data)) { err = -ENOENT; goto out_nofid; } offset += err; } } else if (nwnames > P9_MAXWELEM) { err = -EINVAL; goto out_nofid; } fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } v9fs_path_init(&dpath); v9fs_path_init(&path); err = fid_to_qid(pdu, fidp, &qid); if (err < 0) { goto out; } /* * Both dpath and path initially poin to fidp. * Needed to handle request with nwnames == 0 */ v9fs_path_copy(&dpath, &fidp->path); v9fs_path_copy(&path, &fidp->path); for (name_idx = 0; name_idx < nwnames; name_idx++) { if (not_same_qid(&pdu->s->root_qid, &qid) || strcmp("..", wnames[name_idx].data)) { err = v9fs_co_name_to_path(pdu, &dpath, wnames[name_idx].data, &path); if (err < 0) { goto out; } err = v9fs_co_lstat(pdu, &path, &stbuf); if (err < 0) { goto out; } stat_to_qid(&stbuf, &qid); v9fs_path_copy(&dpath, &path); } memcpy(&qids[name_idx], &qid, sizeof(qid)); } if (fid == newfid) { if (fidp->fid_type != P9_FID_NONE) { err = -EINVAL; goto out; } v9fs_path_copy(&fidp->path, &path); } else { newfidp = alloc_fid(s, newfid); if (newfidp == NULL) { err = -EINVAL; goto out; } newfidp->uid = fidp->uid; v9fs_path_copy(&newfidp->path, &path); } err = v9fs_walk_marshal(pdu, nwnames, qids); trace_v9fs_walk_return(pdu->tag, pdu->id, nwnames, qids); out: put_fid(pdu, fidp); if (newfidp) { put_fid(pdu, newfidp); } v9fs_path_free(&dpath); v9fs_path_free(&path); out_nofid: pdu_complete(pdu, err); if (nwnames && nwnames <= P9_MAXWELEM) { for (name_idx = 0; name_idx < nwnames; name_idx++) { v9fs_string_free(&wnames[name_idx]); } g_free(wnames); g_free(qids); } }
DoS
0
static void coroutine_fn v9fs_walk(void *opaque) { int name_idx; V9fsQID *qids = NULL; int i, err = 0; V9fsPath dpath, path; uint16_t nwnames; struct stat stbuf; size_t offset = 7; int32_t fid, newfid; V9fsString *wnames = NULL; V9fsFidState *fidp; V9fsFidState *newfidp = NULL; V9fsPDU *pdu = opaque; V9fsState *s = pdu->s; V9fsQID qid; err = pdu_unmarshal(pdu, offset, "ddw", &fid, &newfid, &nwnames); if (err < 0) { pdu_complete(pdu, err); return ; } offset += err; trace_v9fs_walk(pdu->tag, pdu->id, fid, newfid, nwnames); if (nwnames && nwnames <= P9_MAXWELEM) { wnames = g_malloc0(sizeof(wnames[0]) * nwnames); qids = g_malloc0(sizeof(qids[0]) * nwnames); for (i = 0; i < nwnames; i++) { err = pdu_unmarshal(pdu, offset, "s", &wnames[i]); if (err < 0) { goto out_nofid; } if (name_is_illegal(wnames[i].data)) { err = -ENOENT; goto out_nofid; } offset += err; } } else if (nwnames > P9_MAXWELEM) { err = -EINVAL; goto out_nofid; } fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } v9fs_path_init(&dpath); v9fs_path_init(&path); err = fid_to_qid(pdu, fidp, &qid); if (err < 0) { goto out; } /* * Both dpath and path initially poin to fidp. * Needed to handle request with nwnames == 0 */ v9fs_path_copy(&dpath, &fidp->path); v9fs_path_copy(&path, &fidp->path); for (name_idx = 0; name_idx < nwnames; name_idx++) { if (not_same_qid(&pdu->s->root_qid, &qid) || strcmp("..", wnames[name_idx].data)) { err = v9fs_co_name_to_path(pdu, &dpath, wnames[name_idx].data, &path); if (err < 0) { goto out; } err = v9fs_co_lstat(pdu, &path, &stbuf); if (err < 0) { goto out; } stat_to_qid(&stbuf, &qid); v9fs_path_copy(&dpath, &path); } memcpy(&qids[name_idx], &qid, sizeof(qid)); } if (fid == newfid) { if (fidp->fid_type != P9_FID_NONE) { err = -EINVAL; goto out; } v9fs_path_copy(&fidp->path, &path); } else { newfidp = alloc_fid(s, newfid); if (newfidp == NULL) { err = -EINVAL; goto out; } newfidp->uid = fidp->uid; v9fs_path_copy(&newfidp->path, &path); } err = v9fs_walk_marshal(pdu, nwnames, qids); trace_v9fs_walk_return(pdu->tag, pdu->id, nwnames, qids); out: put_fid(pdu, fidp); if (newfidp) { put_fid(pdu, newfidp); } v9fs_path_free(&dpath); v9fs_path_free(&path); out_nofid: pdu_complete(pdu, err); if (nwnames && nwnames <= P9_MAXWELEM) { for (name_idx = 0; name_idx < nwnames; name_idx++) { v9fs_string_free(&wnames[name_idx]); } g_free(wnames); g_free(qids); } }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,142
static void coroutine_fn v9fs_wstat(void *opaque) { int32_t fid; int err = 0; int16_t unused; V9fsStat v9stat; size_t offset = 7; struct stat stbuf; V9fsFidState *fidp; V9fsPDU *pdu = opaque; v9fs_stat_init(&v9stat); err = pdu_unmarshal(pdu, offset, "dwS", &fid, &unused, &v9stat); if (err < 0) { goto out_nofid; } trace_v9fs_wstat(pdu->tag, pdu->id, fid, v9stat.mode, v9stat.atime, v9stat.mtime); fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -EINVAL; goto out_nofid; } /* do we need to sync the file? */ if (donttouch_stat(&v9stat)) { err = v9fs_co_fsync(pdu, fidp, 0); goto out; } if (v9stat.mode != -1) { uint32_t v9_mode; err = v9fs_co_lstat(pdu, &fidp->path, &stbuf); if (err < 0) { goto out; } v9_mode = stat_to_v9mode(&stbuf); if ((v9stat.mode & P9_STAT_MODE_TYPE_BITS) != (v9_mode & P9_STAT_MODE_TYPE_BITS)) { /* Attempting to change the type */ err = -EIO; goto out; } err = v9fs_co_chmod(pdu, &fidp->path, v9mode_to_mode(v9stat.mode, &v9stat.extension)); if (err < 0) { goto out; } } if (v9stat.mtime != -1 || v9stat.atime != -1) { struct timespec times[2]; if (v9stat.atime != -1) { times[0].tv_sec = v9stat.atime; times[0].tv_nsec = 0; } else { times[0].tv_nsec = UTIME_OMIT; } if (v9stat.mtime != -1) { times[1].tv_sec = v9stat.mtime; times[1].tv_nsec = 0; } else { times[1].tv_nsec = UTIME_OMIT; } err = v9fs_co_utimensat(pdu, &fidp->path, times); if (err < 0) { goto out; } } if (v9stat.n_gid != -1 || v9stat.n_uid != -1) { err = v9fs_co_chown(pdu, &fidp->path, v9stat.n_uid, v9stat.n_gid); if (err < 0) { goto out; } } if (v9stat.name.size != 0) { err = v9fs_complete_rename(pdu, fidp, -1, &v9stat.name); if (err < 0) { goto out; } } if (v9stat.length != -1) { err = v9fs_co_truncate(pdu, &fidp->path, v9stat.length); if (err < 0) { goto out; } } err = offset; out: put_fid(pdu, fidp); out_nofid: v9fs_stat_free(&v9stat); pdu_complete(pdu, err); }
DoS
0
static void coroutine_fn v9fs_wstat(void *opaque) { int32_t fid; int err = 0; int16_t unused; V9fsStat v9stat; size_t offset = 7; struct stat stbuf; V9fsFidState *fidp; V9fsPDU *pdu = opaque; v9fs_stat_init(&v9stat); err = pdu_unmarshal(pdu, offset, "dwS", &fid, &unused, &v9stat); if (err < 0) { goto out_nofid; } trace_v9fs_wstat(pdu->tag, pdu->id, fid, v9stat.mode, v9stat.atime, v9stat.mtime); fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -EINVAL; goto out_nofid; } /* do we need to sync the file? */ if (donttouch_stat(&v9stat)) { err = v9fs_co_fsync(pdu, fidp, 0); goto out; } if (v9stat.mode != -1) { uint32_t v9_mode; err = v9fs_co_lstat(pdu, &fidp->path, &stbuf); if (err < 0) { goto out; } v9_mode = stat_to_v9mode(&stbuf); if ((v9stat.mode & P9_STAT_MODE_TYPE_BITS) != (v9_mode & P9_STAT_MODE_TYPE_BITS)) { /* Attempting to change the type */ err = -EIO; goto out; } err = v9fs_co_chmod(pdu, &fidp->path, v9mode_to_mode(v9stat.mode, &v9stat.extension)); if (err < 0) { goto out; } } if (v9stat.mtime != -1 || v9stat.atime != -1) { struct timespec times[2]; if (v9stat.atime != -1) { times[0].tv_sec = v9stat.atime; times[0].tv_nsec = 0; } else { times[0].tv_nsec = UTIME_OMIT; } if (v9stat.mtime != -1) { times[1].tv_sec = v9stat.mtime; times[1].tv_nsec = 0; } else { times[1].tv_nsec = UTIME_OMIT; } err = v9fs_co_utimensat(pdu, &fidp->path, times); if (err < 0) { goto out; } } if (v9stat.n_gid != -1 || v9stat.n_uid != -1) { err = v9fs_co_chown(pdu, &fidp->path, v9stat.n_uid, v9stat.n_gid); if (err < 0) { goto out; } } if (v9stat.name.size != 0) { err = v9fs_complete_rename(pdu, fidp, -1, &v9stat.name); if (err < 0) { goto out; } } if (v9stat.length != -1) { err = v9fs_co_truncate(pdu, &fidp->path, v9stat.length); if (err < 0) { goto out; } } err = offset; out: put_fid(pdu, fidp); out_nofid: v9fs_stat_free(&v9stat); pdu_complete(pdu, err); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,143
static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp, uint64_t off, uint32_t max_count) { ssize_t err; size_t offset = 7; uint64_t read_count; V9fsVirtioState *v = container_of(s, V9fsVirtioState, state); VirtQueueElement *elem = v->elems[pdu->idx]; if (fidp->fs.xattr.len < off) { read_count = 0; } else { read_count = fidp->fs.xattr.len - off; } if (read_count > max_count) { read_count = max_count; } err = pdu_marshal(pdu, offset, "d", read_count); if (err < 0) { return err; } offset += err; err = v9fs_pack(elem->in_sg, elem->in_num, offset, ((char *)fidp->fs.xattr.value) + off, read_count); if (err < 0) { return err; } offset += err; return offset; }
DoS
0
static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp, uint64_t off, uint32_t max_count) { ssize_t err; size_t offset = 7; uint64_t read_count; V9fsVirtioState *v = container_of(s, V9fsVirtioState, state); VirtQueueElement *elem = v->elems[pdu->idx]; if (fidp->fs.xattr.len < off) { read_count = 0; } else { read_count = fidp->fs.xattr.len - off; } if (read_count > max_count) { read_count = max_count; } err = pdu_marshal(pdu, offset, "d", read_count); if (err < 0) { return err; } offset += err; err = v9fs_pack(elem->in_sg, elem->in_num, offset, ((char *)fidp->fs.xattr.value) + off, read_count); if (err < 0) { return err; } offset += err; return offset; }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,144
static void coroutine_fn v9fs_xattrcreate(void *opaque) { int flags; int32_t fid; uint64_t size; ssize_t err = 0; V9fsString name; size_t offset = 7; V9fsFidState *file_fidp; V9fsFidState *xattr_fidp; V9fsPDU *pdu = opaque; v9fs_string_init(&name); err = pdu_unmarshal(pdu, offset, "dsqd", &fid, &name, &size, &flags); if (err < 0) { goto out_nofid; } trace_v9fs_xattrcreate(pdu->tag, pdu->id, fid, name.data, size, flags); if (size > XATTR_SIZE_MAX) { err = -E2BIG; goto out_nofid; } file_fidp = get_fid(pdu, fid); if (file_fidp == NULL) { err = -EINVAL; goto out_nofid; } if (file_fidp->fid_type != P9_FID_NONE) { err = -EINVAL; goto out_put_fid; } /* Make the file fid point to xattr */ xattr_fidp = file_fidp; xattr_fidp->fid_type = P9_FID_XATTR; xattr_fidp->fs.xattr.copied_len = 0; xattr_fidp->fs.xattr.xattrwalk_fid = false; xattr_fidp->fs.xattr.len = size; xattr_fidp->fs.xattr.flags = flags; v9fs_string_init(&xattr_fidp->fs.xattr.name); v9fs_string_copy(&xattr_fidp->fs.xattr.name, &name); xattr_fidp->fs.xattr.value = g_malloc0(size); err = offset; out_put_fid: put_fid(pdu, file_fidp); out_nofid: pdu_complete(pdu, err); v9fs_string_free(&name); }
DoS
0
static void coroutine_fn v9fs_xattrcreate(void *opaque) { int flags; int32_t fid; uint64_t size; ssize_t err = 0; V9fsString name; size_t offset = 7; V9fsFidState *file_fidp; V9fsFidState *xattr_fidp; V9fsPDU *pdu = opaque; v9fs_string_init(&name); err = pdu_unmarshal(pdu, offset, "dsqd", &fid, &name, &size, &flags); if (err < 0) { goto out_nofid; } trace_v9fs_xattrcreate(pdu->tag, pdu->id, fid, name.data, size, flags); if (size > XATTR_SIZE_MAX) { err = -E2BIG; goto out_nofid; } file_fidp = get_fid(pdu, fid); if (file_fidp == NULL) { err = -EINVAL; goto out_nofid; } if (file_fidp->fid_type != P9_FID_NONE) { err = -EINVAL; goto out_put_fid; } /* Make the file fid point to xattr */ xattr_fidp = file_fidp; xattr_fidp->fid_type = P9_FID_XATTR; xattr_fidp->fs.xattr.copied_len = 0; xattr_fidp->fs.xattr.xattrwalk_fid = false; xattr_fidp->fs.xattr.len = size; xattr_fidp->fs.xattr.flags = flags; v9fs_string_init(&xattr_fidp->fs.xattr.name); v9fs_string_copy(&xattr_fidp->fs.xattr.name, &name); xattr_fidp->fs.xattr.value = g_malloc0(size); err = offset; out_put_fid: put_fid(pdu, file_fidp); out_nofid: pdu_complete(pdu, err); v9fs_string_free(&name); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,145
static void coroutine_fn v9fs_xattrwalk(void *opaque) { int64_t size; V9fsString name; ssize_t err = 0; size_t offset = 7; int32_t fid, newfid; V9fsFidState *file_fidp; V9fsFidState *xattr_fidp = NULL; V9fsPDU *pdu = opaque; V9fsState *s = pdu->s; v9fs_string_init(&name); err = pdu_unmarshal(pdu, offset, "dds", &fid, &newfid, &name); if (err < 0) { goto out_nofid; } trace_v9fs_xattrwalk(pdu->tag, pdu->id, fid, newfid, name.data); file_fidp = get_fid(pdu, fid); if (file_fidp == NULL) { err = -ENOENT; goto out_nofid; } xattr_fidp = alloc_fid(s, newfid); if (xattr_fidp == NULL) { err = -EINVAL; goto out; } v9fs_path_copy(&xattr_fidp->path, &file_fidp->path); if (!v9fs_string_size(&name)) { /* * listxattr request. Get the size first */ size = v9fs_co_llistxattr(pdu, &xattr_fidp->path, NULL, 0); if (size < 0) { err = size; clunk_fid(s, xattr_fidp->fid); goto out; } /* * Read the xattr value */ xattr_fidp->fs.xattr.len = size; xattr_fidp->fid_type = P9_FID_XATTR; xattr_fidp->fs.xattr.xattrwalk_fid = true; if (size) { xattr_fidp->fs.xattr.value = g_malloc(size); err = v9fs_co_llistxattr(pdu, &xattr_fidp->path, xattr_fidp->fs.xattr.value, xattr_fidp->fs.xattr.len); if (err < 0) { clunk_fid(s, xattr_fidp->fid); goto out; } } err = pdu_marshal(pdu, offset, "q", size); if (err < 0) { goto out; } err += offset; } else { /* * specific xattr fid. We check for xattr * presence also collect the xattr size */ size = v9fs_co_lgetxattr(pdu, &xattr_fidp->path, &name, NULL, 0); if (size < 0) { err = size; clunk_fid(s, xattr_fidp->fid); goto out; } /* * Read the xattr value */ xattr_fidp->fs.xattr.len = size; xattr_fidp->fid_type = P9_FID_XATTR; xattr_fidp->fs.xattr.xattrwalk_fid = true; if (size) { xattr_fidp->fs.xattr.value = g_malloc(size); err = v9fs_co_lgetxattr(pdu, &xattr_fidp->path, &name, xattr_fidp->fs.xattr.value, xattr_fidp->fs.xattr.len); if (err < 0) { clunk_fid(s, xattr_fidp->fid); goto out; } } err = pdu_marshal(pdu, offset, "q", size); if (err < 0) { goto out; } err += offset; } trace_v9fs_xattrwalk_return(pdu->tag, pdu->id, size); out: put_fid(pdu, file_fidp); if (xattr_fidp) { put_fid(pdu, xattr_fidp); } out_nofid: pdu_complete(pdu, err); v9fs_string_free(&name); }
DoS
0
static void coroutine_fn v9fs_xattrwalk(void *opaque) { int64_t size; V9fsString name; ssize_t err = 0; size_t offset = 7; int32_t fid, newfid; V9fsFidState *file_fidp; V9fsFidState *xattr_fidp = NULL; V9fsPDU *pdu = opaque; V9fsState *s = pdu->s; v9fs_string_init(&name); err = pdu_unmarshal(pdu, offset, "dds", &fid, &newfid, &name); if (err < 0) { goto out_nofid; } trace_v9fs_xattrwalk(pdu->tag, pdu->id, fid, newfid, name.data); file_fidp = get_fid(pdu, fid); if (file_fidp == NULL) { err = -ENOENT; goto out_nofid; } xattr_fidp = alloc_fid(s, newfid); if (xattr_fidp == NULL) { err = -EINVAL; goto out; } v9fs_path_copy(&xattr_fidp->path, &file_fidp->path); if (!v9fs_string_size(&name)) { /* * listxattr request. Get the size first */ size = v9fs_co_llistxattr(pdu, &xattr_fidp->path, NULL, 0); if (size < 0) { err = size; clunk_fid(s, xattr_fidp->fid); goto out; } /* * Read the xattr value */ xattr_fidp->fs.xattr.len = size; xattr_fidp->fid_type = P9_FID_XATTR; xattr_fidp->fs.xattr.xattrwalk_fid = true; if (size) { xattr_fidp->fs.xattr.value = g_malloc(size); err = v9fs_co_llistxattr(pdu, &xattr_fidp->path, xattr_fidp->fs.xattr.value, xattr_fidp->fs.xattr.len); if (err < 0) { clunk_fid(s, xattr_fidp->fid); goto out; } } err = pdu_marshal(pdu, offset, "q", size); if (err < 0) { goto out; } err += offset; } else { /* * specific xattr fid. We check for xattr * presence also collect the xattr size */ size = v9fs_co_lgetxattr(pdu, &xattr_fidp->path, &name, NULL, 0); if (size < 0) { err = size; clunk_fid(s, xattr_fidp->fid); goto out; } /* * Read the xattr value */ xattr_fidp->fs.xattr.len = size; xattr_fidp->fid_type = P9_FID_XATTR; xattr_fidp->fs.xattr.xattrwalk_fid = true; if (size) { xattr_fidp->fs.xattr.value = g_malloc(size); err = v9fs_co_lgetxattr(pdu, &xattr_fidp->path, &name, xattr_fidp->fs.xattr.value, xattr_fidp->fs.xattr.len); if (err < 0) { clunk_fid(s, xattr_fidp->fid); goto out; } } err = pdu_marshal(pdu, offset, "q", size); if (err < 0) { goto out; } err += offset; } trace_v9fs_xattrwalk_return(pdu->tag, pdu->id, size); out: put_fid(pdu, file_fidp); if (xattr_fidp) { put_fid(pdu, xattr_fidp); } out_nofid: pdu_complete(pdu, err); v9fs_string_free(&name); }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,146
static void coroutine_fn virtfs_co_reset(void *opaque) { VirtfsCoResetData *data = opaque; virtfs_reset(&data->pdu); data->done = true; }
DoS
0
static void coroutine_fn virtfs_co_reset(void *opaque) { VirtfsCoResetData *data = opaque; virtfs_reset(&data->pdu); data->done = true; }
@@ -3521,8 +3521,8 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp) rc = 0; out: if (rc) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); v9fs_path_free(&path); } return rc; @@ -3530,8 +3530,8 @@ out: void v9fs_device_unrealize_common(V9fsState *s, Error **errp) { - g_free(s->ctx.fs_root); g_free(s->tag); + g_free(s->ctx.fs_root); } typedef struct VirtfsCoResetData {
CWE-400
null
null
6,147
TT_Get_MM_Var( TT_Face face, FT_MM_Var* *master ) { FT_Stream stream = face->root.stream; FT_Memory memory = face->root.memory; FT_ULong table_len; FT_Error error = TT_Err_Ok; FT_ULong fvar_start; FT_Int i, j; FT_MM_Var* mmvar; FT_Fixed* next_coords; FT_String* next_name; FT_Var_Axis* a; FT_Var_Named_Style* ns; GX_FVar_Head fvar_head; static const FT_Frame_Field fvar_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE GX_FVar_Head FT_FRAME_START( 16 ), FT_FRAME_LONG ( version ), FT_FRAME_USHORT( offsetToData ), FT_FRAME_USHORT( countSizePairs ), FT_FRAME_USHORT( axisCount ), FT_FRAME_USHORT( axisSize ), FT_FRAME_USHORT( instanceCount ), FT_FRAME_USHORT( instanceSize ), FT_FRAME_END }; static const FT_Frame_Field fvaraxis_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE GX_FVar_Axis FT_FRAME_START( 20 ), FT_FRAME_ULONG ( axisTag ), FT_FRAME_ULONG ( minValue ), FT_FRAME_ULONG ( defaultValue ), FT_FRAME_ULONG ( maxValue ), FT_FRAME_USHORT( flags ), FT_FRAME_USHORT( nameID ), FT_FRAME_END }; if ( face->blend == NULL ) { /* both `fvar' and `gvar' must be present */ if ( (error = face->goto_table( face, TTAG_gvar, stream, &table_len )) != 0 ) goto Exit; if ( (error = face->goto_table( face, TTAG_fvar, stream, &table_len )) != 0 ) goto Exit; fvar_start = FT_STREAM_POS( ); if ( FT_STREAM_READ_FIELDS( fvar_fields, &fvar_head ) ) goto Exit; if ( fvar_head.version != (FT_Long)0x00010000L || fvar_head.countSizePairs != 2 || fvar_head.axisSize != 20 || /* axisCount limit implied by 16-bit instanceSize */ fvar_head.axisCount > 0x3FFE || fvar_head.instanceSize != 4 + 4 * fvar_head.axisCount || /* instanceCount limit implied by limited range of name IDs */ fvar_head.instanceCount > 0x7EFF || fvar_head.offsetToData + fvar_head.axisCount * 20U + fvar_head.instanceCount * fvar_head.instanceSize > table_len ) { error = TT_Err_Invalid_Table; goto Exit; } if ( FT_NEW( face->blend ) ) goto Exit; /* cannot overflow 32-bit arithmetic because of limits above */ face->blend->mmvar_len = sizeof ( FT_MM_Var ) + fvar_head.axisCount * sizeof ( FT_Var_Axis ) + fvar_head.instanceCount * sizeof ( FT_Var_Named_Style ) + fvar_head.instanceCount * fvar_head.axisCount * sizeof ( FT_Fixed ) + 5 * fvar_head.axisCount; if ( FT_ALLOC( mmvar, face->blend->mmvar_len ) ) goto Exit; face->blend->mmvar = mmvar; mmvar->num_axis = fvar_head.axisCount; mmvar->num_designs = (FT_UInt)-1; /* meaningless in this context; each glyph */ /* may have a different number of designs */ /* (or tuples, as called by Apple) */ mmvar->num_namedstyles = fvar_head.instanceCount; mmvar->axis = (FT_Var_Axis*)&(mmvar[1]); mmvar->namedstyle = (FT_Var_Named_Style*)&(mmvar->axis[fvar_head.axisCount]); next_coords = (FT_Fixed*)&(mmvar->namedstyle[fvar_head.instanceCount]); for ( i = 0; i < fvar_head.instanceCount; ++i ) { mmvar->namedstyle[i].coords = next_coords; next_coords += fvar_head.axisCount; } next_name = (FT_String*)next_coords; for ( i = 0; i < fvar_head.axisCount; ++i ) { mmvar->axis[i].name = next_name; next_name += 5; } if ( FT_STREAM_SEEK( fvar_start + fvar_head.offsetToData ) ) goto Exit; a = mmvar->axis; for ( i = 0; i < fvar_head.axisCount; ++i ) { GX_FVar_Axis axis_rec; if ( FT_STREAM_READ_FIELDS( fvaraxis_fields, &axis_rec ) ) goto Exit; a->tag = axis_rec.axisTag; a->minimum = axis_rec.minValue; /* A Fixed */ a->def = axis_rec.defaultValue; /* A Fixed */ a->maximum = axis_rec.maxValue; /* A Fixed */ a->strid = axis_rec.nameID; a->name[0] = (FT_String)( a->tag >> 24 ); a->name[1] = (FT_String)( ( a->tag >> 16 ) & 0xFF ); a->name[2] = (FT_String)( ( a->tag >> 8 ) & 0xFF ); a->name[3] = (FT_String)( ( a->tag ) & 0xFF ); a->name[4] = 0; ++a; } ns = mmvar->namedstyle; for ( i = 0; i < fvar_head.instanceCount; ++i, ++ns ) { if ( FT_FRAME_ENTER( 4L + 4L * fvar_head.axisCount ) ) goto Exit; ns->strid = FT_GET_USHORT(); (void) /* flags = */ FT_GET_USHORT(); for ( j = 0; j < fvar_head.axisCount; ++j ) ns->coords[j] = FT_GET_ULONG(); /* A Fixed */ FT_FRAME_EXIT(); } } if ( master != NULL ) { FT_UInt n; if ( FT_ALLOC( mmvar, face->blend->mmvar_len ) ) goto Exit; FT_MEM_COPY( mmvar, face->blend->mmvar, face->blend->mmvar_len ); mmvar->axis = (FT_Var_Axis*)&(mmvar[1]); mmvar->namedstyle = (FT_Var_Named_Style*)&(mmvar->axis[mmvar->num_axis]); next_coords = (FT_Fixed*)&(mmvar->namedstyle[mmvar->num_namedstyles]); for ( n = 0; n < mmvar->num_namedstyles; ++n ) { mmvar->namedstyle[n].coords = next_coords; next_coords += mmvar->num_axis; } a = mmvar->axis; next_name = (FT_String*)next_coords; for ( n = 0; n < mmvar->num_axis; ++n ) { a->name = next_name; /* standard PostScript names for some standard apple tags */ if ( a->tag == TTAG_wght ) a->name = (char *)"Weight"; else if ( a->tag == TTAG_wdth ) a->name = (char *)"Width"; else if ( a->tag == TTAG_opsz ) a->name = (char *)"OpticalSize"; else if ( a->tag == TTAG_slnt ) a->name = (char *)"Slant"; next_name += 5; ++a; } *master = mmvar; } Exit: return error; }
DoS Exec Code Overflow
0
TT_Get_MM_Var( TT_Face face, FT_MM_Var* *master ) { FT_Stream stream = face->root.stream; FT_Memory memory = face->root.memory; FT_ULong table_len; FT_Error error = TT_Err_Ok; FT_ULong fvar_start; FT_Int i, j; FT_MM_Var* mmvar; FT_Fixed* next_coords; FT_String* next_name; FT_Var_Axis* a; FT_Var_Named_Style* ns; GX_FVar_Head fvar_head; static const FT_Frame_Field fvar_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE GX_FVar_Head FT_FRAME_START( 16 ), FT_FRAME_LONG ( version ), FT_FRAME_USHORT( offsetToData ), FT_FRAME_USHORT( countSizePairs ), FT_FRAME_USHORT( axisCount ), FT_FRAME_USHORT( axisSize ), FT_FRAME_USHORT( instanceCount ), FT_FRAME_USHORT( instanceSize ), FT_FRAME_END }; static const FT_Frame_Field fvaraxis_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE GX_FVar_Axis FT_FRAME_START( 20 ), FT_FRAME_ULONG ( axisTag ), FT_FRAME_ULONG ( minValue ), FT_FRAME_ULONG ( defaultValue ), FT_FRAME_ULONG ( maxValue ), FT_FRAME_USHORT( flags ), FT_FRAME_USHORT( nameID ), FT_FRAME_END }; if ( face->blend == NULL ) { /* both `fvar' and `gvar' must be present */ if ( (error = face->goto_table( face, TTAG_gvar, stream, &table_len )) != 0 ) goto Exit; if ( (error = face->goto_table( face, TTAG_fvar, stream, &table_len )) != 0 ) goto Exit; fvar_start = FT_STREAM_POS( ); if ( FT_STREAM_READ_FIELDS( fvar_fields, &fvar_head ) ) goto Exit; if ( fvar_head.version != (FT_Long)0x00010000L || fvar_head.countSizePairs != 2 || fvar_head.axisSize != 20 || /* axisCount limit implied by 16-bit instanceSize */ fvar_head.axisCount > 0x3FFE || fvar_head.instanceSize != 4 + 4 * fvar_head.axisCount || /* instanceCount limit implied by limited range of name IDs */ fvar_head.instanceCount > 0x7EFF || fvar_head.offsetToData + fvar_head.axisCount * 20U + fvar_head.instanceCount * fvar_head.instanceSize > table_len ) { error = TT_Err_Invalid_Table; goto Exit; } if ( FT_NEW( face->blend ) ) goto Exit; /* cannot overflow 32-bit arithmetic because of limits above */ face->blend->mmvar_len = sizeof ( FT_MM_Var ) + fvar_head.axisCount * sizeof ( FT_Var_Axis ) + fvar_head.instanceCount * sizeof ( FT_Var_Named_Style ) + fvar_head.instanceCount * fvar_head.axisCount * sizeof ( FT_Fixed ) + 5 * fvar_head.axisCount; if ( FT_ALLOC( mmvar, face->blend->mmvar_len ) ) goto Exit; face->blend->mmvar = mmvar; mmvar->num_axis = fvar_head.axisCount; mmvar->num_designs = (FT_UInt)-1; /* meaningless in this context; each glyph */ /* may have a different number of designs */ /* (or tuples, as called by Apple) */ mmvar->num_namedstyles = fvar_head.instanceCount; mmvar->axis = (FT_Var_Axis*)&(mmvar[1]); mmvar->namedstyle = (FT_Var_Named_Style*)&(mmvar->axis[fvar_head.axisCount]); next_coords = (FT_Fixed*)&(mmvar->namedstyle[fvar_head.instanceCount]); for ( i = 0; i < fvar_head.instanceCount; ++i ) { mmvar->namedstyle[i].coords = next_coords; next_coords += fvar_head.axisCount; } next_name = (FT_String*)next_coords; for ( i = 0; i < fvar_head.axisCount; ++i ) { mmvar->axis[i].name = next_name; next_name += 5; } if ( FT_STREAM_SEEK( fvar_start + fvar_head.offsetToData ) ) goto Exit; a = mmvar->axis; for ( i = 0; i < fvar_head.axisCount; ++i ) { GX_FVar_Axis axis_rec; if ( FT_STREAM_READ_FIELDS( fvaraxis_fields, &axis_rec ) ) goto Exit; a->tag = axis_rec.axisTag; a->minimum = axis_rec.minValue; /* A Fixed */ a->def = axis_rec.defaultValue; /* A Fixed */ a->maximum = axis_rec.maxValue; /* A Fixed */ a->strid = axis_rec.nameID; a->name[0] = (FT_String)( a->tag >> 24 ); a->name[1] = (FT_String)( ( a->tag >> 16 ) & 0xFF ); a->name[2] = (FT_String)( ( a->tag >> 8 ) & 0xFF ); a->name[3] = (FT_String)( ( a->tag ) & 0xFF ); a->name[4] = 0; ++a; } ns = mmvar->namedstyle; for ( i = 0; i < fvar_head.instanceCount; ++i, ++ns ) { if ( FT_FRAME_ENTER( 4L + 4L * fvar_head.axisCount ) ) goto Exit; ns->strid = FT_GET_USHORT(); (void) /* flags = */ FT_GET_USHORT(); for ( j = 0; j < fvar_head.axisCount; ++j ) ns->coords[j] = FT_GET_ULONG(); /* A Fixed */ FT_FRAME_EXIT(); } } if ( master != NULL ) { FT_UInt n; if ( FT_ALLOC( mmvar, face->blend->mmvar_len ) ) goto Exit; FT_MEM_COPY( mmvar, face->blend->mmvar, face->blend->mmvar_len ); mmvar->axis = (FT_Var_Axis*)&(mmvar[1]); mmvar->namedstyle = (FT_Var_Named_Style*)&(mmvar->axis[mmvar->num_axis]); next_coords = (FT_Fixed*)&(mmvar->namedstyle[mmvar->num_namedstyles]); for ( n = 0; n < mmvar->num_namedstyles; ++n ) { mmvar->namedstyle[n].coords = next_coords; next_coords += mmvar->num_axis; } a = mmvar->axis; next_name = (FT_String*)next_coords; for ( n = 0; n < mmvar->num_axis; ++n ) { a->name = next_name; /* standard PostScript names for some standard apple tags */ if ( a->tag == TTAG_wght ) a->name = (char *)"Weight"; else if ( a->tag == TTAG_wdth ) a->name = (char *)"Width"; else if ( a->tag == TTAG_opsz ) a->name = (char *)"OpticalSize"; else if ( a->tag == TTAG_slnt ) a->name = (char *)"Slant"; next_name += 5; ++a; } *master = mmvar; } Exit: return error; }
@@ -130,7 +130,7 @@ FT_Int j; FT_Int first; FT_Memory memory = stream->memory; - FT_Error error = TT_Err_Ok; + FT_Error error = TT_Err_Ok; FT_UNUSED( error ); @@ -154,7 +154,7 @@ runcnt = runcnt & GX_PT_POINT_RUN_COUNT_MASK; first = points[i++] = FT_GET_USHORT(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; /* first point not included in runcount */ @@ -165,7 +165,7 @@ { first = points[i++] = FT_GET_BYTE(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; for ( j = 0; j < runcnt; ++j )
CWE-119
null
null
6,148
TT_Set_MM_Blend( TT_Face face, FT_UInt num_coords, FT_Fixed* coords ) { FT_Error error = TT_Err_Ok; GX_Blend blend; FT_MM_Var* mmvar; FT_UInt i; FT_Memory memory = face->root.memory; enum { mcvt_retain, mcvt_modify, mcvt_load } manageCvt; face->doblend = FALSE; if ( face->blend == NULL ) { if ( (error = TT_Get_MM_Var( face, NULL)) != 0 ) goto Exit; } blend = face->blend; mmvar = blend->mmvar; if ( num_coords != mmvar->num_axis ) { error = TT_Err_Invalid_Argument; goto Exit; } for ( i = 0; i < num_coords; ++i ) if ( coords[i] < -0x00010000L || coords[i] > 0x00010000L ) { error = TT_Err_Invalid_Argument; goto Exit; } if ( blend->glyphoffsets == NULL ) if ( (error = ft_var_load_gvar( face )) != 0 ) goto Exit; if ( blend->normalizedcoords == NULL ) { if ( FT_NEW_ARRAY( blend->normalizedcoords, num_coords ) ) goto Exit; manageCvt = mcvt_modify; /* If we have not set the blend coordinates before this, then the */ /* cvt table will still be what we read from the `cvt ' table and */ /* we don't need to reload it. We may need to change it though... */ } else { manageCvt = mcvt_retain; for ( i = 0; i < num_coords; ++i ) { if ( blend->normalizedcoords[i] != coords[i] ) { manageCvt = mcvt_load; break; } } /* If we don't change the blend coords then we don't need to do */ /* anything to the cvt table. It will be correct. Otherwise we */ /* no longer have the original cvt (it was modified when we set */ /* the blend last time), so we must reload and then modify it. */ } blend->num_axis = num_coords; FT_MEM_COPY( blend->normalizedcoords, coords, num_coords * sizeof ( FT_Fixed ) ); face->doblend = TRUE; if ( face->cvt != NULL ) { switch ( manageCvt ) { case mcvt_load: /* The cvt table has been loaded already; every time we change the */ /* blend we may need to reload and remodify the cvt table. */ FT_FREE( face->cvt ); face->cvt = NULL; tt_face_load_cvt( face, face->root.stream ); break; case mcvt_modify: /* The original cvt table is in memory. All we need to do is */ /* apply the `cvar' table (if any). */ tt_face_vary_cvt( face, face->root.stream ); break; case mcvt_retain: /* The cvt table is correct for this set of coordinates. */ break; } } Exit: return error; }
DoS Exec Code Overflow
0
TT_Set_MM_Blend( TT_Face face, FT_UInt num_coords, FT_Fixed* coords ) { FT_Error error = TT_Err_Ok; GX_Blend blend; FT_MM_Var* mmvar; FT_UInt i; FT_Memory memory = face->root.memory; enum { mcvt_retain, mcvt_modify, mcvt_load } manageCvt; face->doblend = FALSE; if ( face->blend == NULL ) { if ( (error = TT_Get_MM_Var( face, NULL)) != 0 ) goto Exit; } blend = face->blend; mmvar = blend->mmvar; if ( num_coords != mmvar->num_axis ) { error = TT_Err_Invalid_Argument; goto Exit; } for ( i = 0; i < num_coords; ++i ) if ( coords[i] < -0x00010000L || coords[i] > 0x00010000L ) { error = TT_Err_Invalid_Argument; goto Exit; } if ( blend->glyphoffsets == NULL ) if ( (error = ft_var_load_gvar( face )) != 0 ) goto Exit; if ( blend->normalizedcoords == NULL ) { if ( FT_NEW_ARRAY( blend->normalizedcoords, num_coords ) ) goto Exit; manageCvt = mcvt_modify; /* If we have not set the blend coordinates before this, then the */ /* cvt table will still be what we read from the `cvt ' table and */ /* we don't need to reload it. We may need to change it though... */ } else { manageCvt = mcvt_retain; for ( i = 0; i < num_coords; ++i ) { if ( blend->normalizedcoords[i] != coords[i] ) { manageCvt = mcvt_load; break; } } /* If we don't change the blend coords then we don't need to do */ /* anything to the cvt table. It will be correct. Otherwise we */ /* no longer have the original cvt (it was modified when we set */ /* the blend last time), so we must reload and then modify it. */ } blend->num_axis = num_coords; FT_MEM_COPY( blend->normalizedcoords, coords, num_coords * sizeof ( FT_Fixed ) ); face->doblend = TRUE; if ( face->cvt != NULL ) { switch ( manageCvt ) { case mcvt_load: /* The cvt table has been loaded already; every time we change the */ /* blend we may need to reload and remodify the cvt table. */ FT_FREE( face->cvt ); face->cvt = NULL; tt_face_load_cvt( face, face->root.stream ); break; case mcvt_modify: /* The original cvt table is in memory. All we need to do is */ /* apply the `cvar' table (if any). */ tt_face_vary_cvt( face, face->root.stream ); break; case mcvt_retain: /* The cvt table is correct for this set of coordinates. */ break; } } Exit: return error; }
@@ -130,7 +130,7 @@ FT_Int j; FT_Int first; FT_Memory memory = stream->memory; - FT_Error error = TT_Err_Ok; + FT_Error error = TT_Err_Ok; FT_UNUSED( error ); @@ -154,7 +154,7 @@ runcnt = runcnt & GX_PT_POINT_RUN_COUNT_MASK; first = points[i++] = FT_GET_USHORT(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; /* first point not included in runcount */ @@ -165,7 +165,7 @@ { first = points[i++] = FT_GET_BYTE(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; for ( j = 0; j < runcnt; ++j )
CWE-119
null
null
6,149
TT_Set_Var_Design( TT_Face face, FT_UInt num_coords, FT_Fixed* coords ) { FT_Error error = TT_Err_Ok; FT_Fixed* normalized = NULL; GX_Blend blend; FT_MM_Var* mmvar; FT_UInt i, j; FT_Var_Axis* a; GX_AVarSegment av; FT_Memory memory = face->root.memory; if ( face->blend == NULL ) { if ( (error = TT_Get_MM_Var( face, NULL )) != 0 ) goto Exit; } blend = face->blend; mmvar = blend->mmvar; if ( num_coords != mmvar->num_axis ) { error = TT_Err_Invalid_Argument; goto Exit; } /* Axis normalization is a two stage process. First we normalize */ /* based on the [min,def,max] values for the axis to be [-1,0,1]. */ /* Then, if there's an `avar' table, we renormalize this range. */ if ( FT_NEW_ARRAY( normalized, mmvar->num_axis ) ) goto Exit; a = mmvar->axis; for ( i = 0; i < mmvar->num_axis; ++i, ++a ) { if ( coords[i] > a->maximum || coords[i] < a->minimum ) { error = TT_Err_Invalid_Argument; goto Exit; } if ( coords[i] < a->def ) { normalized[i] = -FT_MulDiv( coords[i] - a->def, 0x10000L, a->minimum - a->def ); } else if ( a->maximum == a->def ) normalized[i] = 0; else { normalized[i] = FT_MulDiv( coords[i] - a->def, 0x10000L, a->maximum - a->def ); } } if ( !blend->avar_checked ) ft_var_load_avar( face ); if ( blend->avar_segment != NULL ) { av = blend->avar_segment; for ( i = 0; i < mmvar->num_axis; ++i, ++av ) { for ( j = 1; j < (FT_UInt)av->pairCount; ++j ) if ( normalized[i] < av->correspondence[j].fromCoord ) { normalized[i] = FT_MulDiv( FT_MulDiv( normalized[i] - av->correspondence[j - 1].fromCoord, 0x10000L, av->correspondence[j].fromCoord - av->correspondence[j - 1].fromCoord ), av->correspondence[j].toCoord - av->correspondence[j - 1].toCoord, 0x10000L ) + av->correspondence[j - 1].toCoord; break; } } } error = TT_Set_MM_Blend( face, num_coords, normalized ); Exit: FT_FREE( normalized ); return error; }
DoS Exec Code Overflow
0
TT_Set_Var_Design( TT_Face face, FT_UInt num_coords, FT_Fixed* coords ) { FT_Error error = TT_Err_Ok; FT_Fixed* normalized = NULL; GX_Blend blend; FT_MM_Var* mmvar; FT_UInt i, j; FT_Var_Axis* a; GX_AVarSegment av; FT_Memory memory = face->root.memory; if ( face->blend == NULL ) { if ( (error = TT_Get_MM_Var( face, NULL )) != 0 ) goto Exit; } blend = face->blend; mmvar = blend->mmvar; if ( num_coords != mmvar->num_axis ) { error = TT_Err_Invalid_Argument; goto Exit; } /* Axis normalization is a two stage process. First we normalize */ /* based on the [min,def,max] values for the axis to be [-1,0,1]. */ /* Then, if there's an `avar' table, we renormalize this range. */ if ( FT_NEW_ARRAY( normalized, mmvar->num_axis ) ) goto Exit; a = mmvar->axis; for ( i = 0; i < mmvar->num_axis; ++i, ++a ) { if ( coords[i] > a->maximum || coords[i] < a->minimum ) { error = TT_Err_Invalid_Argument; goto Exit; } if ( coords[i] < a->def ) { normalized[i] = -FT_MulDiv( coords[i] - a->def, 0x10000L, a->minimum - a->def ); } else if ( a->maximum == a->def ) normalized[i] = 0; else { normalized[i] = FT_MulDiv( coords[i] - a->def, 0x10000L, a->maximum - a->def ); } } if ( !blend->avar_checked ) ft_var_load_avar( face ); if ( blend->avar_segment != NULL ) { av = blend->avar_segment; for ( i = 0; i < mmvar->num_axis; ++i, ++av ) { for ( j = 1; j < (FT_UInt)av->pairCount; ++j ) if ( normalized[i] < av->correspondence[j].fromCoord ) { normalized[i] = FT_MulDiv( FT_MulDiv( normalized[i] - av->correspondence[j - 1].fromCoord, 0x10000L, av->correspondence[j].fromCoord - av->correspondence[j - 1].fromCoord ), av->correspondence[j].toCoord - av->correspondence[j - 1].toCoord, 0x10000L ) + av->correspondence[j - 1].toCoord; break; } } } error = TT_Set_MM_Blend( face, num_coords, normalized ); Exit: FT_FREE( normalized ); return error; }
@@ -130,7 +130,7 @@ FT_Int j; FT_Int first; FT_Memory memory = stream->memory; - FT_Error error = TT_Err_Ok; + FT_Error error = TT_Err_Ok; FT_UNUSED( error ); @@ -154,7 +154,7 @@ runcnt = runcnt & GX_PT_POINT_RUN_COUNT_MASK; first = points[i++] = FT_GET_USHORT(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; /* first point not included in runcount */ @@ -165,7 +165,7 @@ { first = points[i++] = FT_GET_BYTE(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; for ( j = 0; j < runcnt; ++j )
CWE-119
null
null
6,150
TT_Vary_Get_Glyph_Deltas( TT_Face face, FT_UInt glyph_index, FT_Vector* *deltas, FT_UInt n_points ) { FT_Stream stream = face->root.stream; FT_Memory memory = stream->memory; GX_Blend blend = face->blend; FT_Vector* delta_xy; FT_Error error; FT_ULong glyph_start; FT_UInt tupleCount; FT_ULong offsetToData; FT_ULong here; FT_UInt i, j; FT_Fixed* tuple_coords = NULL; FT_Fixed* im_start_coords = NULL; FT_Fixed* im_end_coords = NULL; FT_UInt point_count, spoint_count = 0; FT_UShort* sharedpoints = NULL; FT_UShort* localpoints = NULL; FT_UShort* points; FT_Short *deltas_x, *deltas_y; if ( !face->doblend || blend == NULL ) return TT_Err_Invalid_Argument; /* to be freed by the caller */ if ( FT_NEW_ARRAY( delta_xy, n_points ) ) goto Exit; *deltas = delta_xy; if ( glyph_index >= blend->gv_glyphcnt || blend->glyphoffsets[glyph_index] == blend->glyphoffsets[glyph_index + 1] ) return TT_Err_Ok; /* no variation data for this glyph */ if ( FT_STREAM_SEEK( blend->glyphoffsets[glyph_index] ) || FT_FRAME_ENTER( blend->glyphoffsets[glyph_index + 1] - blend->glyphoffsets[glyph_index] ) ) goto Fail1; glyph_start = FT_Stream_FTell( stream ); /* each set of glyph variation data is formatted similarly to `cvar' */ /* (except we get shared points and global tuples) */ if ( FT_NEW_ARRAY( tuple_coords, blend->num_axis ) || FT_NEW_ARRAY( im_start_coords, blend->num_axis ) || FT_NEW_ARRAY( im_end_coords, blend->num_axis ) ) goto Fail2; tupleCount = FT_GET_USHORT(); offsetToData = glyph_start + FT_GET_USHORT(); if ( tupleCount & GX_TC_TUPLES_SHARE_POINT_NUMBERS ) { here = FT_Stream_FTell( stream ); FT_Stream_SeekSet( stream, offsetToData ); sharedpoints = ft_var_readpackedpoints( stream, &spoint_count ); offsetToData = FT_Stream_FTell( stream ); FT_Stream_SeekSet( stream, here ); } for ( i = 0; i < ( tupleCount & GX_TC_TUPLE_COUNT_MASK ); ++i ) { FT_UInt tupleDataSize; FT_UInt tupleIndex; FT_Fixed apply; tupleDataSize = FT_GET_USHORT(); tupleIndex = FT_GET_USHORT(); if ( tupleIndex & GX_TI_EMBEDDED_TUPLE_COORD ) { for ( j = 0; j < blend->num_axis; ++j ) tuple_coords[j] = FT_GET_SHORT() << 2; /* convert from */ /* short frac to fixed */ } else if ( ( tupleIndex & GX_TI_TUPLE_INDEX_MASK ) >= blend->tuplecount ) { error = TT_Err_Invalid_Table; goto Fail3; } else { FT_MEM_COPY( tuple_coords, &blend->tuplecoords[(tupleIndex & 0xFFF) * blend->num_axis], blend->num_axis * sizeof ( FT_Fixed ) ); } if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) { for ( j = 0; j < blend->num_axis; ++j ) im_start_coords[j] = FT_GET_SHORT() << 2; for ( j = 0; j < blend->num_axis; ++j ) im_end_coords[j] = FT_GET_SHORT() << 2; } apply = ft_var_apply_tuple( blend, (FT_UShort)tupleIndex, tuple_coords, im_start_coords, im_end_coords ); if ( apply == 0 ) /* tuple isn't active for our blend */ { offsetToData += tupleDataSize; continue; } here = FT_Stream_FTell( stream ); if ( tupleIndex & GX_TI_PRIVATE_POINT_NUMBERS ) { FT_Stream_SeekSet( stream, offsetToData ); localpoints = ft_var_readpackedpoints( stream, &point_count ); points = localpoints; } else { points = sharedpoints; point_count = spoint_count; } deltas_x = ft_var_readpackeddeltas( stream, point_count == 0 ? n_points : point_count ); deltas_y = ft_var_readpackeddeltas( stream, point_count == 0 ? n_points : point_count ); if ( points == NULL || deltas_y == NULL || deltas_x == NULL ) ; /* failure, ignore it */ else if ( points == ALL_POINTS ) { /* this means that there are deltas for every point in the glyph */ for ( j = 0; j < n_points; ++j ) { delta_xy[j].x += FT_MulFix( deltas_x[j], apply ); delta_xy[j].y += FT_MulFix( deltas_y[j], apply ); } } else { for ( j = 0; j < point_count; ++j ) { delta_xy[localpoints[j]].x += FT_MulFix( deltas_x[j], apply ); delta_xy[localpoints[j]].y += FT_MulFix( deltas_y[j], apply ); } } if ( localpoints != ALL_POINTS ) FT_FREE( localpoints ); FT_FREE( deltas_x ); FT_FREE( deltas_y ); offsetToData += tupleDataSize; FT_Stream_SeekSet( stream, here ); } Fail3: FT_FREE( tuple_coords ); FT_FREE( im_start_coords ); FT_FREE( im_end_coords ); Fail2: FT_FRAME_EXIT(); Fail1: if ( error ) { FT_FREE( delta_xy ); *deltas = NULL; } Exit: return error; }
DoS Exec Code Overflow
0
TT_Vary_Get_Glyph_Deltas( TT_Face face, FT_UInt glyph_index, FT_Vector* *deltas, FT_UInt n_points ) { FT_Stream stream = face->root.stream; FT_Memory memory = stream->memory; GX_Blend blend = face->blend; FT_Vector* delta_xy; FT_Error error; FT_ULong glyph_start; FT_UInt tupleCount; FT_ULong offsetToData; FT_ULong here; FT_UInt i, j; FT_Fixed* tuple_coords = NULL; FT_Fixed* im_start_coords = NULL; FT_Fixed* im_end_coords = NULL; FT_UInt point_count, spoint_count = 0; FT_UShort* sharedpoints = NULL; FT_UShort* localpoints = NULL; FT_UShort* points; FT_Short *deltas_x, *deltas_y; if ( !face->doblend || blend == NULL ) return TT_Err_Invalid_Argument; /* to be freed by the caller */ if ( FT_NEW_ARRAY( delta_xy, n_points ) ) goto Exit; *deltas = delta_xy; if ( glyph_index >= blend->gv_glyphcnt || blend->glyphoffsets[glyph_index] == blend->glyphoffsets[glyph_index + 1] ) return TT_Err_Ok; /* no variation data for this glyph */ if ( FT_STREAM_SEEK( blend->glyphoffsets[glyph_index] ) || FT_FRAME_ENTER( blend->glyphoffsets[glyph_index + 1] - blend->glyphoffsets[glyph_index] ) ) goto Fail1; glyph_start = FT_Stream_FTell( stream ); /* each set of glyph variation data is formatted similarly to `cvar' */ /* (except we get shared points and global tuples) */ if ( FT_NEW_ARRAY( tuple_coords, blend->num_axis ) || FT_NEW_ARRAY( im_start_coords, blend->num_axis ) || FT_NEW_ARRAY( im_end_coords, blend->num_axis ) ) goto Fail2; tupleCount = FT_GET_USHORT(); offsetToData = glyph_start + FT_GET_USHORT(); if ( tupleCount & GX_TC_TUPLES_SHARE_POINT_NUMBERS ) { here = FT_Stream_FTell( stream ); FT_Stream_SeekSet( stream, offsetToData ); sharedpoints = ft_var_readpackedpoints( stream, &spoint_count ); offsetToData = FT_Stream_FTell( stream ); FT_Stream_SeekSet( stream, here ); } for ( i = 0; i < ( tupleCount & GX_TC_TUPLE_COUNT_MASK ); ++i ) { FT_UInt tupleDataSize; FT_UInt tupleIndex; FT_Fixed apply; tupleDataSize = FT_GET_USHORT(); tupleIndex = FT_GET_USHORT(); if ( tupleIndex & GX_TI_EMBEDDED_TUPLE_COORD ) { for ( j = 0; j < blend->num_axis; ++j ) tuple_coords[j] = FT_GET_SHORT() << 2; /* convert from */ /* short frac to fixed */ } else if ( ( tupleIndex & GX_TI_TUPLE_INDEX_MASK ) >= blend->tuplecount ) { error = TT_Err_Invalid_Table; goto Fail3; } else { FT_MEM_COPY( tuple_coords, &blend->tuplecoords[(tupleIndex & 0xFFF) * blend->num_axis], blend->num_axis * sizeof ( FT_Fixed ) ); } if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) { for ( j = 0; j < blend->num_axis; ++j ) im_start_coords[j] = FT_GET_SHORT() << 2; for ( j = 0; j < blend->num_axis; ++j ) im_end_coords[j] = FT_GET_SHORT() << 2; } apply = ft_var_apply_tuple( blend, (FT_UShort)tupleIndex, tuple_coords, im_start_coords, im_end_coords ); if ( apply == 0 ) /* tuple isn't active for our blend */ { offsetToData += tupleDataSize; continue; } here = FT_Stream_FTell( stream ); if ( tupleIndex & GX_TI_PRIVATE_POINT_NUMBERS ) { FT_Stream_SeekSet( stream, offsetToData ); localpoints = ft_var_readpackedpoints( stream, &point_count ); points = localpoints; } else { points = sharedpoints; point_count = spoint_count; } deltas_x = ft_var_readpackeddeltas( stream, point_count == 0 ? n_points : point_count ); deltas_y = ft_var_readpackeddeltas( stream, point_count == 0 ? n_points : point_count ); if ( points == NULL || deltas_y == NULL || deltas_x == NULL ) ; /* failure, ignore it */ else if ( points == ALL_POINTS ) { /* this means that there are deltas for every point in the glyph */ for ( j = 0; j < n_points; ++j ) { delta_xy[j].x += FT_MulFix( deltas_x[j], apply ); delta_xy[j].y += FT_MulFix( deltas_y[j], apply ); } } else { for ( j = 0; j < point_count; ++j ) { delta_xy[localpoints[j]].x += FT_MulFix( deltas_x[j], apply ); delta_xy[localpoints[j]].y += FT_MulFix( deltas_y[j], apply ); } } if ( localpoints != ALL_POINTS ) FT_FREE( localpoints ); FT_FREE( deltas_x ); FT_FREE( deltas_y ); offsetToData += tupleDataSize; FT_Stream_SeekSet( stream, here ); } Fail3: FT_FREE( tuple_coords ); FT_FREE( im_start_coords ); FT_FREE( im_end_coords ); Fail2: FT_FRAME_EXIT(); Fail1: if ( error ) { FT_FREE( delta_xy ); *deltas = NULL; } Exit: return error; }
@@ -130,7 +130,7 @@ FT_Int j; FT_Int first; FT_Memory memory = stream->memory; - FT_Error error = TT_Err_Ok; + FT_Error error = TT_Err_Ok; FT_UNUSED( error ); @@ -154,7 +154,7 @@ runcnt = runcnt & GX_PT_POINT_RUN_COUNT_MASK; first = points[i++] = FT_GET_USHORT(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; /* first point not included in runcount */ @@ -165,7 +165,7 @@ { first = points[i++] = FT_GET_BYTE(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; for ( j = 0; j < runcnt; ++j )
CWE-119
null
null
6,151
ft_var_apply_tuple( GX_Blend blend, FT_UShort tupleIndex, FT_Fixed* tuple_coords, FT_Fixed* im_start_coords, FT_Fixed* im_end_coords ) { FT_UInt i; FT_Fixed apply; FT_Fixed temp; apply = 0x10000L; for ( i = 0; i < blend->num_axis; ++i ) { if ( tuple_coords[i] == 0 ) /* It's not clear why (for intermediate tuples) we don't need */ /* to check against start/end -- the documentation says we don't. */ /* Similarly, it's unclear why we don't need to scale along the */ /* axis. */ continue; else if ( blend->normalizedcoords[i] == 0 || ( blend->normalizedcoords[i] < 0 && tuple_coords[i] > 0 ) || ( blend->normalizedcoords[i] > 0 && tuple_coords[i] < 0 ) ) { apply = 0; break; } else if ( !( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) ) /* not an intermediate tuple */ apply = FT_MulDiv( apply, blend->normalizedcoords[i] > 0 ? blend->normalizedcoords[i] : -blend->normalizedcoords[i], 0x10000L ); else if ( blend->normalizedcoords[i] <= im_start_coords[i] || blend->normalizedcoords[i] >= im_end_coords[i] ) { apply = 0; break; } else if ( blend->normalizedcoords[i] < tuple_coords[i] ) { temp = FT_MulDiv( blend->normalizedcoords[i] - im_start_coords[i], 0x10000L, tuple_coords[i] - im_start_coords[i]); apply = FT_MulDiv( apply, temp, 0x10000L ); } else { temp = FT_MulDiv( im_end_coords[i] - blend->normalizedcoords[i], 0x10000L, im_end_coords[i] - tuple_coords[i] ); apply = FT_MulDiv( apply, temp, 0x10000L ); } } return apply; }
DoS Exec Code Overflow
0
ft_var_apply_tuple( GX_Blend blend, FT_UShort tupleIndex, FT_Fixed* tuple_coords, FT_Fixed* im_start_coords, FT_Fixed* im_end_coords ) { FT_UInt i; FT_Fixed apply; FT_Fixed temp; apply = 0x10000L; for ( i = 0; i < blend->num_axis; ++i ) { if ( tuple_coords[i] == 0 ) /* It's not clear why (for intermediate tuples) we don't need */ /* to check against start/end -- the documentation says we don't. */ /* Similarly, it's unclear why we don't need to scale along the */ /* axis. */ continue; else if ( blend->normalizedcoords[i] == 0 || ( blend->normalizedcoords[i] < 0 && tuple_coords[i] > 0 ) || ( blend->normalizedcoords[i] > 0 && tuple_coords[i] < 0 ) ) { apply = 0; break; } else if ( !( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) ) /* not an intermediate tuple */ apply = FT_MulDiv( apply, blend->normalizedcoords[i] > 0 ? blend->normalizedcoords[i] : -blend->normalizedcoords[i], 0x10000L ); else if ( blend->normalizedcoords[i] <= im_start_coords[i] || blend->normalizedcoords[i] >= im_end_coords[i] ) { apply = 0; break; } else if ( blend->normalizedcoords[i] < tuple_coords[i] ) { temp = FT_MulDiv( blend->normalizedcoords[i] - im_start_coords[i], 0x10000L, tuple_coords[i] - im_start_coords[i]); apply = FT_MulDiv( apply, temp, 0x10000L ); } else { temp = FT_MulDiv( im_end_coords[i] - blend->normalizedcoords[i], 0x10000L, im_end_coords[i] - tuple_coords[i] ); apply = FT_MulDiv( apply, temp, 0x10000L ); } } return apply; }
@@ -130,7 +130,7 @@ FT_Int j; FT_Int first; FT_Memory memory = stream->memory; - FT_Error error = TT_Err_Ok; + FT_Error error = TT_Err_Ok; FT_UNUSED( error ); @@ -154,7 +154,7 @@ runcnt = runcnt & GX_PT_POINT_RUN_COUNT_MASK; first = points[i++] = FT_GET_USHORT(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; /* first point not included in runcount */ @@ -165,7 +165,7 @@ { first = points[i++] = FT_GET_BYTE(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; for ( j = 0; j < runcnt; ++j )
CWE-119
null
null
6,152
ft_var_load_gvar( TT_Face face ) { FT_Stream stream = FT_FACE_STREAM(face); FT_Memory memory = stream->memory; GX_Blend blend = face->blend; FT_Error error; FT_UInt i, j; FT_ULong table_len; FT_ULong gvar_start; FT_ULong offsetToData; GX_GVar_Head gvar_head; static const FT_Frame_Field gvar_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE GX_GVar_Head FT_FRAME_START( 20 ), FT_FRAME_LONG ( version ), FT_FRAME_USHORT( axisCount ), FT_FRAME_USHORT( globalCoordCount ), FT_FRAME_ULONG ( offsetToCoord ), FT_FRAME_USHORT( glyphCount ), FT_FRAME_USHORT( flags ), FT_FRAME_ULONG ( offsetToData ), FT_FRAME_END }; if ( (error = face->goto_table( face, TTAG_gvar, stream, &table_len )) != 0 ) goto Exit; gvar_start = FT_STREAM_POS( ); if ( FT_STREAM_READ_FIELDS( gvar_fields, &gvar_head ) ) goto Exit; blend->tuplecount = gvar_head.globalCoordCount; blend->gv_glyphcnt = gvar_head.glyphCount; offsetToData = gvar_start + gvar_head.offsetToData; if ( gvar_head.version != (FT_Long)0x00010000L || gvar_head.axisCount != (FT_UShort)blend->mmvar->num_axis ) { error = TT_Err_Invalid_Table; goto Exit; } if ( FT_NEW_ARRAY( blend->glyphoffsets, blend->gv_glyphcnt + 1 ) ) goto Exit; if ( gvar_head.flags & 1 ) { /* long offsets (one more offset than glyphs, to mark size of last) */ if ( FT_FRAME_ENTER( ( blend->gv_glyphcnt + 1 ) * 4L ) ) goto Exit; for ( i = 0; i <= blend->gv_glyphcnt; ++i ) blend->glyphoffsets[i] = offsetToData + FT_GET_LONG(); FT_FRAME_EXIT(); } else { /* short offsets (one more offset than glyphs, to mark size of last) */ if ( FT_FRAME_ENTER( ( blend->gv_glyphcnt + 1 ) * 2L ) ) goto Exit; for ( i = 0; i <= blend->gv_glyphcnt; ++i ) blend->glyphoffsets[i] = offsetToData + FT_GET_USHORT() * 2; /* XXX: Undocumented: `*2'! */ FT_FRAME_EXIT(); } if ( blend->tuplecount != 0 ) { if ( FT_NEW_ARRAY( blend->tuplecoords, gvar_head.axisCount * blend->tuplecount ) ) goto Exit; if ( FT_STREAM_SEEK( gvar_start + gvar_head.offsetToCoord ) || FT_FRAME_ENTER( blend->tuplecount * gvar_head.axisCount * 2L ) ) goto Exit; for ( i = 0; i < blend->tuplecount; ++i ) for ( j = 0 ; j < (FT_UInt)gvar_head.axisCount; ++j ) blend->tuplecoords[i * gvar_head.axisCount + j] = FT_GET_SHORT() << 2; /* convert to FT_Fixed */ FT_FRAME_EXIT(); } Exit: return error; }
DoS Exec Code Overflow
0
ft_var_load_gvar( TT_Face face ) { FT_Stream stream = FT_FACE_STREAM(face); FT_Memory memory = stream->memory; GX_Blend blend = face->blend; FT_Error error; FT_UInt i, j; FT_ULong table_len; FT_ULong gvar_start; FT_ULong offsetToData; GX_GVar_Head gvar_head; static const FT_Frame_Field gvar_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE GX_GVar_Head FT_FRAME_START( 20 ), FT_FRAME_LONG ( version ), FT_FRAME_USHORT( axisCount ), FT_FRAME_USHORT( globalCoordCount ), FT_FRAME_ULONG ( offsetToCoord ), FT_FRAME_USHORT( glyphCount ), FT_FRAME_USHORT( flags ), FT_FRAME_ULONG ( offsetToData ), FT_FRAME_END }; if ( (error = face->goto_table( face, TTAG_gvar, stream, &table_len )) != 0 ) goto Exit; gvar_start = FT_STREAM_POS( ); if ( FT_STREAM_READ_FIELDS( gvar_fields, &gvar_head ) ) goto Exit; blend->tuplecount = gvar_head.globalCoordCount; blend->gv_glyphcnt = gvar_head.glyphCount; offsetToData = gvar_start + gvar_head.offsetToData; if ( gvar_head.version != (FT_Long)0x00010000L || gvar_head.axisCount != (FT_UShort)blend->mmvar->num_axis ) { error = TT_Err_Invalid_Table; goto Exit; } if ( FT_NEW_ARRAY( blend->glyphoffsets, blend->gv_glyphcnt + 1 ) ) goto Exit; if ( gvar_head.flags & 1 ) { /* long offsets (one more offset than glyphs, to mark size of last) */ if ( FT_FRAME_ENTER( ( blend->gv_glyphcnt + 1 ) * 4L ) ) goto Exit; for ( i = 0; i <= blend->gv_glyphcnt; ++i ) blend->glyphoffsets[i] = offsetToData + FT_GET_LONG(); FT_FRAME_EXIT(); } else { /* short offsets (one more offset than glyphs, to mark size of last) */ if ( FT_FRAME_ENTER( ( blend->gv_glyphcnt + 1 ) * 2L ) ) goto Exit; for ( i = 0; i <= blend->gv_glyphcnt; ++i ) blend->glyphoffsets[i] = offsetToData + FT_GET_USHORT() * 2; /* XXX: Undocumented: `*2'! */ FT_FRAME_EXIT(); } if ( blend->tuplecount != 0 ) { if ( FT_NEW_ARRAY( blend->tuplecoords, gvar_head.axisCount * blend->tuplecount ) ) goto Exit; if ( FT_STREAM_SEEK( gvar_start + gvar_head.offsetToCoord ) || FT_FRAME_ENTER( blend->tuplecount * gvar_head.axisCount * 2L ) ) goto Exit; for ( i = 0; i < blend->tuplecount; ++i ) for ( j = 0 ; j < (FT_UInt)gvar_head.axisCount; ++j ) blend->tuplecoords[i * gvar_head.axisCount + j] = FT_GET_SHORT() << 2; /* convert to FT_Fixed */ FT_FRAME_EXIT(); } Exit: return error; }
@@ -130,7 +130,7 @@ FT_Int j; FT_Int first; FT_Memory memory = stream->memory; - FT_Error error = TT_Err_Ok; + FT_Error error = TT_Err_Ok; FT_UNUSED( error ); @@ -154,7 +154,7 @@ runcnt = runcnt & GX_PT_POINT_RUN_COUNT_MASK; first = points[i++] = FT_GET_USHORT(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; /* first point not included in runcount */ @@ -165,7 +165,7 @@ { first = points[i++] = FT_GET_BYTE(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; for ( j = 0; j < runcnt; ++j )
CWE-119
null
null
6,153
ft_var_readpackeddeltas( FT_Stream stream, FT_Offset delta_cnt ) { FT_Short *deltas = NULL; FT_UInt runcnt; FT_Offset i; FT_UInt j; FT_Memory memory = stream->memory; FT_Error error = TT_Err_Ok; FT_UNUSED( error ); if ( FT_NEW_ARRAY( deltas, delta_cnt ) ) return NULL; i = 0; while ( i < delta_cnt ) { runcnt = FT_GET_BYTE(); if ( runcnt & GX_DT_DELTAS_ARE_ZERO ) { /* runcnt zeroes get added */ for ( j = 0; j <= ( runcnt & GX_DT_DELTA_RUN_COUNT_MASK ) && i < delta_cnt; ++j ) deltas[i++] = 0; } else if ( runcnt & GX_DT_DELTAS_ARE_WORDS ) { /* runcnt shorts from the stack */ for ( j = 0; j <= ( runcnt & GX_DT_DELTA_RUN_COUNT_MASK ) && i < delta_cnt; ++j ) deltas[i++] = FT_GET_SHORT(); } else { /* runcnt signed bytes from the stack */ for ( j = 0; j <= ( runcnt & GX_DT_DELTA_RUN_COUNT_MASK ) && i < delta_cnt; ++j ) deltas[i++] = FT_GET_CHAR(); } if ( j <= ( runcnt & GX_DT_DELTA_RUN_COUNT_MASK ) ) { /* Bad format */ FT_FREE( deltas ); return NULL; } } return deltas; }
DoS Exec Code Overflow
0
ft_var_readpackeddeltas( FT_Stream stream, FT_Offset delta_cnt ) { FT_Short *deltas = NULL; FT_UInt runcnt; FT_Offset i; FT_UInt j; FT_Memory memory = stream->memory; FT_Error error = TT_Err_Ok; FT_UNUSED( error ); if ( FT_NEW_ARRAY( deltas, delta_cnt ) ) return NULL; i = 0; while ( i < delta_cnt ) { runcnt = FT_GET_BYTE(); if ( runcnt & GX_DT_DELTAS_ARE_ZERO ) { /* runcnt zeroes get added */ for ( j = 0; j <= ( runcnt & GX_DT_DELTA_RUN_COUNT_MASK ) && i < delta_cnt; ++j ) deltas[i++] = 0; } else if ( runcnt & GX_DT_DELTAS_ARE_WORDS ) { /* runcnt shorts from the stack */ for ( j = 0; j <= ( runcnt & GX_DT_DELTA_RUN_COUNT_MASK ) && i < delta_cnt; ++j ) deltas[i++] = FT_GET_SHORT(); } else { /* runcnt signed bytes from the stack */ for ( j = 0; j <= ( runcnt & GX_DT_DELTA_RUN_COUNT_MASK ) && i < delta_cnt; ++j ) deltas[i++] = FT_GET_CHAR(); } if ( j <= ( runcnt & GX_DT_DELTA_RUN_COUNT_MASK ) ) { /* Bad format */ FT_FREE( deltas ); return NULL; } } return deltas; }
@@ -130,7 +130,7 @@ FT_Int j; FT_Int first; FT_Memory memory = stream->memory; - FT_Error error = TT_Err_Ok; + FT_Error error = TT_Err_Ok; FT_UNUSED( error ); @@ -154,7 +154,7 @@ runcnt = runcnt & GX_PT_POINT_RUN_COUNT_MASK; first = points[i++] = FT_GET_USHORT(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; /* first point not included in runcount */ @@ -165,7 +165,7 @@ { first = points[i++] = FT_GET_BYTE(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; for ( j = 0; j < runcnt; ++j )
CWE-119
null
null
6,154
tt_done_blend( FT_Memory memory, GX_Blend blend ) { if ( blend != NULL ) { FT_UInt i; FT_FREE( blend->normalizedcoords ); FT_FREE( blend->mmvar ); if ( blend->avar_segment != NULL ) { for ( i = 0; i < blend->num_axis; ++i ) FT_FREE( blend->avar_segment[i].correspondence ); FT_FREE( blend->avar_segment ); } FT_FREE( blend->tuplecoords ); FT_FREE( blend->glyphoffsets ); FT_FREE( blend ); } }
DoS Exec Code Overflow
0
tt_done_blend( FT_Memory memory, GX_Blend blend ) { if ( blend != NULL ) { FT_UInt i; FT_FREE( blend->normalizedcoords ); FT_FREE( blend->mmvar ); if ( blend->avar_segment != NULL ) { for ( i = 0; i < blend->num_axis; ++i ) FT_FREE( blend->avar_segment[i].correspondence ); FT_FREE( blend->avar_segment ); } FT_FREE( blend->tuplecoords ); FT_FREE( blend->glyphoffsets ); FT_FREE( blend ); } }
@@ -130,7 +130,7 @@ FT_Int j; FT_Int first; FT_Memory memory = stream->memory; - FT_Error error = TT_Err_Ok; + FT_Error error = TT_Err_Ok; FT_UNUSED( error ); @@ -154,7 +154,7 @@ runcnt = runcnt & GX_PT_POINT_RUN_COUNT_MASK; first = points[i++] = FT_GET_USHORT(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; /* first point not included in runcount */ @@ -165,7 +165,7 @@ { first = points[i++] = FT_GET_BYTE(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; for ( j = 0; j < runcnt; ++j )
CWE-119
null
null
6,155
tt_face_vary_cvt( TT_Face face, FT_Stream stream ) { FT_Error error; FT_Memory memory = stream->memory; FT_ULong table_start; FT_ULong table_len; FT_UInt tupleCount; FT_ULong offsetToData; FT_ULong here; FT_UInt i, j; FT_Fixed* tuple_coords = NULL; FT_Fixed* im_start_coords = NULL; FT_Fixed* im_end_coords = NULL; GX_Blend blend = face->blend; FT_UInt point_count; FT_UShort* localpoints; FT_Short* deltas; FT_TRACE2(( "CVAR " )); if ( blend == NULL ) { FT_TRACE2(( "tt_face_vary_cvt: no blend specified\n" )); error = TT_Err_Ok; goto Exit; } if ( face->cvt == NULL ) { FT_TRACE2(( "tt_face_vary_cvt: no `cvt ' table\n" )); error = TT_Err_Ok; goto Exit; } error = face->goto_table( face, TTAG_cvar, stream, &table_len ); if ( error ) { FT_TRACE2(( "is missing\n" )); error = TT_Err_Ok; goto Exit; } if ( FT_FRAME_ENTER( table_len ) ) { error = TT_Err_Ok; goto Exit; } table_start = FT_Stream_FTell( stream ); if ( FT_GET_LONG() != 0x00010000L ) { FT_TRACE2(( "bad table version\n" )); error = TT_Err_Ok; goto FExit; } if ( FT_NEW_ARRAY( tuple_coords, blend->num_axis ) || FT_NEW_ARRAY( im_start_coords, blend->num_axis ) || FT_NEW_ARRAY( im_end_coords, blend->num_axis ) ) goto FExit; tupleCount = FT_GET_USHORT(); offsetToData = table_start + FT_GET_USHORT(); /* The documentation implies there are flags packed into the */ /* tuplecount, but John Jenkins says that shared points don't apply */ /* to `cvar', and no other flags are defined. */ for ( i = 0; i < ( tupleCount & 0xFFF ); ++i ) { FT_UInt tupleDataSize; FT_UInt tupleIndex; FT_Fixed apply; tupleDataSize = FT_GET_USHORT(); tupleIndex = FT_GET_USHORT(); /* There is no provision here for a global tuple coordinate section, */ /* so John says. There are no tuple indices, just embedded tuples. */ if ( tupleIndex & GX_TI_EMBEDDED_TUPLE_COORD ) { for ( j = 0; j < blend->num_axis; ++j ) tuple_coords[j] = FT_GET_SHORT() << 2; /* convert from */ /* short frac to fixed */ } else { /* skip this tuple; it makes no sense */ if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) for ( j = 0; j < 2 * blend->num_axis; ++j ) (void)FT_GET_SHORT(); offsetToData += tupleDataSize; continue; } if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) { for ( j = 0; j < blend->num_axis; ++j ) im_start_coords[j] = FT_GET_SHORT() << 2; for ( j = 0; j < blend->num_axis; ++j ) im_end_coords[j] = FT_GET_SHORT() << 2; } apply = ft_var_apply_tuple( blend, (FT_UShort)tupleIndex, tuple_coords, im_start_coords, im_end_coords ); if ( /* tuple isn't active for our blend */ apply == 0 || /* global points not allowed, */ /* if they aren't local, makes no sense */ !( tupleIndex & GX_TI_PRIVATE_POINT_NUMBERS ) ) { offsetToData += tupleDataSize; continue; } here = FT_Stream_FTell( stream ); FT_Stream_SeekSet( stream, offsetToData ); localpoints = ft_var_readpackedpoints( stream, &point_count ); deltas = ft_var_readpackeddeltas( stream, point_count == 0 ? face->cvt_size : point_count ); if ( localpoints == NULL || deltas == NULL ) /* failure, ignore it */; else if ( localpoints == ALL_POINTS ) { /* this means that there are deltas for every entry in cvt */ for ( j = 0; j < face->cvt_size; ++j ) face->cvt[j] = (FT_Short)( face->cvt[j] + FT_MulFix( deltas[j], apply ) ); } else { for ( j = 0; j < point_count; ++j ) { int pindex = localpoints[j]; face->cvt[pindex] = (FT_Short)( face->cvt[pindex] + FT_MulFix( deltas[j], apply ) ); } } if ( localpoints != ALL_POINTS ) FT_FREE( localpoints ); FT_FREE( deltas ); offsetToData += tupleDataSize; FT_Stream_SeekSet( stream, here ); } FExit: FT_FRAME_EXIT(); Exit: FT_FREE( tuple_coords ); FT_FREE( im_start_coords ); FT_FREE( im_end_coords ); return error; }
DoS Exec Code Overflow
0
tt_face_vary_cvt( TT_Face face, FT_Stream stream ) { FT_Error error; FT_Memory memory = stream->memory; FT_ULong table_start; FT_ULong table_len; FT_UInt tupleCount; FT_ULong offsetToData; FT_ULong here; FT_UInt i, j; FT_Fixed* tuple_coords = NULL; FT_Fixed* im_start_coords = NULL; FT_Fixed* im_end_coords = NULL; GX_Blend blend = face->blend; FT_UInt point_count; FT_UShort* localpoints; FT_Short* deltas; FT_TRACE2(( "CVAR " )); if ( blend == NULL ) { FT_TRACE2(( "tt_face_vary_cvt: no blend specified\n" )); error = TT_Err_Ok; goto Exit; } if ( face->cvt == NULL ) { FT_TRACE2(( "tt_face_vary_cvt: no `cvt ' table\n" )); error = TT_Err_Ok; goto Exit; } error = face->goto_table( face, TTAG_cvar, stream, &table_len ); if ( error ) { FT_TRACE2(( "is missing\n" )); error = TT_Err_Ok; goto Exit; } if ( FT_FRAME_ENTER( table_len ) ) { error = TT_Err_Ok; goto Exit; } table_start = FT_Stream_FTell( stream ); if ( FT_GET_LONG() != 0x00010000L ) { FT_TRACE2(( "bad table version\n" )); error = TT_Err_Ok; goto FExit; } if ( FT_NEW_ARRAY( tuple_coords, blend->num_axis ) || FT_NEW_ARRAY( im_start_coords, blend->num_axis ) || FT_NEW_ARRAY( im_end_coords, blend->num_axis ) ) goto FExit; tupleCount = FT_GET_USHORT(); offsetToData = table_start + FT_GET_USHORT(); /* The documentation implies there are flags packed into the */ /* tuplecount, but John Jenkins says that shared points don't apply */ /* to `cvar', and no other flags are defined. */ for ( i = 0; i < ( tupleCount & 0xFFF ); ++i ) { FT_UInt tupleDataSize; FT_UInt tupleIndex; FT_Fixed apply; tupleDataSize = FT_GET_USHORT(); tupleIndex = FT_GET_USHORT(); /* There is no provision here for a global tuple coordinate section, */ /* so John says. There are no tuple indices, just embedded tuples. */ if ( tupleIndex & GX_TI_EMBEDDED_TUPLE_COORD ) { for ( j = 0; j < blend->num_axis; ++j ) tuple_coords[j] = FT_GET_SHORT() << 2; /* convert from */ /* short frac to fixed */ } else { /* skip this tuple; it makes no sense */ if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) for ( j = 0; j < 2 * blend->num_axis; ++j ) (void)FT_GET_SHORT(); offsetToData += tupleDataSize; continue; } if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) { for ( j = 0; j < blend->num_axis; ++j ) im_start_coords[j] = FT_GET_SHORT() << 2; for ( j = 0; j < blend->num_axis; ++j ) im_end_coords[j] = FT_GET_SHORT() << 2; } apply = ft_var_apply_tuple( blend, (FT_UShort)tupleIndex, tuple_coords, im_start_coords, im_end_coords ); if ( /* tuple isn't active for our blend */ apply == 0 || /* global points not allowed, */ /* if they aren't local, makes no sense */ !( tupleIndex & GX_TI_PRIVATE_POINT_NUMBERS ) ) { offsetToData += tupleDataSize; continue; } here = FT_Stream_FTell( stream ); FT_Stream_SeekSet( stream, offsetToData ); localpoints = ft_var_readpackedpoints( stream, &point_count ); deltas = ft_var_readpackeddeltas( stream, point_count == 0 ? face->cvt_size : point_count ); if ( localpoints == NULL || deltas == NULL ) /* failure, ignore it */; else if ( localpoints == ALL_POINTS ) { /* this means that there are deltas for every entry in cvt */ for ( j = 0; j < face->cvt_size; ++j ) face->cvt[j] = (FT_Short)( face->cvt[j] + FT_MulFix( deltas[j], apply ) ); } else { for ( j = 0; j < point_count; ++j ) { int pindex = localpoints[j]; face->cvt[pindex] = (FT_Short)( face->cvt[pindex] + FT_MulFix( deltas[j], apply ) ); } } if ( localpoints != ALL_POINTS ) FT_FREE( localpoints ); FT_FREE( deltas ); offsetToData += tupleDataSize; FT_Stream_SeekSet( stream, here ); } FExit: FT_FRAME_EXIT(); Exit: FT_FREE( tuple_coords ); FT_FREE( im_start_coords ); FT_FREE( im_end_coords ); return error; }
@@ -130,7 +130,7 @@ FT_Int j; FT_Int first; FT_Memory memory = stream->memory; - FT_Error error = TT_Err_Ok; + FT_Error error = TT_Err_Ok; FT_UNUSED( error ); @@ -154,7 +154,7 @@ runcnt = runcnt & GX_PT_POINT_RUN_COUNT_MASK; first = points[i++] = FT_GET_USHORT(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; /* first point not included in runcount */ @@ -165,7 +165,7 @@ { first = points[i++] = FT_GET_BYTE(); - if ( runcnt < 1 ) + if ( runcnt < 1 || i + runcnt >= n ) goto Exit; for ( j = 0; j < runcnt; ++j )
CWE-119
null
null
6,156
static void __h2_deinit(void) { pool_destroy(pool_head_h2s); pool_destroy(pool_head_h2c); }
Exec Code Overflow
0
static void __h2_deinit(void) { pool_destroy(pool_head_h2s); pool_destroy(pool_head_h2c); }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,157
static void __h2_init(void) { alpn_register_mux(&alpn_mux_h2); cfg_register_keywords(&cfg_kws); hap_register_post_deinit(__h2_deinit); pool_head_h2c = create_pool("h2c", sizeof(struct h2c), MEM_F_SHARED); pool_head_h2s = create_pool("h2s", sizeof(struct h2s), MEM_F_SHARED); }
Exec Code Overflow
0
static void __h2_init(void) { alpn_register_mux(&alpn_mux_h2); cfg_register_keywords(&cfg_kws); hap_register_post_deinit(__h2_deinit); pool_head_h2c = create_pool("h2c", sizeof(struct h2c), MEM_F_SHARED); pool_head_h2s = create_pool("h2s", sizeof(struct h2s), MEM_F_SHARED); }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,158
static struct conn_stream *h2_attach(struct connection *conn) { return NULL; }
Exec Code Overflow
0
static struct conn_stream *h2_attach(struct connection *conn) { return NULL; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,159
static void h2_detach(struct conn_stream *cs) { struct h2s *h2s = cs->ctx; struct h2c *h2c; cs->ctx = NULL; if (!h2s) return; h2c = h2s->h2c; h2s->cs = NULL; /* this stream may be blocked waiting for some data to leave (possibly * an ES or RST frame), so orphan it in this case. */ if (!(cs->conn->flags & CO_FL_ERROR) && (h2s->flags & (H2_SF_BLK_MBUSY | H2_SF_BLK_MROOM | H2_SF_BLK_MFCTL))) return; if ((h2c->flags & H2_CF_DEM_BLOCK_ANY && h2s->id == h2c->dsi) || (h2c->flags & H2_CF_MUX_BLOCK_ANY && h2s->id == h2c->msi)) { /* unblock the connection if it was blocked on this * stream. */ h2c->flags &= ~H2_CF_DEM_BLOCK_ANY; h2c->flags &= ~H2_CF_MUX_BLOCK_ANY; conn_xprt_want_recv(cs->conn); conn_xprt_want_send(cs->conn); } h2s_destroy(h2s); /* We don't want to close right now unless we're removing the * last stream, and either the connection is in error, or it * reached the ID already specified in a GOAWAY frame received * or sent (as seen by last_sid >= 0). */ if (eb_is_empty(&h2c->streams_by_id) && /* don't close if streams exist */ ((h2c->conn->flags & CO_FL_ERROR) || /* errors close immediately */ (h2c->flags & H2_CF_GOAWAY_FAILED) || (!h2c->mbuf->o && /* mux buffer empty, also process clean events below */ (conn_xprt_read0_pending(h2c->conn) || (h2c->last_sid >= 0 && h2c->max_id >= h2c->last_sid))))) { /* no more stream will come, kill it now */ h2_release(h2c->conn); } else if (h2c->task) { if (eb_is_empty(&h2c->streams_by_id) || h2c->mbuf->o) { h2c->task->expire = tick_add(now_ms, h2c->last_sid < 0 ? h2c->timeout : h2c->shut_timeout); task_queue(h2c->task); } else h2c->task->expire = TICK_ETERNITY; } }
Exec Code Overflow
0
static void h2_detach(struct conn_stream *cs) { struct h2s *h2s = cs->ctx; struct h2c *h2c; cs->ctx = NULL; if (!h2s) return; h2c = h2s->h2c; h2s->cs = NULL; /* this stream may be blocked waiting for some data to leave (possibly * an ES or RST frame), so orphan it in this case. */ if (!(cs->conn->flags & CO_FL_ERROR) && (h2s->flags & (H2_SF_BLK_MBUSY | H2_SF_BLK_MROOM | H2_SF_BLK_MFCTL))) return; if ((h2c->flags & H2_CF_DEM_BLOCK_ANY && h2s->id == h2c->dsi) || (h2c->flags & H2_CF_MUX_BLOCK_ANY && h2s->id == h2c->msi)) { /* unblock the connection if it was blocked on this * stream. */ h2c->flags &= ~H2_CF_DEM_BLOCK_ANY; h2c->flags &= ~H2_CF_MUX_BLOCK_ANY; conn_xprt_want_recv(cs->conn); conn_xprt_want_send(cs->conn); } h2s_destroy(h2s); /* We don't want to close right now unless we're removing the * last stream, and either the connection is in error, or it * reached the ID already specified in a GOAWAY frame received * or sent (as seen by last_sid >= 0). */ if (eb_is_empty(&h2c->streams_by_id) && /* don't close if streams exist */ ((h2c->conn->flags & CO_FL_ERROR) || /* errors close immediately */ (h2c->flags & H2_CF_GOAWAY_FAILED) || (!h2c->mbuf->o && /* mux buffer empty, also process clean events below */ (conn_xprt_read0_pending(h2c->conn) || (h2c->last_sid >= 0 && h2c->max_id >= h2c->last_sid))))) { /* no more stream will come, kill it now */ h2_release(h2c->conn); } else if (h2c->task) { if (eb_is_empty(&h2c->streams_by_id) || h2c->mbuf->o) { h2c->task->expire = tick_add(now_ms, h2c->last_sid < 0 ? h2c->timeout : h2c->shut_timeout); task_queue(h2c->task); } else h2c->task->expire = TICK_ETERNITY; } }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,160
static int h2_frt_transfer_data(struct h2s *h2s, struct buffer *buf, int count) { struct h2c *h2c = h2s->h2c; int block1, block2; unsigned int flen = h2c->dfl; h2s->cs->flags &= ~CS_FL_RCV_MORE; h2c->flags &= ~H2_CF_DEM_SFULL; /* The padlen is the first byte before data, and the padding appears * after data. padlen+data+padding are included in flen. */ if (h2c->dff & H2_F_DATA_PADDED) { if (h2c->dbuf->i < 1) return 0; h2c->dpl = *(uint8_t *)bi_ptr(h2c->dbuf); if (h2c->dpl >= h2c->dfl) { /* RFC7540#6.1 : pad length = length of frame payload or greater */ h2c_error(h2c, H2_ERR_PROTOCOL_ERROR); return 0; } /* skip the padlen byte */ bi_del(h2c->dbuf, 1); h2c->dfl--; h2c->rcvd_c++; h2c->rcvd_s++; h2c->dff &= ~H2_F_DATA_PADDED; } flen = h2c->dfl - h2c->dpl; if (!flen) goto end_transfer; if (flen > h2c->dbuf->i) { flen = h2c->dbuf->i; if (!flen) return 0; } /* does it fit in output buffer or should we wait ? */ if (flen > count) { flen = count; if (!flen) { h2c->flags |= H2_CF_DEM_SFULL; h2s->cs->flags |= CS_FL_RCV_MORE; return 0; } } /* Block1 is the length of the first block before the buffer wraps, * block2 is the optional second block to reach the end of the frame. */ block1 = bi_contig_data(h2c->dbuf); if (block1 > flen) block1 = flen; block2 = flen - block1; if (block1) bi_putblk(buf, b_ptr(h2c->dbuf, 0), block1); if (block2) bi_putblk(buf, b_ptr(h2c->dbuf, block1), block2); /* now mark the input data as consumed (will be deleted from the buffer * by the caller when seeing FRAME_A after sending the window update). */ bi_del(h2c->dbuf, flen); h2c->dfl -= flen; h2c->rcvd_c += flen; h2c->rcvd_s += flen; // warning, this can also affect the closed streams! if (h2c->dfl > h2c->dpl) { /* more data available, transfer stalled on stream full */ h2c->flags |= H2_CF_DEM_SFULL; h2s->cs->flags |= CS_FL_RCV_MORE; return flen; } end_transfer: /* here we're done with the frame, all the payload (except padding) was * transferred. */ h2c->rcvd_c += h2c->dpl; h2c->rcvd_s += h2c->dpl; h2c->dpl = 0; h2c->st0 = H2_CS_FRAME_A; // send the corresponding window update /* don't send it before returning data! * FIXME: should we instead try to send it much later, after the * response ? This would require that we keep a copy of it in h2s. */ if (h2c->dff & H2_F_DATA_END_STREAM) { h2s->cs->flags |= CS_FL_EOS; h2s->flags |= H2_SF_ES_RCVD; } return flen; }
Exec Code Overflow
0
static int h2_frt_transfer_data(struct h2s *h2s, struct buffer *buf, int count) { struct h2c *h2c = h2s->h2c; int block1, block2; unsigned int flen = h2c->dfl; h2s->cs->flags &= ~CS_FL_RCV_MORE; h2c->flags &= ~H2_CF_DEM_SFULL; /* The padlen is the first byte before data, and the padding appears * after data. padlen+data+padding are included in flen. */ if (h2c->dff & H2_F_DATA_PADDED) { if (h2c->dbuf->i < 1) return 0; h2c->dpl = *(uint8_t *)bi_ptr(h2c->dbuf); if (h2c->dpl >= h2c->dfl) { /* RFC7540#6.1 : pad length = length of frame payload or greater */ h2c_error(h2c, H2_ERR_PROTOCOL_ERROR); return 0; } /* skip the padlen byte */ bi_del(h2c->dbuf, 1); h2c->dfl--; h2c->rcvd_c++; h2c->rcvd_s++; h2c->dff &= ~H2_F_DATA_PADDED; } flen = h2c->dfl - h2c->dpl; if (!flen) goto end_transfer; if (flen > h2c->dbuf->i) { flen = h2c->dbuf->i; if (!flen) return 0; } /* does it fit in output buffer or should we wait ? */ if (flen > count) { flen = count; if (!flen) { h2c->flags |= H2_CF_DEM_SFULL; h2s->cs->flags |= CS_FL_RCV_MORE; return 0; } } /* Block1 is the length of the first block before the buffer wraps, * block2 is the optional second block to reach the end of the frame. */ block1 = bi_contig_data(h2c->dbuf); if (block1 > flen) block1 = flen; block2 = flen - block1; if (block1) bi_putblk(buf, b_ptr(h2c->dbuf, 0), block1); if (block2) bi_putblk(buf, b_ptr(h2c->dbuf, block1), block2); /* now mark the input data as consumed (will be deleted from the buffer * by the caller when seeing FRAME_A after sending the window update). */ bi_del(h2c->dbuf, flen); h2c->dfl -= flen; h2c->rcvd_c += flen; h2c->rcvd_s += flen; // warning, this can also affect the closed streams! if (h2c->dfl > h2c->dpl) { /* more data available, transfer stalled on stream full */ h2c->flags |= H2_CF_DEM_SFULL; h2s->cs->flags |= CS_FL_RCV_MORE; return flen; } end_transfer: /* here we're done with the frame, all the payload (except padding) was * transferred. */ h2c->rcvd_c += h2c->dpl; h2c->rcvd_s += h2c->dpl; h2c->dpl = 0; h2c->st0 = H2_CS_FRAME_A; // send the corresponding window update /* don't send it before returning data! * FIXME: should we instead try to send it much later, after the * response ? This would require that we keep a copy of it in h2s. */ if (h2c->dff & H2_F_DATA_END_STREAM) { h2s->cs->flags |= CS_FL_EOS; h2s->flags |= H2_SF_ES_RCVD; } return flen; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,161
static inline struct buffer *h2_get_buf(struct h2c *h2c, struct buffer **bptr) { struct buffer *buf = NULL; if (likely(LIST_ISEMPTY(&h2c->buf_wait.list)) && unlikely((buf = b_alloc_margin(bptr, 0)) == NULL)) { h2c->buf_wait.target = h2c; h2c->buf_wait.wakeup_cb = h2_buf_available; HA_SPIN_LOCK(BUF_WQ_LOCK, &buffer_wq_lock); LIST_ADDQ(&buffer_wq, &h2c->buf_wait.list); HA_SPIN_UNLOCK(BUF_WQ_LOCK, &buffer_wq_lock); __conn_xprt_stop_recv(h2c->conn); } return buf; }
Exec Code Overflow
0
static inline struct buffer *h2_get_buf(struct h2c *h2c, struct buffer **bptr) { struct buffer *buf = NULL; if (likely(LIST_ISEMPTY(&h2c->buf_wait.list)) && unlikely((buf = b_alloc_margin(bptr, 0)) == NULL)) { h2c->buf_wait.target = h2c; h2c->buf_wait.wakeup_cb = h2_buf_available; HA_SPIN_LOCK(BUF_WQ_LOCK, &buffer_wq_lock); LIST_ADDQ(&buffer_wq, &h2c->buf_wait.list); HA_SPIN_UNLOCK(BUF_WQ_LOCK, &buffer_wq_lock); __conn_xprt_stop_recv(h2c->conn); } return buf; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,162
static inline __maybe_unused void h2_get_buf_bytes(void *dst, size_t bytes, const struct buffer *b, int o) { readv_bytes(dst, bytes, b_ptr(b, o), b_end(b) - b_ptr(b, o), b->data); }
Exec Code Overflow
0
static inline __maybe_unused void h2_get_buf_bytes(void *dst, size_t bytes, const struct buffer *b, int o) { readv_bytes(dst, bytes, b_ptr(b, o), b_end(b) - b_ptr(b, o), b->data); }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,163
static inline __maybe_unused int h2_get_frame_hdr(struct buffer *b, struct h2_fh *h) { int ret; ret = h2_peek_frame_hdr(b, h); if (ret > 0) h2_skip_frame_hdr(b); return ret; }
Exec Code Overflow
0
static inline __maybe_unused int h2_get_frame_hdr(struct buffer *b, struct h2_fh *h) { int ret; ret = h2_peek_frame_hdr(b, h); if (ret > 0) h2_skip_frame_hdr(b); return ret; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,164
static inline __maybe_unused uint32_t h2_get_n32(const struct buffer *b, int o) { return readv_n32(b_ptr(b, o), b_end(b) - b_ptr(b, o), b->data); }
Exec Code Overflow
0
static inline __maybe_unused uint32_t h2_get_n32(const struct buffer *b, int o) { return readv_n32(b_ptr(b, o), b_end(b) - b_ptr(b, o), b->data); }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,165
static inline __maybe_unused uint64_t h2_get_n64(const struct buffer *b, int o) { return readv_n64(b_ptr(b, o), b_end(b) - b_ptr(b, o), b->data); }
Exec Code Overflow
0
static inline __maybe_unused uint64_t h2_get_n64(const struct buffer *b, int o) { return readv_n64(b_ptr(b, o), b_end(b) - b_ptr(b, o), b->data); }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,166
static int h2_parse_header_table_size(char **args, int section_type, struct proxy *curpx, struct proxy *defpx, const char *file, int line, char **err) { if (too_many_args(1, args, err, NULL)) return -1; h2_settings_header_table_size = atoi(args[1]); if (h2_settings_header_table_size < 4096 || h2_settings_header_table_size > 65536) { memprintf(err, "'%s' expects a numeric value between 4096 and 65536.", args[0]); return -1; } return 0; }
Exec Code Overflow
0
static int h2_parse_header_table_size(char **args, int section_type, struct proxy *curpx, struct proxy *defpx, const char *file, int line, char **err) { if (too_many_args(1, args, err, NULL)) return -1; h2_settings_header_table_size = atoi(args[1]); if (h2_settings_header_table_size < 4096 || h2_settings_header_table_size > 65536) { memprintf(err, "'%s' expects a numeric value between 4096 and 65536.", args[0]); return -1; } return 0; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,167
static int h2_parse_initial_window_size(char **args, int section_type, struct proxy *curpx, struct proxy *defpx, const char *file, int line, char **err) { if (too_many_args(1, args, err, NULL)) return -1; h2_settings_initial_window_size = atoi(args[1]); if (h2_settings_initial_window_size < 0) { memprintf(err, "'%s' expects a positive numeric value.", args[0]); return -1; } return 0; }
Exec Code Overflow
0
static int h2_parse_initial_window_size(char **args, int section_type, struct proxy *curpx, struct proxy *defpx, const char *file, int line, char **err) { if (too_many_args(1, args, err, NULL)) return -1; h2_settings_initial_window_size = atoi(args[1]); if (h2_settings_initial_window_size < 0) { memprintf(err, "'%s' expects a positive numeric value.", args[0]); return -1; } return 0; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,168
static int h2_parse_max_concurrent_streams(char **args, int section_type, struct proxy *curpx, struct proxy *defpx, const char *file, int line, char **err) { if (too_many_args(1, args, err, NULL)) return -1; h2_settings_max_concurrent_streams = atoi(args[1]); if (h2_settings_max_concurrent_streams < 0) { memprintf(err, "'%s' expects a positive numeric value.", args[0]); return -1; } return 0; }
Exec Code Overflow
0
static int h2_parse_max_concurrent_streams(char **args, int section_type, struct proxy *curpx, struct proxy *defpx, const char *file, int line, char **err) { if (too_many_args(1, args, err, NULL)) return -1; h2_settings_max_concurrent_streams = atoi(args[1]); if (h2_settings_max_concurrent_streams < 0) { memprintf(err, "'%s' expects a positive numeric value.", args[0]); return -1; } return 0; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,169
static int h2_process_mux(struct h2c *h2c) { struct h2s *h2s, *h2s_back; /* start by sending possibly pending window updates */ if (h2c->rcvd_c > 0 && !(h2c->flags & (H2_CF_MUX_MFULL | H2_CF_MUX_MALLOC)) && h2c_send_conn_wu(h2c) < 0) goto fail; /* First we always process the flow control list because the streams * waiting there were already elected for immediate emission but were * blocked just on this. */ list_for_each_entry_safe(h2s, h2s_back, &h2c->fctl_list, list) { if (h2c->mws <= 0 || h2c->flags & H2_CF_MUX_BLOCK_ANY || h2c->st0 >= H2_CS_ERROR) break; /* In theory it's possible that h2s->cs == NULL here : * - client sends crap that causes a parse error * - RST_STREAM is produced and CS_FL_ERROR at the same time * - RST_STREAM cannot be emitted because mux is busy/full * - stream gets notified, detaches and quits * - mux buffer gets ready and wakes pending streams up * - bam! */ h2s->flags &= ~H2_SF_BLK_ANY; if (h2s->cs) { h2s->cs->data_cb->send(h2s->cs); h2s->cs->data_cb->wake(h2s->cs); } else { h2s_send_rst_stream(h2c, h2s); } /* depending on callee's blocking reasons, we may queue in send * list or completely dequeue. */ if ((h2s->flags & H2_SF_BLK_MFCTL) == 0) { if (h2s->flags & H2_SF_BLK_ANY) { LIST_DEL(&h2s->list); LIST_ADDQ(&h2c->send_list, &h2s->list); } else { LIST_DEL(&h2s->list); LIST_INIT(&h2s->list); if (h2s->cs) h2s->cs->flags &= ~CS_FL_DATA_WR_ENA; else { /* just sent the last frame for this orphaned stream */ h2s_destroy(h2s); } } } } list_for_each_entry_safe(h2s, h2s_back, &h2c->send_list, list) { if (h2c->st0 >= H2_CS_ERROR || h2c->flags & H2_CF_MUX_BLOCK_ANY) break; /* In theory it's possible that h2s->cs == NULL here : * - client sends crap that causes a parse error * - RST_STREAM is produced and CS_FL_ERROR at the same time * - RST_STREAM cannot be emitted because mux is busy/full * - stream gets notified, detaches and quits * - mux buffer gets ready and wakes pending streams up * - bam! */ h2s->flags &= ~H2_SF_BLK_ANY; if (h2s->cs) { h2s->cs->data_cb->send(h2s->cs); h2s->cs->data_cb->wake(h2s->cs); } else { h2s_send_rst_stream(h2c, h2s); } /* depending on callee's blocking reasons, we may queue in fctl * list or completely dequeue. */ if (h2s->flags & H2_SF_BLK_MFCTL) { /* stream hit the connection's flow control */ LIST_DEL(&h2s->list); LIST_ADDQ(&h2c->fctl_list, &h2s->list); } else if (!(h2s->flags & H2_SF_BLK_ANY)) { LIST_DEL(&h2s->list); LIST_INIT(&h2s->list); if (h2s->cs) h2s->cs->flags &= ~CS_FL_DATA_WR_ENA; else { /* just sent the last frame for this orphaned stream */ h2s_destroy(h2s); } } } fail: if (unlikely(h2c->st0 >= H2_CS_ERROR)) { if (h2c->st0 == H2_CS_ERROR) { if (h2c->max_id >= 0) { h2c_send_goaway_error(h2c, NULL); if (h2c->flags & H2_CF_MUX_BLOCK_ANY) return 0; } h2c->st0 = H2_CS_ERROR2; // sent (or failed hard) ! } return 1; } return (h2c->mws <= 0 || LIST_ISEMPTY(&h2c->fctl_list)) && LIST_ISEMPTY(&h2c->send_list); }
Exec Code Overflow
0
static int h2_process_mux(struct h2c *h2c) { struct h2s *h2s, *h2s_back; /* start by sending possibly pending window updates */ if (h2c->rcvd_c > 0 && !(h2c->flags & (H2_CF_MUX_MFULL | H2_CF_MUX_MALLOC)) && h2c_send_conn_wu(h2c) < 0) goto fail; /* First we always process the flow control list because the streams * waiting there were already elected for immediate emission but were * blocked just on this. */ list_for_each_entry_safe(h2s, h2s_back, &h2c->fctl_list, list) { if (h2c->mws <= 0 || h2c->flags & H2_CF_MUX_BLOCK_ANY || h2c->st0 >= H2_CS_ERROR) break; /* In theory it's possible that h2s->cs == NULL here : * - client sends crap that causes a parse error * - RST_STREAM is produced and CS_FL_ERROR at the same time * - RST_STREAM cannot be emitted because mux is busy/full * - stream gets notified, detaches and quits * - mux buffer gets ready and wakes pending streams up * - bam! */ h2s->flags &= ~H2_SF_BLK_ANY; if (h2s->cs) { h2s->cs->data_cb->send(h2s->cs); h2s->cs->data_cb->wake(h2s->cs); } else { h2s_send_rst_stream(h2c, h2s); } /* depending on callee's blocking reasons, we may queue in send * list or completely dequeue. */ if ((h2s->flags & H2_SF_BLK_MFCTL) == 0) { if (h2s->flags & H2_SF_BLK_ANY) { LIST_DEL(&h2s->list); LIST_ADDQ(&h2c->send_list, &h2s->list); } else { LIST_DEL(&h2s->list); LIST_INIT(&h2s->list); if (h2s->cs) h2s->cs->flags &= ~CS_FL_DATA_WR_ENA; else { /* just sent the last frame for this orphaned stream */ h2s_destroy(h2s); } } } } list_for_each_entry_safe(h2s, h2s_back, &h2c->send_list, list) { if (h2c->st0 >= H2_CS_ERROR || h2c->flags & H2_CF_MUX_BLOCK_ANY) break; /* In theory it's possible that h2s->cs == NULL here : * - client sends crap that causes a parse error * - RST_STREAM is produced and CS_FL_ERROR at the same time * - RST_STREAM cannot be emitted because mux is busy/full * - stream gets notified, detaches and quits * - mux buffer gets ready and wakes pending streams up * - bam! */ h2s->flags &= ~H2_SF_BLK_ANY; if (h2s->cs) { h2s->cs->data_cb->send(h2s->cs); h2s->cs->data_cb->wake(h2s->cs); } else { h2s_send_rst_stream(h2c, h2s); } /* depending on callee's blocking reasons, we may queue in fctl * list or completely dequeue. */ if (h2s->flags & H2_SF_BLK_MFCTL) { /* stream hit the connection's flow control */ LIST_DEL(&h2s->list); LIST_ADDQ(&h2c->fctl_list, &h2s->list); } else if (!(h2s->flags & H2_SF_BLK_ANY)) { LIST_DEL(&h2s->list); LIST_INIT(&h2s->list); if (h2s->cs) h2s->cs->flags &= ~CS_FL_DATA_WR_ENA; else { /* just sent the last frame for this orphaned stream */ h2s_destroy(h2s); } } } fail: if (unlikely(h2c->st0 >= H2_CS_ERROR)) { if (h2c->st0 == H2_CS_ERROR) { if (h2c->max_id >= 0) { h2c_send_goaway_error(h2c, NULL); if (h2c->flags & H2_CF_MUX_BLOCK_ANY) return 0; } h2c->st0 = H2_CS_ERROR2; // sent (or failed hard) ! } return 1; } return (h2c->mws <= 0 || LIST_ISEMPTY(&h2c->fctl_list)) && LIST_ISEMPTY(&h2c->send_list); }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,170
static int h2_rcv_buf(struct conn_stream *cs, struct buffer *buf, int count) { struct h2s *h2s = cs->ctx; struct h2c *h2c = h2s->h2c; int ret = 0; if (h2c->st0 != H2_CS_FRAME_P) return 0; // no pre-parsed frame yet if (h2c->dsi != h2s->id) return 0; // not for us if (!h2c->dbuf->size) return 0; // empty buffer switch (h2c->dft) { case H2_FT_HEADERS: ret = h2_frt_decode_headers(h2s, buf, count); break; case H2_FT_DATA: ret = h2_frt_transfer_data(h2s, buf, count); break; default: ret = 0; } return ret; }
Exec Code Overflow
0
static int h2_rcv_buf(struct conn_stream *cs, struct buffer *buf, int count) { struct h2s *h2s = cs->ctx; struct h2c *h2c = h2s->h2c; int ret = 0; if (h2c->st0 != H2_CS_FRAME_P) return 0; // no pre-parsed frame yet if (h2c->dsi != h2s->id) return 0; // not for us if (!h2c->dbuf->size) return 0; // empty buffer switch (h2c->dft) { case H2_FT_HEADERS: ret = h2_frt_decode_headers(h2s, buf, count); break; case H2_FT_DATA: ret = h2_frt_transfer_data(h2s, buf, count); break; default: ret = 0; } return ret; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,171
static void h2_recv(struct connection *conn) { struct h2c *h2c = conn->mux_ctx; struct buffer *buf; int max; if (!h2_recv_allowed(h2c)) return; buf = h2_get_buf(h2c, &h2c->dbuf); if (!buf) { h2c->flags |= H2_CF_DEM_DALLOC; return; } /* note: buf->o == 0 */ max = buf->size - buf->i; if (max) conn->xprt->rcv_buf(conn, buf, max); if (!buf->i) { h2_release_buf(h2c, &h2c->dbuf); return; } if (buf->i == buf->size) h2c->flags |= H2_CF_DEM_DFULL; return; }
Exec Code Overflow
0
static void h2_recv(struct connection *conn) { struct h2c *h2c = conn->mux_ctx; struct buffer *buf; int max; if (!h2_recv_allowed(h2c)) return; buf = h2_get_buf(h2c, &h2c->dbuf); if (!buf) { h2c->flags |= H2_CF_DEM_DALLOC; return; } /* note: buf->o == 0 */ max = buf->size - buf->i; if (max) conn->xprt->rcv_buf(conn, buf, max); if (!buf->i) { h2_release_buf(h2c, &h2c->dbuf); return; } if (buf->i == buf->size) h2c->flags |= H2_CF_DEM_DFULL; return; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,172
static inline int h2_recv_allowed(const struct h2c *h2c) { if (h2c->dbuf->i == 0 && (h2c->st0 >= H2_CS_ERROR || h2c->conn->flags & CO_FL_ERROR || conn_xprt_read0_pending(h2c->conn))) return 0; if (!(h2c->flags & H2_CF_DEM_DALLOC) && !(h2c->flags & H2_CF_DEM_BLOCK_ANY)) return 1; return 0; }
Exec Code Overflow
0
static inline int h2_recv_allowed(const struct h2c *h2c) { if (h2c->dbuf->i == 0 && (h2c->st0 >= H2_CS_ERROR || h2c->conn->flags & CO_FL_ERROR || conn_xprt_read0_pending(h2c->conn))) return 0; if (!(h2c->flags & H2_CF_DEM_DALLOC) && !(h2c->flags & H2_CF_DEM_BLOCK_ANY)) return 1; return 0; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,173
static void h2_release(struct connection *conn) { struct h2c *h2c = conn->mux_ctx; LIST_DEL(&conn->list); if (h2c) { hpack_dht_free(h2c->ddht); HA_SPIN_LOCK(BUF_WQ_LOCK, &buffer_wq_lock); LIST_DEL(&h2c->buf_wait.list); HA_SPIN_UNLOCK(BUF_WQ_LOCK, &buffer_wq_lock); h2_release_buf(h2c, &h2c->dbuf); h2_release_buf(h2c, &h2c->mbuf); if (h2c->task) { h2c->task->context = NULL; task_wakeup(h2c->task, TASK_WOKEN_OTHER); h2c->task = NULL; } pool_free(pool_head_h2c, h2c); } conn->mux = NULL; conn->mux_ctx = NULL; conn_stop_tracking(conn); conn_full_close(conn); if (conn->destroy_cb) conn->destroy_cb(conn); conn_free(conn); }
Exec Code Overflow
0
static void h2_release(struct connection *conn) { struct h2c *h2c = conn->mux_ctx; LIST_DEL(&conn->list); if (h2c) { hpack_dht_free(h2c->ddht); HA_SPIN_LOCK(BUF_WQ_LOCK, &buffer_wq_lock); LIST_DEL(&h2c->buf_wait.list); HA_SPIN_UNLOCK(BUF_WQ_LOCK, &buffer_wq_lock); h2_release_buf(h2c, &h2c->dbuf); h2_release_buf(h2c, &h2c->mbuf); if (h2c->task) { h2c->task->context = NULL; task_wakeup(h2c->task, TASK_WOKEN_OTHER); h2c->task = NULL; } pool_free(pool_head_h2c, h2c); } conn->mux = NULL; conn->mux_ctx = NULL; conn_stop_tracking(conn); conn_full_close(conn); if (conn->destroy_cb) conn->destroy_cb(conn); conn_free(conn); }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,174
static inline void h2_release_buf(struct h2c *h2c, struct buffer **bptr) { if ((*bptr)->size) { b_free(bptr); offer_buffers(h2c->buf_wait.target, tasks_run_queue + applets_active_queue); } }
Exec Code Overflow
0
static inline void h2_release_buf(struct h2c *h2c, struct buffer **bptr) { if ((*bptr)->size) { b_free(bptr); offer_buffers(h2c->buf_wait.target, tasks_run_queue + applets_active_queue); } }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,175
static void h2_send(struct connection *conn) { struct h2c *h2c = conn->mux_ctx; int done; if (conn->flags & CO_FL_ERROR) return; if (conn->flags & (CO_FL_HANDSHAKE|CO_FL_WAIT_L4_CONN|CO_FL_WAIT_L6_CONN)) { /* a handshake was requested */ return; } /* This loop is quite simple : it tries to fill as much as it can from * pending streams into the existing buffer until it's reportedly full * or the end of send requests is reached. Then it tries to send this * buffer's contents out, marks it not full if at least one byte could * be sent, and tries again. * * The snd_buf() function normally takes a "flags" argument which may * be made of a combination of CO_SFL_MSG_MORE to indicate that more * data immediately comes and CO_SFL_STREAMER to indicate that the * connection is streaming lots of data (used to increase TLS record * size at the expense of latency). The former can be sent any time * there's a buffer full flag, as it indicates at least one stream * attempted to send and failed so there are pending data. An * alternative would be to set it as long as there's an active stream * but that would be problematic for ACKs until we have an absolute * guarantee that all waiters have at least one byte to send. The * latter should possibly not be set for now. */ done = 0; while (!done) { unsigned int flags = 0; /* fill as much as we can into the current buffer */ while (((h2c->flags & (H2_CF_MUX_MFULL|H2_CF_MUX_MALLOC)) == 0) && !done) done = h2_process_mux(h2c); if (conn->flags & CO_FL_ERROR) break; if (h2c->flags & (H2_CF_MUX_MFULL | H2_CF_DEM_MBUSY | H2_CF_DEM_MROOM)) flags |= CO_SFL_MSG_MORE; if (h2c->mbuf->o && conn->xprt->snd_buf(conn, h2c->mbuf, flags) <= 0) break; /* wrote at least one byte, the buffer is not full anymore */ h2c->flags &= ~(H2_CF_MUX_MFULL | H2_CF_DEM_MROOM); } if (conn->flags & CO_FL_SOCK_WR_SH) { /* output closed, nothing to send, clear the buffer to release it */ h2c->mbuf->o = 0; } }
Exec Code Overflow
0
static void h2_send(struct connection *conn) { struct h2c *h2c = conn->mux_ctx; int done; if (conn->flags & CO_FL_ERROR) return; if (conn->flags & (CO_FL_HANDSHAKE|CO_FL_WAIT_L4_CONN|CO_FL_WAIT_L6_CONN)) { /* a handshake was requested */ return; } /* This loop is quite simple : it tries to fill as much as it can from * pending streams into the existing buffer until it's reportedly full * or the end of send requests is reached. Then it tries to send this * buffer's contents out, marks it not full if at least one byte could * be sent, and tries again. * * The snd_buf() function normally takes a "flags" argument which may * be made of a combination of CO_SFL_MSG_MORE to indicate that more * data immediately comes and CO_SFL_STREAMER to indicate that the * connection is streaming lots of data (used to increase TLS record * size at the expense of latency). The former can be sent any time * there's a buffer full flag, as it indicates at least one stream * attempted to send and failed so there are pending data. An * alternative would be to set it as long as there's an active stream * but that would be problematic for ACKs until we have an absolute * guarantee that all waiters have at least one byte to send. The * latter should possibly not be set for now. */ done = 0; while (!done) { unsigned int flags = 0; /* fill as much as we can into the current buffer */ while (((h2c->flags & (H2_CF_MUX_MFULL|H2_CF_MUX_MALLOC)) == 0) && !done) done = h2_process_mux(h2c); if (conn->flags & CO_FL_ERROR) break; if (h2c->flags & (H2_CF_MUX_MFULL | H2_CF_DEM_MBUSY | H2_CF_DEM_MROOM)) flags |= CO_SFL_MSG_MORE; if (h2c->mbuf->o && conn->xprt->snd_buf(conn, h2c->mbuf, flags) <= 0) break; /* wrote at least one byte, the buffer is not full anymore */ h2c->flags &= ~(H2_CF_MUX_MFULL | H2_CF_DEM_MROOM); } if (conn->flags & CO_FL_SOCK_WR_SH) { /* output closed, nothing to send, clear the buffer to release it */ h2c->mbuf->o = 0; } }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,176
static int h2_send_empty_data_es(struct h2s *h2s) { struct h2c *h2c = h2s->h2c; struct buffer *res; char str[9]; int ret; if (h2s->st == H2_SS_HLOC || h2s->st == H2_SS_ERROR || h2s->st == H2_SS_CLOSED) return 1; if (h2c_mux_busy(h2c, h2s)) { h2s->flags |= H2_SF_BLK_MBUSY; return 0; } res = h2_get_buf(h2c, &h2c->mbuf); if (!res) { h2c->flags |= H2_CF_MUX_MALLOC; h2s->flags |= H2_SF_BLK_MROOM; return 0; } /* len: 0x000000, type: 0(DATA), flags: ES=1 */ memcpy(str, "\x00\x00\x00\x00\x01", 5); write_n32(str + 5, h2s->id); ret = bo_istput(res, ist2(str, 9)); if (likely(ret > 0)) { h2s->flags |= H2_SF_ES_SENT; } else if (!ret) { h2c->flags |= H2_CF_MUX_MFULL; h2s->flags |= H2_SF_BLK_MROOM; return 0; } else { h2c_error(h2c, H2_ERR_INTERNAL_ERROR); return 0; } return ret; }
Exec Code Overflow
0
static int h2_send_empty_data_es(struct h2s *h2s) { struct h2c *h2c = h2s->h2c; struct buffer *res; char str[9]; int ret; if (h2s->st == H2_SS_HLOC || h2s->st == H2_SS_ERROR || h2s->st == H2_SS_CLOSED) return 1; if (h2c_mux_busy(h2c, h2s)) { h2s->flags |= H2_SF_BLK_MBUSY; return 0; } res = h2_get_buf(h2c, &h2c->mbuf); if (!res) { h2c->flags |= H2_CF_MUX_MALLOC; h2s->flags |= H2_SF_BLK_MROOM; return 0; } /* len: 0x000000, type: 0(DATA), flags: ES=1 */ memcpy(str, "\x00\x00\x00\x00\x01", 5); write_n32(str + 5, h2s->id); ret = bo_istput(res, ist2(str, 9)); if (likely(ret > 0)) { h2s->flags |= H2_SF_ES_SENT; } else if (!ret) { h2c->flags |= H2_CF_MUX_MFULL; h2s->flags |= H2_SF_BLK_MROOM; return 0; } else { h2c_error(h2c, H2_ERR_INTERNAL_ERROR); return 0; } return ret; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,177
static inline __maybe_unused void h2_set_frame_size(void *frame, uint32_t len) { uint8_t *out = frame; *out = len >> 16; write_n16(out + 1, len); }
Exec Code Overflow
0
static inline __maybe_unused void h2_set_frame_size(void *frame, uint32_t len) { uint8_t *out = frame; *out = len >> 16; write_n16(out + 1, len); }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,178
static void h2_show_fd(struct chunk *msg, struct connection *conn) { struct h2c *h2c = conn->mux_ctx; struct h2s *h2s; struct eb32_node *node; int fctl_cnt = 0; int send_cnt = 0; int tree_cnt = 0; int orph_cnt = 0; if (!h2c) return; list_for_each_entry(h2s, &h2c->fctl_list, list) fctl_cnt++; list_for_each_entry(h2s, &h2c->send_list, list) send_cnt++; node = eb32_first(&h2c->streams_by_id); while (node) { h2s = container_of(node, struct h2s, by_id); tree_cnt++; if (!h2s->cs) orph_cnt++; node = eb32_next(node); } chunk_appendf(msg, " st0=%d flg=0x%08x fctl_cnt=%d send_cnt=%d tree_cnt=%d orph_cnt=%d", h2c->st0, h2c->flags, fctl_cnt, send_cnt, tree_cnt, orph_cnt); }
Exec Code Overflow
0
static void h2_show_fd(struct chunk *msg, struct connection *conn) { struct h2c *h2c = conn->mux_ctx; struct h2s *h2s; struct eb32_node *node; int fctl_cnt = 0; int send_cnt = 0; int tree_cnt = 0; int orph_cnt = 0; if (!h2c) return; list_for_each_entry(h2s, &h2c->fctl_list, list) fctl_cnt++; list_for_each_entry(h2s, &h2c->send_list, list) send_cnt++; node = eb32_first(&h2c->streams_by_id); while (node) { h2s = container_of(node, struct h2s, by_id); tree_cnt++; if (!h2s->cs) orph_cnt++; node = eb32_next(node); } chunk_appendf(msg, " st0=%d flg=0x%08x fctl_cnt=%d send_cnt=%d tree_cnt=%d orph_cnt=%d", h2c->st0, h2c->flags, fctl_cnt, send_cnt, tree_cnt, orph_cnt); }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,179
static void h2_shutr(struct conn_stream *cs, enum cs_shr_mode mode) { struct h2s *h2s = cs->ctx; if (!mode) return; if (h2s->st == H2_SS_HLOC || h2s->st == H2_SS_ERROR || h2s->st == H2_SS_CLOSED) return; /* if no outgoing data was seen on this stream, it means it was * closed with a "tcp-request content" rule that is normally * used to kill the connection ASAP (eg: limit abuse). In this * case we send a goaway to close the connection. */ if (!(h2s->flags & H2_SF_RST_SENT) && h2s_send_rst_stream(h2s->h2c, h2s) <= 0) goto add_to_list; if (!(h2s->flags & H2_SF_OUTGOING_DATA) && !(h2s->h2c->flags & (H2_CF_GOAWAY_SENT|H2_CF_GOAWAY_FAILED)) && h2c_send_goaway_error(h2s->h2c, h2s) <= 0) goto add_to_list; if (h2s->h2c->mbuf->o && !(cs->conn->flags & CO_FL_XPRT_WR_ENA)) conn_xprt_want_send(cs->conn); h2s_close(h2s); add_to_list: if (LIST_ISEMPTY(&h2s->list)) { if (h2s->flags & H2_SF_BLK_MFCTL) LIST_ADDQ(&h2s->h2c->fctl_list, &h2s->list); else if (h2s->flags & (H2_SF_BLK_MBUSY|H2_SF_BLK_MROOM)) LIST_ADDQ(&h2s->h2c->send_list, &h2s->list); } }
Exec Code Overflow
0
static void h2_shutr(struct conn_stream *cs, enum cs_shr_mode mode) { struct h2s *h2s = cs->ctx; if (!mode) return; if (h2s->st == H2_SS_HLOC || h2s->st == H2_SS_ERROR || h2s->st == H2_SS_CLOSED) return; /* if no outgoing data was seen on this stream, it means it was * closed with a "tcp-request content" rule that is normally * used to kill the connection ASAP (eg: limit abuse). In this * case we send a goaway to close the connection. */ if (!(h2s->flags & H2_SF_RST_SENT) && h2s_send_rst_stream(h2s->h2c, h2s) <= 0) goto add_to_list; if (!(h2s->flags & H2_SF_OUTGOING_DATA) && !(h2s->h2c->flags & (H2_CF_GOAWAY_SENT|H2_CF_GOAWAY_FAILED)) && h2c_send_goaway_error(h2s->h2c, h2s) <= 0) goto add_to_list; if (h2s->h2c->mbuf->o && !(cs->conn->flags & CO_FL_XPRT_WR_ENA)) conn_xprt_want_send(cs->conn); h2s_close(h2s); add_to_list: if (LIST_ISEMPTY(&h2s->list)) { if (h2s->flags & H2_SF_BLK_MFCTL) LIST_ADDQ(&h2s->h2c->fctl_list, &h2s->list); else if (h2s->flags & (H2_SF_BLK_MBUSY|H2_SF_BLK_MROOM)) LIST_ADDQ(&h2s->h2c->send_list, &h2s->list); } }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,180
static void h2_shutw(struct conn_stream *cs, enum cs_shw_mode mode) { struct h2s *h2s = cs->ctx; if (h2s->st == H2_SS_HLOC || h2s->st == H2_SS_ERROR || h2s->st == H2_SS_CLOSED) return; if (h2s->flags & H2_SF_HEADERS_SENT) { /* we can cleanly close using an empty data frame only after headers */ if (!(h2s->flags & (H2_SF_ES_SENT|H2_SF_RST_SENT)) && h2_send_empty_data_es(h2s) <= 0) goto add_to_list; if (h2s->st == H2_SS_HREM) h2s_close(h2s); else h2s->st = H2_SS_HLOC; } else { /* if no outgoing data was seen on this stream, it means it was * closed with a "tcp-request content" rule that is normally * used to kill the connection ASAP (eg: limit abuse). In this * case we send a goaway to close the connection. */ if (!(h2s->flags & H2_SF_RST_SENT) && h2s_send_rst_stream(h2s->h2c, h2s) <= 0) goto add_to_list; if (!(h2s->flags & H2_SF_OUTGOING_DATA) && !(h2s->h2c->flags & (H2_CF_GOAWAY_SENT|H2_CF_GOAWAY_FAILED)) && h2c_send_goaway_error(h2s->h2c, h2s) <= 0) goto add_to_list; h2s_close(h2s); } if (h2s->h2c->mbuf->o && !(cs->conn->flags & CO_FL_XPRT_WR_ENA)) conn_xprt_want_send(cs->conn); add_to_list: if (LIST_ISEMPTY(&h2s->list)) { if (h2s->flags & H2_SF_BLK_MFCTL) LIST_ADDQ(&h2s->h2c->fctl_list, &h2s->list); else if (h2s->flags & (H2_SF_BLK_MBUSY|H2_SF_BLK_MROOM)) LIST_ADDQ(&h2s->h2c->send_list, &h2s->list); } }
Exec Code Overflow
0
static void h2_shutw(struct conn_stream *cs, enum cs_shw_mode mode) { struct h2s *h2s = cs->ctx; if (h2s->st == H2_SS_HLOC || h2s->st == H2_SS_ERROR || h2s->st == H2_SS_CLOSED) return; if (h2s->flags & H2_SF_HEADERS_SENT) { /* we can cleanly close using an empty data frame only after headers */ if (!(h2s->flags & (H2_SF_ES_SENT|H2_SF_RST_SENT)) && h2_send_empty_data_es(h2s) <= 0) goto add_to_list; if (h2s->st == H2_SS_HREM) h2s_close(h2s); else h2s->st = H2_SS_HLOC; } else { /* if no outgoing data was seen on this stream, it means it was * closed with a "tcp-request content" rule that is normally * used to kill the connection ASAP (eg: limit abuse). In this * case we send a goaway to close the connection. */ if (!(h2s->flags & H2_SF_RST_SENT) && h2s_send_rst_stream(h2s->h2c, h2s) <= 0) goto add_to_list; if (!(h2s->flags & H2_SF_OUTGOING_DATA) && !(h2s->h2c->flags & (H2_CF_GOAWAY_SENT|H2_CF_GOAWAY_FAILED)) && h2c_send_goaway_error(h2s->h2c, h2s) <= 0) goto add_to_list; h2s_close(h2s); } if (h2s->h2c->mbuf->o && !(cs->conn->flags & CO_FL_XPRT_WR_ENA)) conn_xprt_want_send(cs->conn); add_to_list: if (LIST_ISEMPTY(&h2s->list)) { if (h2s->flags & H2_SF_BLK_MFCTL) LIST_ADDQ(&h2s->h2c->fctl_list, &h2s->list); else if (h2s->flags & (H2_SF_BLK_MBUSY|H2_SF_BLK_MROOM)) LIST_ADDQ(&h2s->h2c->send_list, &h2s->list); } }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,181
static inline __maybe_unused void h2_skip_frame_hdr(struct buffer *b) { bi_del(b, 9); }
Exec Code Overflow
0
static inline __maybe_unused void h2_skip_frame_hdr(struct buffer *b) { bi_del(b, 9); }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,182
static int h2_snd_buf(struct conn_stream *cs, struct buffer *buf, int flags) { struct h2s *h2s = cs->ctx; int total = 0; if (!(h2s->flags & H2_SF_OUTGOING_DATA) && buf->o) h2s->flags |= H2_SF_OUTGOING_DATA; while (h2s->res.state < HTTP_MSG_DONE && buf->o) { if (h2s->res.state < HTTP_MSG_BODY) { total += h2s_frt_make_resp_headers(h2s, buf); if (h2s->st >= H2_SS_ERROR) break; if (h2s->flags & H2_SF_BLK_ANY) break; } else if (h2s->res.state < HTTP_MSG_TRAILERS) { total += h2s_frt_make_resp_data(h2s, buf); if (h2s->st >= H2_SS_ERROR) break; if (h2s->flags & H2_SF_BLK_ANY) break; } else if (h2s->res.state == HTTP_MSG_TRAILERS) { /* consume the trailers if any (we don't forward them for now) */ int count = h1_measure_trailers(buf); if (unlikely(count <= 0)) { if (count < 0) h2s_error(h2s, H2_ERR_INTERNAL_ERROR); break; } total += count; bo_del(buf, count); bo_del(buf, buf->o); h2s->res.state = HTTP_MSG_DONE; break; } else { cs->flags |= CS_FL_ERROR; break; } } /* RST are sent similarly to frame acks */ if (h2s->st == H2_SS_ERROR || h2s->flags & H2_SF_RST_RCVD) { cs->flags |= CS_FL_ERROR; if (h2s_send_rst_stream(h2s->h2c, h2s) > 0) h2s_close(h2s); } if (h2s->flags & H2_SF_BLK_SFCTL) { /* stream flow control, quit the list */ LIST_DEL(&h2s->list); LIST_INIT(&h2s->list); } else if (LIST_ISEMPTY(&h2s->list)) { if (h2s->flags & H2_SF_BLK_MFCTL) LIST_ADDQ(&h2s->h2c->fctl_list, &h2s->list); else if (h2s->flags & (H2_SF_BLK_MBUSY|H2_SF_BLK_MROOM)) LIST_ADDQ(&h2s->h2c->send_list, &h2s->list); } return total; }
Exec Code Overflow
0
static int h2_snd_buf(struct conn_stream *cs, struct buffer *buf, int flags) { struct h2s *h2s = cs->ctx; int total = 0; if (!(h2s->flags & H2_SF_OUTGOING_DATA) && buf->o) h2s->flags |= H2_SF_OUTGOING_DATA; while (h2s->res.state < HTTP_MSG_DONE && buf->o) { if (h2s->res.state < HTTP_MSG_BODY) { total += h2s_frt_make_resp_headers(h2s, buf); if (h2s->st >= H2_SS_ERROR) break; if (h2s->flags & H2_SF_BLK_ANY) break; } else if (h2s->res.state < HTTP_MSG_TRAILERS) { total += h2s_frt_make_resp_data(h2s, buf); if (h2s->st >= H2_SS_ERROR) break; if (h2s->flags & H2_SF_BLK_ANY) break; } else if (h2s->res.state == HTTP_MSG_TRAILERS) { /* consume the trailers if any (we don't forward them for now) */ int count = h1_measure_trailers(buf); if (unlikely(count <= 0)) { if (count < 0) h2s_error(h2s, H2_ERR_INTERNAL_ERROR); break; } total += count; bo_del(buf, count); bo_del(buf, buf->o); h2s->res.state = HTTP_MSG_DONE; break; } else { cs->flags |= CS_FL_ERROR; break; } } /* RST are sent similarly to frame acks */ if (h2s->st == H2_SS_ERROR || h2s->flags & H2_SF_RST_RCVD) { cs->flags |= CS_FL_ERROR; if (h2s_send_rst_stream(h2s->h2c, h2s) > 0) h2s_close(h2s); } if (h2s->flags & H2_SF_BLK_SFCTL) { /* stream flow control, quit the list */ LIST_DEL(&h2s->list); LIST_INIT(&h2s->list); } else if (LIST_ISEMPTY(&h2s->list)) { if (h2s->flags & H2_SF_BLK_MFCTL) LIST_ADDQ(&h2s->h2c->fctl_list, &h2s->list); else if (h2s->flags & (H2_SF_BLK_MBUSY|H2_SF_BLK_MROOM)) LIST_ADDQ(&h2s->h2c->send_list, &h2s->list); } return total; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,183
static struct task *h2_timeout_task(struct task *t) { struct h2c *h2c = t->context; int expired = tick_is_expired(t->expire, now_ms); if (!expired && h2c) return t; task_delete(t); task_free(t); if (!h2c) { /* resources were already deleted */ return NULL; } h2c->task = NULL; h2c_error(h2c, H2_ERR_NO_ERROR); h2_wake_some_streams(h2c, 0, 0); if (h2c->mbuf->o) { /* don't even try to send a GOAWAY, the buffer is stuck */ h2c->flags |= H2_CF_GOAWAY_FAILED; } /* try to send but no need to insist */ h2c->last_sid = h2c->max_id; if (h2c_send_goaway_error(h2c, NULL) <= 0) h2c->flags |= H2_CF_GOAWAY_FAILED; if (h2c->mbuf->o && !(h2c->flags & H2_CF_GOAWAY_FAILED) && conn_xprt_ready(h2c->conn)) h2c->conn->xprt->snd_buf(h2c->conn, h2c->mbuf, 0); /* either we can release everything now or it will be done later once * the last stream closes. */ if (eb_is_empty(&h2c->streams_by_id)) h2_release(h2c->conn); return NULL; }
Exec Code Overflow
0
static struct task *h2_timeout_task(struct task *t) { struct h2c *h2c = t->context; int expired = tick_is_expired(t->expire, now_ms); if (!expired && h2c) return t; task_delete(t); task_free(t); if (!h2c) { /* resources were already deleted */ return NULL; } h2c->task = NULL; h2c_error(h2c, H2_ERR_NO_ERROR); h2_wake_some_streams(h2c, 0, 0); if (h2c->mbuf->o) { /* don't even try to send a GOAWAY, the buffer is stuck */ h2c->flags |= H2_CF_GOAWAY_FAILED; } /* try to send but no need to insist */ h2c->last_sid = h2c->max_id; if (h2c_send_goaway_error(h2c, NULL) <= 0) h2c->flags |= H2_CF_GOAWAY_FAILED; if (h2c->mbuf->o && !(h2c->flags & H2_CF_GOAWAY_FAILED) && conn_xprt_ready(h2c->conn)) h2c->conn->xprt->snd_buf(h2c->conn, h2c->mbuf, 0); /* either we can release everything now or it will be done later once * the last stream closes. */ if (eb_is_empty(&h2c->streams_by_id)) h2_release(h2c->conn); return NULL; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,184
static void h2_update_poll(struct conn_stream *cs) { struct h2s *h2s = cs->ctx; if (!h2s) return; /* we may unblock a blocked read */ if (cs->flags & CS_FL_DATA_RD_ENA) { /* the stream indicates it's willing to read */ h2s->h2c->flags &= ~H2_CF_DEM_SFULL; if (h2s->h2c->dsi == h2s->id) { conn_xprt_want_recv(cs->conn); conn_xprt_want_send(cs->conn); } } /* Note: the stream and stream-int code doesn't allow us to perform a * synchronous send() here unfortunately, because this code is called * as si_update() from the process_stream() context. This means that * we have to queue the current cs and defer its processing after the * connection's cs list is processed anyway. */ if (cs->flags & CS_FL_DATA_WR_ENA) { if (LIST_ISEMPTY(&h2s->list)) { if (LIST_ISEMPTY(&h2s->h2c->send_list) && !h2s->h2c->mbuf->o && // not yet subscribed !(cs->conn->flags & CO_FL_SOCK_WR_SH)) conn_xprt_want_send(cs->conn); LIST_ADDQ(&h2s->h2c->send_list, &h2s->list); } } else if (!LIST_ISEMPTY(&h2s->list)) { LIST_DEL(&h2s->list); LIST_INIT(&h2s->list); h2s->flags &= ~(H2_SF_BLK_MBUSY | H2_SF_BLK_MROOM | H2_SF_BLK_MFCTL); } /* this can happen from within si_chk_snd() */ if (h2s->h2c->mbuf->o && !(cs->conn->flags & CO_FL_XPRT_WR_ENA)) conn_xprt_want_send(cs->conn); }
Exec Code Overflow
0
static void h2_update_poll(struct conn_stream *cs) { struct h2s *h2s = cs->ctx; if (!h2s) return; /* we may unblock a blocked read */ if (cs->flags & CS_FL_DATA_RD_ENA) { /* the stream indicates it's willing to read */ h2s->h2c->flags &= ~H2_CF_DEM_SFULL; if (h2s->h2c->dsi == h2s->id) { conn_xprt_want_recv(cs->conn); conn_xprt_want_send(cs->conn); } } /* Note: the stream and stream-int code doesn't allow us to perform a * synchronous send() here unfortunately, because this code is called * as si_update() from the process_stream() context. This means that * we have to queue the current cs and defer its processing after the * connection's cs list is processed anyway. */ if (cs->flags & CS_FL_DATA_WR_ENA) { if (LIST_ISEMPTY(&h2s->list)) { if (LIST_ISEMPTY(&h2s->h2c->send_list) && !h2s->h2c->mbuf->o && // not yet subscribed !(cs->conn->flags & CO_FL_SOCK_WR_SH)) conn_xprt_want_send(cs->conn); LIST_ADDQ(&h2s->h2c->send_list, &h2s->list); } } else if (!LIST_ISEMPTY(&h2s->list)) { LIST_DEL(&h2s->list); LIST_INIT(&h2s->list); h2s->flags &= ~(H2_SF_BLK_MBUSY | H2_SF_BLK_MROOM | H2_SF_BLK_MFCTL); } /* this can happen from within si_chk_snd() */ if (h2s->h2c->mbuf->o && !(cs->conn->flags & CO_FL_XPRT_WR_ENA)) conn_xprt_want_send(cs->conn); }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,185
static void h2_wake_some_streams(struct h2c *h2c, int last, uint32_t flags) { struct eb32_node *node; struct h2s *h2s; if (h2c->st0 >= H2_CS_ERROR || h2c->conn->flags & CO_FL_ERROR) flags |= CS_FL_ERROR; if (conn_xprt_read0_pending(h2c->conn)) flags |= CS_FL_EOS; node = eb32_lookup_ge(&h2c->streams_by_id, last + 1); while (node) { h2s = container_of(node, struct h2s, by_id); if (h2s->id <= last) break; node = eb32_next(node); if (!h2s->cs) { /* this stream was already orphaned */ h2s_destroy(h2s); continue; } h2s->cs->flags |= flags; /* recv is used to force to detect CS_FL_EOS that wake() * doesn't handle in the stream int code. */ h2s->cs->data_cb->recv(h2s->cs); h2s->cs->data_cb->wake(h2s->cs); if (flags & CS_FL_ERROR && h2s->st < H2_SS_ERROR) h2s->st = H2_SS_ERROR; else if (flags & CS_FL_EOS && h2s->st == H2_SS_OPEN) h2s->st = H2_SS_HREM; else if (flags & CS_FL_EOS && h2s->st == H2_SS_HLOC) h2s_close(h2s); } }
Exec Code Overflow
0
static void h2_wake_some_streams(struct h2c *h2c, int last, uint32_t flags) { struct eb32_node *node; struct h2s *h2s; if (h2c->st0 >= H2_CS_ERROR || h2c->conn->flags & CO_FL_ERROR) flags |= CS_FL_ERROR; if (conn_xprt_read0_pending(h2c->conn)) flags |= CS_FL_EOS; node = eb32_lookup_ge(&h2c->streams_by_id, last + 1); while (node) { h2s = container_of(node, struct h2s, by_id); if (h2s->id <= last) break; node = eb32_next(node); if (!h2s->cs) { /* this stream was already orphaned */ h2s_destroy(h2s); continue; } h2s->cs->flags |= flags; /* recv is used to force to detect CS_FL_EOS that wake() * doesn't handle in the stream int code. */ h2s->cs->data_cb->recv(h2s->cs); h2s->cs->data_cb->wake(h2s->cs); if (flags & CS_FL_ERROR && h2s->st < H2_SS_ERROR) h2s->st = H2_SS_ERROR; else if (flags & CS_FL_EOS && h2s->st == H2_SS_OPEN) h2s->st = H2_SS_HREM; else if (flags & CS_FL_EOS && h2s->st == H2_SS_HLOC) h2s_close(h2s); } }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,186
static int h2c_ack_settings(struct h2c *h2c) { struct buffer *res; char str[9]; int ret = -1; if (h2c_mux_busy(h2c, NULL)) { h2c->flags |= H2_CF_DEM_MBUSY; return 0; } res = h2_get_buf(h2c, &h2c->mbuf); if (!res) { h2c->flags |= H2_CF_MUX_MALLOC; h2c->flags |= H2_CF_DEM_MROOM; return 0; } memcpy(str, "\x00\x00\x00" /* length : 0 (no data) */ "\x04" "\x01" /* type : 4, flags : ACK */ "\x00\x00\x00\x00" /* stream ID */, 9); ret = bo_istput(res, ist2(str, 9)); if (unlikely(ret <= 0)) { if (!ret) { h2c->flags |= H2_CF_MUX_MFULL; h2c->flags |= H2_CF_DEM_MROOM; return 0; } else { h2c_error(h2c, H2_ERR_INTERNAL_ERROR); return 0; } } return ret; }
Exec Code Overflow
0
static int h2c_ack_settings(struct h2c *h2c) { struct buffer *res; char str[9]; int ret = -1; if (h2c_mux_busy(h2c, NULL)) { h2c->flags |= H2_CF_DEM_MBUSY; return 0; } res = h2_get_buf(h2c, &h2c->mbuf); if (!res) { h2c->flags |= H2_CF_MUX_MALLOC; h2c->flags |= H2_CF_DEM_MROOM; return 0; } memcpy(str, "\x00\x00\x00" /* length : 0 (no data) */ "\x04" "\x01" /* type : 4, flags : ACK */ "\x00\x00\x00\x00" /* stream ID */, 9); ret = bo_istput(res, ist2(str, 9)); if (unlikely(ret <= 0)) { if (!ret) { h2c->flags |= H2_CF_MUX_MFULL; h2c->flags |= H2_CF_DEM_MROOM; return 0; } else { h2c_error(h2c, H2_ERR_INTERNAL_ERROR); return 0; } } return ret; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,187
static int h2c_frt_handle_data(struct h2c *h2c, struct h2s *h2s) { int error; /* note that empty DATA frames are perfectly valid and sometimes used * to signal an end of stream (with the ES flag). */ if (!h2c->dbuf->size && h2c->dfl) return 0; // empty buffer if (h2c->dbuf->i < h2c->dfl && h2c->dbuf->i < h2c->dbuf->size) return 0; // incomplete frame /* now either the frame is complete or the buffer is complete */ if (!h2c->dsi) { /* RFC7540#6.1 */ error = H2_ERR_PROTOCOL_ERROR; goto conn_err; } if (h2s->st != H2_SS_OPEN && h2s->st != H2_SS_HLOC) { /* RFC7540#6.1 */ error = H2_ERR_STREAM_CLOSED; goto strm_err; } /* call the upper layers to process the frame, then let the upper layer * notify the stream about any change. */ if (!h2s->cs) { error = H2_ERR_STREAM_CLOSED; goto strm_err; } h2s->cs->data_cb->recv(h2s->cs); if (h2s->cs->data_cb->wake(h2s->cs) < 0) { /* cs has just been destroyed, we have to kill h2s. */ error = H2_ERR_STREAM_CLOSED; goto strm_err; } if (h2c->st0 >= H2_CS_ERROR) return 0; if (h2s->st >= H2_SS_ERROR) { /* stream error : send RST_STREAM */ h2c->st0 = H2_CS_FRAME_E; } /* check for completion : the callee will change this to FRAME_A or * FRAME_H once done. */ if (h2c->st0 == H2_CS_FRAME_P) return 0; /* last frame */ if (h2c->dff & H2_F_DATA_END_STREAM) { h2s->st = H2_SS_HREM; h2s->flags |= H2_SF_ES_RCVD; } return 1; conn_err: h2c_error(h2c, error); return 0; strm_err: if (h2s) { h2s_error(h2s, error); h2c->st0 = H2_CS_FRAME_E; } else h2c_error(h2c, error); return 0; }
Exec Code Overflow
0
static int h2c_frt_handle_data(struct h2c *h2c, struct h2s *h2s) { int error; /* note that empty DATA frames are perfectly valid and sometimes used * to signal an end of stream (with the ES flag). */ if (!h2c->dbuf->size && h2c->dfl) return 0; // empty buffer if (h2c->dbuf->i < h2c->dfl && h2c->dbuf->i < h2c->dbuf->size) return 0; // incomplete frame /* now either the frame is complete or the buffer is complete */ if (!h2c->dsi) { /* RFC7540#6.1 */ error = H2_ERR_PROTOCOL_ERROR; goto conn_err; } if (h2s->st != H2_SS_OPEN && h2s->st != H2_SS_HLOC) { /* RFC7540#6.1 */ error = H2_ERR_STREAM_CLOSED; goto strm_err; } /* call the upper layers to process the frame, then let the upper layer * notify the stream about any change. */ if (!h2s->cs) { error = H2_ERR_STREAM_CLOSED; goto strm_err; } h2s->cs->data_cb->recv(h2s->cs); if (h2s->cs->data_cb->wake(h2s->cs) < 0) { /* cs has just been destroyed, we have to kill h2s. */ error = H2_ERR_STREAM_CLOSED; goto strm_err; } if (h2c->st0 >= H2_CS_ERROR) return 0; if (h2s->st >= H2_SS_ERROR) { /* stream error : send RST_STREAM */ h2c->st0 = H2_CS_FRAME_E; } /* check for completion : the callee will change this to FRAME_A or * FRAME_H once done. */ if (h2c->st0 == H2_CS_FRAME_P) return 0; /* last frame */ if (h2c->dff & H2_F_DATA_END_STREAM) { h2s->st = H2_SS_HREM; h2s->flags |= H2_SF_ES_RCVD; } return 1; conn_err: h2c_error(h2c, error); return 0; strm_err: if (h2s) { h2s_error(h2s, error); h2c->st0 = H2_CS_FRAME_E; } else h2c_error(h2c, error); return 0; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,188
static int h2c_frt_handle_headers(struct h2c *h2c, struct h2s *h2s) { int error; if (!h2c->dfl) { error = H2_ERR_PROTOCOL_ERROR; // empty headers frame! goto strm_err; } if (!h2c->dbuf->size) return 0; // empty buffer if (h2c->dbuf->i < h2c->dfl && h2c->dbuf->i < h2c->dbuf->size) return 0; // incomplete frame /* now either the frame is complete or the buffer is complete */ if (h2s->st != H2_SS_IDLE) { /* FIXME: stream already exists, this is only allowed for * trailers (not supported for now). */ error = H2_ERR_PROTOCOL_ERROR; goto conn_err; } else if (h2c->dsi <= h2c->max_id || !(h2c->dsi & 1)) { /* RFC7540#5.1.1 stream id > prev ones, and must be odd here */ error = H2_ERR_PROTOCOL_ERROR; goto conn_err; } h2s = h2c_stream_new(h2c, h2c->dsi); if (!h2s) { error = H2_ERR_INTERNAL_ERROR; goto conn_err; } h2s->st = H2_SS_OPEN; if (h2c->dff & H2_F_HEADERS_END_STREAM) { h2s->st = H2_SS_HREM; h2s->flags |= H2_SF_ES_RCVD; } /* call the upper layers to process the frame, then let the upper layer * notify the stream about any change. */ h2s->cs->data_cb->recv(h2s->cs); if (h2s->cs->data_cb->wake(h2s->cs) < 0) { /* FIXME: cs has already been destroyed, but we have to kill h2s. */ error = H2_ERR_INTERNAL_ERROR; goto conn_err; } if (h2c->st0 >= H2_CS_ERROR) return 0; if (h2s->st >= H2_SS_ERROR) { /* stream error : send RST_STREAM */ h2c->st0 = H2_CS_FRAME_E; } else { /* update the max stream ID if the request is being processed */ if (h2s->id > h2c->max_id) h2c->max_id = h2s->id; } return 1; conn_err: h2c_error(h2c, error); return 0; strm_err: if (h2s) { h2s_error(h2s, error); h2c->st0 = H2_CS_FRAME_E; } else h2c_error(h2c, error); return 0; }
Exec Code Overflow
0
static int h2c_frt_handle_headers(struct h2c *h2c, struct h2s *h2s) { int error; if (!h2c->dfl) { error = H2_ERR_PROTOCOL_ERROR; // empty headers frame! goto strm_err; } if (!h2c->dbuf->size) return 0; // empty buffer if (h2c->dbuf->i < h2c->dfl && h2c->dbuf->i < h2c->dbuf->size) return 0; // incomplete frame /* now either the frame is complete or the buffer is complete */ if (h2s->st != H2_SS_IDLE) { /* FIXME: stream already exists, this is only allowed for * trailers (not supported for now). */ error = H2_ERR_PROTOCOL_ERROR; goto conn_err; } else if (h2c->dsi <= h2c->max_id || !(h2c->dsi & 1)) { /* RFC7540#5.1.1 stream id > prev ones, and must be odd here */ error = H2_ERR_PROTOCOL_ERROR; goto conn_err; } h2s = h2c_stream_new(h2c, h2c->dsi); if (!h2s) { error = H2_ERR_INTERNAL_ERROR; goto conn_err; } h2s->st = H2_SS_OPEN; if (h2c->dff & H2_F_HEADERS_END_STREAM) { h2s->st = H2_SS_HREM; h2s->flags |= H2_SF_ES_RCVD; } /* call the upper layers to process the frame, then let the upper layer * notify the stream about any change. */ h2s->cs->data_cb->recv(h2s->cs); if (h2s->cs->data_cb->wake(h2s->cs) < 0) { /* FIXME: cs has already been destroyed, but we have to kill h2s. */ error = H2_ERR_INTERNAL_ERROR; goto conn_err; } if (h2c->st0 >= H2_CS_ERROR) return 0; if (h2s->st >= H2_SS_ERROR) { /* stream error : send RST_STREAM */ h2c->st0 = H2_CS_FRAME_E; } else { /* update the max stream ID if the request is being processed */ if (h2s->id > h2c->max_id) h2c->max_id = h2s->id; } return 1; conn_err: h2c_error(h2c, error); return 0; strm_err: if (h2s) { h2s_error(h2s, error); h2c->st0 = H2_CS_FRAME_E; } else h2c_error(h2c, error); return 0; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,189
static int h2c_frt_init(struct connection *conn) { struct h2c *h2c; struct task *t = NULL; struct session *sess = conn->owner; h2c = pool_alloc(pool_head_h2c); if (!h2c) goto fail; h2c->shut_timeout = h2c->timeout = sess->fe->timeout.client; if (tick_isset(sess->fe->timeout.clientfin)) h2c->shut_timeout = sess->fe->timeout.clientfin; h2c->task = NULL; if (tick_isset(h2c->timeout)) { t = task_new(tid_bit); if (!t) goto fail; h2c->task = t; t->process = h2_timeout_task; t->context = h2c; t->expire = tick_add(now_ms, h2c->timeout); } h2c->ddht = hpack_dht_alloc(h2_settings_header_table_size); if (!h2c->ddht) goto fail; /* Initialise the context. */ h2c->st0 = H2_CS_PREFACE; h2c->conn = conn; h2c->max_id = -1; h2c->errcode = H2_ERR_NO_ERROR; h2c->flags = H2_CF_NONE; h2c->rcvd_c = 0; h2c->rcvd_s = 0; h2c->nb_streams = 0; h2c->dbuf = &buf_empty; h2c->dsi = -1; h2c->msi = -1; h2c->last_sid = -1; h2c->mbuf = &buf_empty; h2c->miw = 65535; /* mux initial window size */ h2c->mws = 65535; /* mux window size */ h2c->mfs = 16384; /* initial max frame size */ h2c->streams_by_id = EB_ROOT_UNIQUE; LIST_INIT(&h2c->send_list); LIST_INIT(&h2c->fctl_list); LIST_INIT(&h2c->buf_wait.list); conn->mux_ctx = h2c; if (t) task_queue(t); conn_xprt_want_recv(conn); /* mux->wake will be called soon to complete the operation */ return 0; fail: if (t) task_free(t); pool_free(pool_head_h2c, h2c); return -1; }
Exec Code Overflow
0
static int h2c_frt_init(struct connection *conn) { struct h2c *h2c; struct task *t = NULL; struct session *sess = conn->owner; h2c = pool_alloc(pool_head_h2c); if (!h2c) goto fail; h2c->shut_timeout = h2c->timeout = sess->fe->timeout.client; if (tick_isset(sess->fe->timeout.clientfin)) h2c->shut_timeout = sess->fe->timeout.clientfin; h2c->task = NULL; if (tick_isset(h2c->timeout)) { t = task_new(tid_bit); if (!t) goto fail; h2c->task = t; t->process = h2_timeout_task; t->context = h2c; t->expire = tick_add(now_ms, h2c->timeout); } h2c->ddht = hpack_dht_alloc(h2_settings_header_table_size); if (!h2c->ddht) goto fail; /* Initialise the context. */ h2c->st0 = H2_CS_PREFACE; h2c->conn = conn; h2c->max_id = -1; h2c->errcode = H2_ERR_NO_ERROR; h2c->flags = H2_CF_NONE; h2c->rcvd_c = 0; h2c->rcvd_s = 0; h2c->nb_streams = 0; h2c->dbuf = &buf_empty; h2c->dsi = -1; h2c->msi = -1; h2c->last_sid = -1; h2c->mbuf = &buf_empty; h2c->miw = 65535; /* mux initial window size */ h2c->mws = 65535; /* mux window size */ h2c->mfs = 16384; /* initial max frame size */ h2c->streams_by_id = EB_ROOT_UNIQUE; LIST_INIT(&h2c->send_list); LIST_INIT(&h2c->fctl_list); LIST_INIT(&h2c->buf_wait.list); conn->mux_ctx = h2c; if (t) task_queue(t); conn_xprt_want_recv(conn); /* mux->wake will be called soon to complete the operation */ return 0; fail: if (t) task_free(t); pool_free(pool_head_h2c, h2c); return -1; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,190
static int h2c_frt_recv_preface(struct h2c *h2c) { int ret1; int ret2; ret1 = b_isteq(h2c->dbuf, 0, h2c->dbuf->i, ist(H2_CONN_PREFACE)); if (unlikely(ret1 <= 0)) { if (ret1 < 0 || conn_xprt_read0_pending(h2c->conn)) h2c_error(h2c, H2_ERR_PROTOCOL_ERROR); return 0; } ret2 = h2c_snd_settings(h2c); if (ret2 > 0) bi_del(h2c->dbuf, ret1); return ret2; }
Exec Code Overflow
0
static int h2c_frt_recv_preface(struct h2c *h2c) { int ret1; int ret2; ret1 = b_isteq(h2c->dbuf, 0, h2c->dbuf->i, ist(H2_CONN_PREFACE)); if (unlikely(ret1 <= 0)) { if (ret1 < 0 || conn_xprt_read0_pending(h2c->conn)) h2c_error(h2c, H2_ERR_PROTOCOL_ERROR); return 0; } ret2 = h2c_snd_settings(h2c); if (ret2 > 0) bi_del(h2c->dbuf, ret1); return ret2; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,191
static int h2c_handle_ping(struct h2c *h2c) { /* frame length must be exactly 8 */ if (h2c->dfl != 8) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); return 0; } /* schedule a response */ if (!(h2c->dff & H2_F_PING_ACK)) h2c->st0 = H2_CS_FRAME_A; return 1; }
Exec Code Overflow
0
static int h2c_handle_ping(struct h2c *h2c) { /* frame length must be exactly 8 */ if (h2c->dfl != 8) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); return 0; } /* schedule a response */ if (!(h2c->dff & H2_F_PING_ACK)) h2c->st0 = H2_CS_FRAME_A; return 1; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,192
static int h2c_handle_priority(struct h2c *h2c) { int error; if (h2c->dsi == 0) { error = H2_ERR_PROTOCOL_ERROR; goto conn_err; } if (h2c->dfl != 5) { error = H2_ERR_FRAME_SIZE_ERROR; goto conn_err; } /* process full frame only */ if (h2c->dbuf->i < h2c->dfl) return 0; if (h2_get_n32(h2c->dbuf, 0) == h2c->dsi) { /* 7540#5.3 : can't depend on itself */ error = H2_ERR_PROTOCOL_ERROR; goto conn_err; } return 1; conn_err: h2c_error(h2c, error); return 0; }
Exec Code Overflow
0
static int h2c_handle_priority(struct h2c *h2c) { int error; if (h2c->dsi == 0) { error = H2_ERR_PROTOCOL_ERROR; goto conn_err; } if (h2c->dfl != 5) { error = H2_ERR_FRAME_SIZE_ERROR; goto conn_err; } /* process full frame only */ if (h2c->dbuf->i < h2c->dfl) return 0; if (h2_get_n32(h2c->dbuf, 0) == h2c->dsi) { /* 7540#5.3 : can't depend on itself */ error = H2_ERR_PROTOCOL_ERROR; goto conn_err; } return 1; conn_err: h2c_error(h2c, error); return 0; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,193
static int h2c_handle_rst_stream(struct h2c *h2c, struct h2s *h2s) { int error; if (h2c->dsi == 0) { error = H2_ERR_PROTOCOL_ERROR; goto conn_err; } if (h2c->dfl != 4) { error = H2_ERR_FRAME_SIZE_ERROR; goto conn_err; } /* process full frame only */ if (h2c->dbuf->i < h2c->dfl) return 0; /* late RST, already handled */ if (h2s->st == H2_SS_CLOSED) return 1; h2s->errcode = h2_get_n32(h2c->dbuf, 0); h2s_close(h2s); if (h2s->cs) { h2s->cs->flags |= CS_FL_EOS | CS_FL_ERROR; /* recv is used to force to detect CS_FL_EOS that wake() * doesn't handle in the stream-int code. */ h2s->cs->data_cb->recv(h2s->cs); h2s->cs->data_cb->wake(h2s->cs); } h2s->flags |= H2_SF_RST_RCVD; return 1; conn_err: h2c_error(h2c, error); return 0; }
Exec Code Overflow
0
static int h2c_handle_rst_stream(struct h2c *h2c, struct h2s *h2s) { int error; if (h2c->dsi == 0) { error = H2_ERR_PROTOCOL_ERROR; goto conn_err; } if (h2c->dfl != 4) { error = H2_ERR_FRAME_SIZE_ERROR; goto conn_err; } /* process full frame only */ if (h2c->dbuf->i < h2c->dfl) return 0; /* late RST, already handled */ if (h2s->st == H2_SS_CLOSED) return 1; h2s->errcode = h2_get_n32(h2c->dbuf, 0); h2s_close(h2s); if (h2s->cs) { h2s->cs->flags |= CS_FL_EOS | CS_FL_ERROR; /* recv is used to force to detect CS_FL_EOS that wake() * doesn't handle in the stream-int code. */ h2s->cs->data_cb->recv(h2s->cs); h2s->cs->data_cb->wake(h2s->cs); } h2s->flags |= H2_SF_RST_RCVD; return 1; conn_err: h2c_error(h2c, error); return 0; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,194
static int h2c_handle_settings(struct h2c *h2c) { unsigned int offset; int error; if (h2c->dff & H2_F_SETTINGS_ACK) { if (h2c->dfl) { error = H2_ERR_FRAME_SIZE_ERROR; goto fail; } return 1; } if (h2c->dsi != 0) { error = H2_ERR_PROTOCOL_ERROR; goto fail; } if (h2c->dfl % 6) { error = H2_ERR_FRAME_SIZE_ERROR; goto fail; } /* that's the limit we can process */ if (h2c->dfl > global.tune.bufsize) { error = H2_ERR_FRAME_SIZE_ERROR; goto fail; } /* process full frame only */ if (h2c->dbuf->i < h2c->dfl) return 0; /* parse the frame */ for (offset = 0; offset < h2c->dfl; offset += 6) { uint16_t type = h2_get_n16(h2c->dbuf, offset); int32_t arg = h2_get_n32(h2c->dbuf, offset + 2); switch (type) { case H2_SETTINGS_INITIAL_WINDOW_SIZE: /* we need to update all existing streams with the * difference from the previous iws. */ if (arg < 0) { // RFC7540#6.5.2 error = H2_ERR_FLOW_CONTROL_ERROR; goto fail; } h2c_update_all_ws(h2c, arg - h2c->miw); h2c->miw = arg; break; case H2_SETTINGS_MAX_FRAME_SIZE: if (arg < 16384 || arg > 16777215) { // RFC7540#6.5.2 error = H2_ERR_PROTOCOL_ERROR; goto fail; } h2c->mfs = arg; break; case H2_SETTINGS_ENABLE_PUSH: if (arg < 0 || arg > 1) { // RFC7540#6.5.2 error = H2_ERR_PROTOCOL_ERROR; goto fail; } break; } } /* need to ACK this frame now */ h2c->st0 = H2_CS_FRAME_A; return 1; fail: h2c_error(h2c, error); return 0; }
Exec Code Overflow
0
static int h2c_handle_settings(struct h2c *h2c) { unsigned int offset; int error; if (h2c->dff & H2_F_SETTINGS_ACK) { if (h2c->dfl) { error = H2_ERR_FRAME_SIZE_ERROR; goto fail; } return 1; } if (h2c->dsi != 0) { error = H2_ERR_PROTOCOL_ERROR; goto fail; } if (h2c->dfl % 6) { error = H2_ERR_FRAME_SIZE_ERROR; goto fail; } /* that's the limit we can process */ if (h2c->dfl > global.tune.bufsize) { error = H2_ERR_FRAME_SIZE_ERROR; goto fail; } /* process full frame only */ if (h2c->dbuf->i < h2c->dfl) return 0; /* parse the frame */ for (offset = 0; offset < h2c->dfl; offset += 6) { uint16_t type = h2_get_n16(h2c->dbuf, offset); int32_t arg = h2_get_n32(h2c->dbuf, offset + 2); switch (type) { case H2_SETTINGS_INITIAL_WINDOW_SIZE: /* we need to update all existing streams with the * difference from the previous iws. */ if (arg < 0) { // RFC7540#6.5.2 error = H2_ERR_FLOW_CONTROL_ERROR; goto fail; } h2c_update_all_ws(h2c, arg - h2c->miw); h2c->miw = arg; break; case H2_SETTINGS_MAX_FRAME_SIZE: if (arg < 16384 || arg > 16777215) { // RFC7540#6.5.2 error = H2_ERR_PROTOCOL_ERROR; goto fail; } h2c->mfs = arg; break; case H2_SETTINGS_ENABLE_PUSH: if (arg < 0 || arg > 1) { // RFC7540#6.5.2 error = H2_ERR_PROTOCOL_ERROR; goto fail; } break; } } /* need to ACK this frame now */ h2c->st0 = H2_CS_FRAME_A; return 1; fail: h2c_error(h2c, error); return 0; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,195
static int h2c_handle_window_update(struct h2c *h2c, struct h2s *h2s) { int32_t inc; int error; if (h2c->dfl != 4) { error = H2_ERR_FRAME_SIZE_ERROR; goto conn_err; } /* process full frame only */ if (h2c->dbuf->i < h2c->dfl) return 0; inc = h2_get_n32(h2c->dbuf, 0); if (h2c->dsi != 0) { /* stream window update */ /* it's not an error to receive WU on a closed stream */ if (h2s->st == H2_SS_CLOSED) return 1; if (!inc) { error = H2_ERR_PROTOCOL_ERROR; goto strm_err; } if (h2s->mws >= 0 && h2s->mws + inc < 0) { error = H2_ERR_FLOW_CONTROL_ERROR; goto strm_err; } h2s->mws += inc; if (h2s->mws > 0 && (h2s->flags & H2_SF_BLK_SFCTL)) { h2s->flags &= ~H2_SF_BLK_SFCTL; if (h2s->cs && LIST_ISEMPTY(&h2s->list) && (h2s->cs->flags & CS_FL_DATA_WR_ENA)) { /* This stream wanted to send but could not due to its * own flow control. We can put it back into the send * list now, it will be handled upon next send() call. */ LIST_ADDQ(&h2c->send_list, &h2s->list); } } } else { /* connection window update */ if (!inc) { error = H2_ERR_PROTOCOL_ERROR; goto conn_err; } if (h2c->mws >= 0 && h2c->mws + inc < 0) { error = H2_ERR_FLOW_CONTROL_ERROR; goto conn_err; } h2c->mws += inc; } return 1; conn_err: h2c_error(h2c, error); return 0; strm_err: if (h2s) { h2s_error(h2s, error); h2c->st0 = H2_CS_FRAME_E; } else h2c_error(h2c, error); return 0; }
Exec Code Overflow
0
static int h2c_handle_window_update(struct h2c *h2c, struct h2s *h2s) { int32_t inc; int error; if (h2c->dfl != 4) { error = H2_ERR_FRAME_SIZE_ERROR; goto conn_err; } /* process full frame only */ if (h2c->dbuf->i < h2c->dfl) return 0; inc = h2_get_n32(h2c->dbuf, 0); if (h2c->dsi != 0) { /* stream window update */ /* it's not an error to receive WU on a closed stream */ if (h2s->st == H2_SS_CLOSED) return 1; if (!inc) { error = H2_ERR_PROTOCOL_ERROR; goto strm_err; } if (h2s->mws >= 0 && h2s->mws + inc < 0) { error = H2_ERR_FLOW_CONTROL_ERROR; goto strm_err; } h2s->mws += inc; if (h2s->mws > 0 && (h2s->flags & H2_SF_BLK_SFCTL)) { h2s->flags &= ~H2_SF_BLK_SFCTL; if (h2s->cs && LIST_ISEMPTY(&h2s->list) && (h2s->cs->flags & CS_FL_DATA_WR_ENA)) { /* This stream wanted to send but could not due to its * own flow control. We can put it back into the send * list now, it will be handled upon next send() call. */ LIST_ADDQ(&h2c->send_list, &h2s->list); } } } else { /* connection window update */ if (!inc) { error = H2_ERR_PROTOCOL_ERROR; goto conn_err; } if (h2c->mws >= 0 && h2c->mws + inc < 0) { error = H2_ERR_FLOW_CONTROL_ERROR; goto conn_err; } h2c->mws += inc; } return 1; conn_err: h2c_error(h2c, error); return 0; strm_err: if (h2s) { h2s_error(h2s, error); h2c->st0 = H2_CS_FRAME_E; } else h2c_error(h2c, error); return 0; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,196
static int h2c_send_goaway_error(struct h2c *h2c, struct h2s *h2s) { struct buffer *res; char str[17]; int ret; if (h2c->flags & H2_CF_GOAWAY_FAILED) return 1; // claim that it worked if (h2c_mux_busy(h2c, h2s)) { if (h2s) h2s->flags |= H2_SF_BLK_MBUSY; else h2c->flags |= H2_CF_DEM_MBUSY; return 0; } res = h2_get_buf(h2c, &h2c->mbuf); if (!res) { h2c->flags |= H2_CF_MUX_MALLOC; if (h2s) h2s->flags |= H2_SF_BLK_MROOM; else h2c->flags |= H2_CF_DEM_MROOM; return 0; } /* len: 8, type: 7, flags: none, sid: 0 */ memcpy(str, "\x00\x00\x08\x07\x00\x00\x00\x00\x00", 9); if (h2c->last_sid < 0) h2c->last_sid = h2c->max_id; write_n32(str + 9, h2c->last_sid); write_n32(str + 13, h2c->errcode); ret = bo_istput(res, ist2(str, 17)); if (unlikely(ret <= 0)) { if (!ret) { h2c->flags |= H2_CF_MUX_MFULL; if (h2s) h2s->flags |= H2_SF_BLK_MROOM; else h2c->flags |= H2_CF_DEM_MROOM; return 0; } else { /* we cannot report this error using GOAWAY, so we mark * it and claim a success. */ h2c_error(h2c, H2_ERR_INTERNAL_ERROR); h2c->flags |= H2_CF_GOAWAY_FAILED; return 1; } } h2c->flags |= H2_CF_GOAWAY_SENT; return ret; }
Exec Code Overflow
0
static int h2c_send_goaway_error(struct h2c *h2c, struct h2s *h2s) { struct buffer *res; char str[17]; int ret; if (h2c->flags & H2_CF_GOAWAY_FAILED) return 1; // claim that it worked if (h2c_mux_busy(h2c, h2s)) { if (h2s) h2s->flags |= H2_SF_BLK_MBUSY; else h2c->flags |= H2_CF_DEM_MBUSY; return 0; } res = h2_get_buf(h2c, &h2c->mbuf); if (!res) { h2c->flags |= H2_CF_MUX_MALLOC; if (h2s) h2s->flags |= H2_SF_BLK_MROOM; else h2c->flags |= H2_CF_DEM_MROOM; return 0; } /* len: 8, type: 7, flags: none, sid: 0 */ memcpy(str, "\x00\x00\x08\x07\x00\x00\x00\x00\x00", 9); if (h2c->last_sid < 0) h2c->last_sid = h2c->max_id; write_n32(str + 9, h2c->last_sid); write_n32(str + 13, h2c->errcode); ret = bo_istput(res, ist2(str, 17)); if (unlikely(ret <= 0)) { if (!ret) { h2c->flags |= H2_CF_MUX_MFULL; if (h2s) h2s->flags |= H2_SF_BLK_MROOM; else h2c->flags |= H2_CF_DEM_MROOM; return 0; } else { /* we cannot report this error using GOAWAY, so we mark * it and claim a success. */ h2c_error(h2c, H2_ERR_INTERNAL_ERROR); h2c->flags |= H2_CF_GOAWAY_FAILED; return 1; } } h2c->flags |= H2_CF_GOAWAY_SENT; return ret; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,197
static int h2c_send_rst_stream(struct h2c *h2c, struct h2s *h2s) { struct buffer *res; char str[13]; int ret; /* RFC7540#5.4.2: To avoid looping, an endpoint MUST NOT send a * RST_STREAM in response to a RST_STREAM frame. */ if (h2c->dft == H2_FT_RST_STREAM) { ret = 1; goto ignore; } if (h2c_mux_busy(h2c, h2s)) { h2c->flags |= H2_CF_DEM_MBUSY; return 0; } res = h2_get_buf(h2c, &h2c->mbuf); if (!res) { h2c->flags |= H2_CF_MUX_MALLOC; h2c->flags |= H2_CF_DEM_MROOM; return 0; } /* len: 4, type: 3, flags: none */ memcpy(str, "\x00\x00\x04\x03\x00", 5); write_n32(str + 5, h2c->dsi); write_n32(str + 9, (h2s->st > H2_SS_IDLE && h2s->st < H2_SS_CLOSED) ? h2s->errcode : H2_ERR_STREAM_CLOSED); ret = bo_istput(res, ist2(str, 13)); if (unlikely(ret <= 0)) { if (!ret) { h2c->flags |= H2_CF_MUX_MFULL; h2c->flags |= H2_CF_DEM_MROOM; return 0; } else { h2c_error(h2c, H2_ERR_INTERNAL_ERROR); return 0; } } ignore: if (h2s->st > H2_SS_IDLE && h2s->st < H2_SS_CLOSED) { h2s->flags |= H2_SF_RST_SENT; h2s_close(h2s); } return ret; }
Exec Code Overflow
0
static int h2c_send_rst_stream(struct h2c *h2c, struct h2s *h2s) { struct buffer *res; char str[13]; int ret; /* RFC7540#5.4.2: To avoid looping, an endpoint MUST NOT send a * RST_STREAM in response to a RST_STREAM frame. */ if (h2c->dft == H2_FT_RST_STREAM) { ret = 1; goto ignore; } if (h2c_mux_busy(h2c, h2s)) { h2c->flags |= H2_CF_DEM_MBUSY; return 0; } res = h2_get_buf(h2c, &h2c->mbuf); if (!res) { h2c->flags |= H2_CF_MUX_MALLOC; h2c->flags |= H2_CF_DEM_MROOM; return 0; } /* len: 4, type: 3, flags: none */ memcpy(str, "\x00\x00\x04\x03\x00", 5); write_n32(str + 5, h2c->dsi); write_n32(str + 9, (h2s->st > H2_SS_IDLE && h2s->st < H2_SS_CLOSED) ? h2s->errcode : H2_ERR_STREAM_CLOSED); ret = bo_istput(res, ist2(str, 13)); if (unlikely(ret <= 0)) { if (!ret) { h2c->flags |= H2_CF_MUX_MFULL; h2c->flags |= H2_CF_DEM_MROOM; return 0; } else { h2c_error(h2c, H2_ERR_INTERNAL_ERROR); return 0; } } ignore: if (h2s->st > H2_SS_IDLE && h2s->st < H2_SS_CLOSED) { h2s->flags |= H2_SF_RST_SENT; h2s_close(h2s); } return ret; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,198
static int h2c_send_strm_wu(struct h2c *h2c) { int ret = 1; if (h2c->rcvd_s <= 0) return 1; /* send WU for the stream */ ret = h2c_send_window_update(h2c, h2c->dsi, h2c->rcvd_s); if (ret > 0) h2c->rcvd_s = 0; return ret; }
Exec Code Overflow
0
static int h2c_send_strm_wu(struct h2c *h2c) { int ret = 1; if (h2c->rcvd_s <= 0) return 1; /* send WU for the stream */ ret = h2c_send_window_update(h2c, h2c->dsi, h2c->rcvd_s); if (ret > 0) h2c->rcvd_s = 0; return ret; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null
6,199
static int h2c_snd_settings(struct h2c *h2c) { struct buffer *res; char buf_data[100]; // enough for 15 settings struct chunk buf; int ret; if (h2c_mux_busy(h2c, NULL)) { h2c->flags |= H2_CF_DEM_MBUSY; return 0; } res = h2_get_buf(h2c, &h2c->mbuf); if (!res) { h2c->flags |= H2_CF_MUX_MALLOC; h2c->flags |= H2_CF_DEM_MROOM; return 0; } chunk_init(&buf, buf_data, sizeof(buf_data)); chunk_memcpy(&buf, "\x00\x00\x00" /* length : 0 for now */ "\x04\x00" /* type : 4 (settings), flags : 0 */ "\x00\x00\x00\x00", /* stream ID : 0 */ 9); if (h2_settings_header_table_size != 4096) { char str[6] = "\x00\x01"; /* header_table_size */ write_n32(str + 2, h2_settings_header_table_size); chunk_memcat(&buf, str, 6); } if (h2_settings_initial_window_size != 65535) { char str[6] = "\x00\x04"; /* initial_window_size */ write_n32(str + 2, h2_settings_initial_window_size); chunk_memcat(&buf, str, 6); } if (h2_settings_max_concurrent_streams != 0) { char str[6] = "\x00\x03"; /* max_concurrent_streams */ /* Note: 0 means "unlimited" for haproxy's config but not for * the protocol, so never send this value! */ write_n32(str + 2, h2_settings_max_concurrent_streams); chunk_memcat(&buf, str, 6); } if (global.tune.bufsize != 16384) { char str[6] = "\x00\x05"; /* max_frame_size */ /* note: similarly we could also emit MAX_HEADER_LIST_SIZE to * match bufsize - rewrite size, but at the moment it seems * that clients don't take care of it. */ write_n32(str + 2, global.tune.bufsize); chunk_memcat(&buf, str, 6); } h2_set_frame_size(buf.str, buf.len - 9); ret = bo_istput(res, ist2(buf.str, buf.len)); if (unlikely(ret <= 0)) { if (!ret) { h2c->flags |= H2_CF_MUX_MFULL; h2c->flags |= H2_CF_DEM_MROOM; return 0; } else { h2c_error(h2c, H2_ERR_INTERNAL_ERROR); return 0; } } return ret; }
Exec Code Overflow
0
static int h2c_snd_settings(struct h2c *h2c) { struct buffer *res; char buf_data[100]; // enough for 15 settings struct chunk buf; int ret; if (h2c_mux_busy(h2c, NULL)) { h2c->flags |= H2_CF_DEM_MBUSY; return 0; } res = h2_get_buf(h2c, &h2c->mbuf); if (!res) { h2c->flags |= H2_CF_MUX_MALLOC; h2c->flags |= H2_CF_DEM_MROOM; return 0; } chunk_init(&buf, buf_data, sizeof(buf_data)); chunk_memcpy(&buf, "\x00\x00\x00" /* length : 0 for now */ "\x04\x00" /* type : 4 (settings), flags : 0 */ "\x00\x00\x00\x00", /* stream ID : 0 */ 9); if (h2_settings_header_table_size != 4096) { char str[6] = "\x00\x01"; /* header_table_size */ write_n32(str + 2, h2_settings_header_table_size); chunk_memcat(&buf, str, 6); } if (h2_settings_initial_window_size != 65535) { char str[6] = "\x00\x04"; /* initial_window_size */ write_n32(str + 2, h2_settings_initial_window_size); chunk_memcat(&buf, str, 6); } if (h2_settings_max_concurrent_streams != 0) { char str[6] = "\x00\x03"; /* max_concurrent_streams */ /* Note: 0 means "unlimited" for haproxy's config but not for * the protocol, so never send this value! */ write_n32(str + 2, h2_settings_max_concurrent_streams); chunk_memcat(&buf, str, 6); } if (global.tune.bufsize != 16384) { char str[6] = "\x00\x05"; /* max_frame_size */ /* note: similarly we could also emit MAX_HEADER_LIST_SIZE to * match bufsize - rewrite size, but at the moment it seems * that clients don't take care of it. */ write_n32(str + 2, global.tune.bufsize); chunk_memcat(&buf, str, 6); } h2_set_frame_size(buf.str, buf.len - 9); ret = bo_istput(res, ist2(buf.str, buf.len)); if (unlikely(ret <= 0)) { if (!ret) { h2c->flags |= H2_CF_MUX_MFULL; h2c->flags |= H2_CF_DEM_MROOM; return 0; } else { h2c_error(h2c, H2_ERR_INTERNAL_ERROR); return 0; } } return ret; }
@@ -1735,7 +1735,7 @@ static void h2_process_demux(struct h2c *h2c) goto fail; } - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { /* RFC7540#3.5: a GOAWAY frame MAY be omitted */ h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR2; @@ -1765,7 +1765,7 @@ static void h2_process_demux(struct h2c *h2c) if (!h2_peek_frame_hdr(h2c->dbuf, &hdr)) break; - if ((int)hdr.len < 0 || (int)hdr.len > h2c->mfs) { + if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) { h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR); h2c->st0 = H2_CS_ERROR; break;
CWE-119
null
null