remote: Fix incorrect passing of port option

Submitted by Radostin Stoyanov on Jan. 28, 2018, 4:18 p.m.

Details

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

Commit Message

Radostin Stoyanov Jan. 28, 2018, 4:18 p.m.
The `port` option for image-cache and image-proxy is converted 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;
	}
---
 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;