提交 219fd58b 编写于 作者: M M. Mohan Kumar 提交者: Eric Van Hensbergen

net/9p: Use proper data types

Use proper data types for storing the count of the binary blob and
length of a string. Without this patch length calculation of string will
always result in -1 because of comparision between signed and unsigned
integer.
Signed-off-by: NM. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: NVenkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: NEric Van Hensbergen <ericvh@gmail.com>
上级 af7542fc
...@@ -178,27 +178,24 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, ...@@ -178,27 +178,24 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt,
break; break;
case 's':{ case 's':{
char **sptr = va_arg(ap, char **); char **sptr = va_arg(ap, char **);
int16_t len; uint16_t len;
int size;
errcode = p9pdu_readf(pdu, proto_version, errcode = p9pdu_readf(pdu, proto_version,
"w", &len); "w", &len);
if (errcode) if (errcode)
break; break;
size = max_t(int16_t, len, 0); *sptr = kmalloc(len + 1, GFP_KERNEL);
*sptr = kmalloc(size + 1, GFP_KERNEL);
if (*sptr == NULL) { if (*sptr == NULL) {
errcode = -EFAULT; errcode = -EFAULT;
break; break;
} }
if (pdu_read(pdu, *sptr, size)) { if (pdu_read(pdu, *sptr, len)) {
errcode = -EFAULT; errcode = -EFAULT;
kfree(*sptr); kfree(*sptr);
*sptr = NULL; *sptr = NULL;
} else } else
(*sptr)[size] = 0; (*sptr)[len] = 0;
} }
break; break;
case 'Q':{ case 'Q':{
...@@ -234,14 +231,14 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, ...@@ -234,14 +231,14 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt,
} }
break; break;
case 'D':{ case 'D':{
int32_t *count = va_arg(ap, int32_t *); uint32_t *count = va_arg(ap, uint32_t *);
void **data = va_arg(ap, void **); void **data = va_arg(ap, void **);
errcode = errcode =
p9pdu_readf(pdu, proto_version, "d", count); p9pdu_readf(pdu, proto_version, "d", count);
if (!errcode) { if (!errcode) {
*count = *count =
min_t(int32_t, *count, min_t(uint32_t, *count,
pdu->size - pdu->offset); pdu->size - pdu->offset);
*data = &pdu->sdata[pdu->offset]; *data = &pdu->sdata[pdu->offset];
} }
...@@ -404,9 +401,10 @@ p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, const char *fmt, ...@@ -404,9 +401,10 @@ p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, const char *fmt,
break; break;
case 's':{ case 's':{
const char *sptr = va_arg(ap, const char *); const char *sptr = va_arg(ap, const char *);
int16_t len = 0; uint16_t len = 0;
if (sptr) if (sptr)
len = min_t(int16_t, strlen(sptr), USHRT_MAX); len = min_t(uint16_t, strlen(sptr),
USHRT_MAX);
errcode = p9pdu_writef(pdu, proto_version, errcode = p9pdu_writef(pdu, proto_version,
"w", len); "w", len);
...@@ -438,7 +436,7 @@ p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, const char *fmt, ...@@ -438,7 +436,7 @@ p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, const char *fmt,
stbuf->n_gid, stbuf->n_muid); stbuf->n_gid, stbuf->n_muid);
} break; } break;
case 'D':{ case 'D':{
int32_t count = va_arg(ap, int32_t); uint32_t count = va_arg(ap, uint32_t);
const void *data = va_arg(ap, const void *); const void *data = va_arg(ap, const void *);
errcode = p9pdu_writef(pdu, proto_version, "d", errcode = p9pdu_writef(pdu, proto_version, "d",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册