net/9p: Use proper data types
Subsystems (2)
PATCH 1/1 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.
--- net/9p/protocol.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
net/9p/protocol.c +4 -4
@@ -234,14 +234,14 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, }break ;case 'D' :{ - int32_t *count = va_arg(ap, int32_t *); + uint32_t *count = va_arg(ap, int32_t *); void **data = va_arg(ap, void **); errcode =p9pdu_readf (pdu, proto_version,"d" , count);if (!errcode) { *count = -min_t (int32_t, *count, +min_t (uint32_t, *count, pdu->size - pdu->offset); *data = &pdu->sdata[pdu->offset]; }
@@ -404,9 +404,9 @@ p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, const char *fmt,break ;case 's' :{ const char *sptr = va_arg(ap, const char *); -int16_t len =0 ; +uint16_t len =0 ;if (sptr) - len =min_t (int16_t,strlen (sptr), + len =min_t (uint16_t,strlen (sptr),USHRT_MAX ); errcode = p9pdu_writef(pdu, proto_version,
Signature · 1 line
1.7.3.4
Commit 33551d7be66cec324c47990ed526b7fe327b011f net/9p/protocol.c: Remove duplicated macros from Thiago Farina <[email protected]> exposed this issue
Quoted 33 lines · M. Mohan Kumar
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 M. Mohan Kumar <[email protected]>--- net/9p/protocol.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)net/9p/protocol.c +2
-2@@ -234,14 +234,14 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, } break;case 'D' :{ - int32_t *count = va_arg(ap, int32_t *); + uint32_t *count = va_arg(ap, int32_t *); void **data = va_arg(ap, void **); errcode =p9pdu_readf (pdu, proto_version,"d" , count);if (!errcode) { *count = -min_t (int32_t, *count, +min_t (uint32_t, *count, pdu->size - pdu->offset); *data = &pdu->sdata[pdu->offset]; }@@ -404,9 +404,9 @@ p9pdu_vwritef(struct p9_fcall *pdu, int proto_version,const char *fmt, break;
net/9p/protocol.c p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, · line 412
Quoted 10 lines
net/9p/protocol.c +2
-2case 's' :{ const char *sptr = va_arg(ap, const char *); -int16_t len =0 ; +uint16_t len =0 ;if (sptr) - len =min_t (int16_t,strlen (sptr), + len =min_t (uint16_t,strlen (sptr),USHRT_MAX ); errcode = p9pdu_writef(pdu, proto_version,
----
M. Mohan Kumar
Quoted 15 lines · M. Mohan Kumar
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 M. Mohan Kumar <[email protected]>--- net/9p/protocol.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)net/9p/protocol.c +0
-0
net/9p/protocol.c p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, · line 237
Quoted 5 lines
net/9p/protocol.c +1
-1@@ -234,14 +234,14 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, }break ;case 'D' :{ - int32_t *count = va_arg(ap, int32_t *); + uint32_t *count = va_arg(ap, int32_t *);
uinit32_t * inside the va_arg also to be consistent?
net/9p/protocol.c p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, · line 247
Quoted 11 lines
net/9p/protocol.c +1
-1void **data = va_arg(ap, void **); errcode =p9pdu_readf (pdu, proto_version,"d" , count);if (!errcode) { *count = -min_t (int32_t, *count, +min_t (uint32_t, *count, pdu->size - pdu->offset); *data = &pdu->sdata[pdu->offset]; }
Did you take care of MAX/max_t comparisons too? Looks like you missed at least one for case 's'
Thanks,
JV
Quoted 12 lines
net/9p/protocol.c +2
-2@@ -404,9 +404,9 @@ p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, const char *fmt,break ;case 's' :{ const char *sptr = va_arg(ap, const char *); -int16_t len =0 ; +uint16_t len =0 ;if (sptr) - len =min_t (int16_t,strlen (sptr), + len =min_t (uint16_t,strlen (sptr),USHRT_MAX ); errcode = p9pdu_writef(pdu, proto_version,