[PATCHv2] remote: Fix incorrect port option

Submitted by Radostin Stoyanov on Jan. 28, 2018, 9:10 p.m.

Details

Message ID 20180128211013.22935-1-rstoyanov1@gmail.com
State New
Series "remote: Fix incorrect port option"
Headers show

Commit Message

Radostin Stoyanov Jan. 28, 2018, 9:10 p.m.
The `port` option for image-cache and image-proxy is converted from
 unsigned short integer to network byte order twice.
- 1st when the argument is provided from the user (in crtools.c)
- 2nd when the value is provided set to `sin_port` (in img-remote.c)
Unfortunately the 2nd conversion reverses the 1st one.

Example:

	#include <stdio.h>
	#include <arpa/inet.h>
	#include <stdlib.h>

	int main()
	{
	    printf("%d\n", htons(atoi("1234"))); /* 53764 */
	    printf("%d\n", htons(htons(atoi("1234")))); /* 1234 */
	    return 0;
	}

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
---
 criu/crtools.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/criu/crtools.c b/criu/crtools.c
index 07bb2655..dffae5c8 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -719,7 +719,7 @@  int main(int argc, char *argv[], char *envp[])
 			opts.addr = optarg;
 			break;
 		case 1052:
-			opts.port = htons(atoi(optarg));
+			opts.port = atoi(optarg);
 			if (!opts.port)
 				goto bad_arg;
 			break;

Comments

Dmitry Safonov Jan. 29, 2018, 3:26 p.m.
2018-01-28 21:10 GMT+00:00 Radostin Stoyanov <rstoyanov1@gmail.com>:
> The `port` option for image-cache and image-proxy is converted from
>  unsigned short integer to network byte order twice.
> - 1st when the argument is provided from the user (in crtools.c)
> - 2nd when the value is provided set to `sin_port` (in img-remote.c)
> Unfortunately the 2nd conversion reverses the 1st one.
>
> Example:
>
>         #include <stdio.h>
>         #include <arpa/inet.h>
>         #include <stdlib.h>
>
>         int main()
>         {
>             printf("%d\n", htons(atoi("1234"))); /* 53764 */
>             printf("%d\n", htons(htons(atoi("1234")))); /* 1234 */
>             return 0;
>         }
>
> Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>

I wonder if we should also fix setup_opts_from_req()..