1

我的代码有问题,变量receiver_buffer从json_packet或函数external_auth_format_packet中的uu获取一些数据。

在这里您可以在日志中看到:

Sep 26 12:35:07 ubuntu sshd[58912]: userauth_external: DEBUG: socket_path: /tmp/auth.sock
Sep 26 12:35:07 ubuntu sshd[58912]: userauth_external: DEBUG: json_packet: {"user": "root", "key": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDwHDG/TpoUDts9CFrUWh6eoOlPcQYTLIpkF1udDaRZMsdZSZyDsWO5otqrUiQuVLFBXKa4CMiYBJIll2Ye/ZMWjbWd6mkrhE/u4Ha+DS6wyoza3mgn4ekDYxHqzk6/9kVnNtdh+sw3h0OwhkJJG/fAGzGFZhaV5bRS8f9u6pxIKTdmUfozkfe/QhYlFS9gaFnlK2rn8efK1oeNL00YBEcFLVeFdFqU9xuTOrHIQuOHxEynF/zekJ69D1MDhLZDhzq7mfy00wOnS51Q0gxZUdBiFr0ahuD/WrxKgwYunAsp1hD22+WU89vmoPtonWE7a6hTeZtz6Mb0YPfmRwz+CaR1", "type": "ssh-rsa"}
Sep 26 12:35:07 ubuntu sshd[58912]: userauth_external: DEBUG: sent json_packet to server
Sep 26 12:35:07 ubuntu sshd[58912]: userauth_external: DEBUG: receiver_buffer memory allocation
Sep 26 12:35:07 ubuntu sshd[58912]: userauth_external: DEBUG: recv has received: {"status":1,"command":"command='./gitserve' "}
Sep 26 12:35:07 ubuntu sshd[58912]: userauth_external: DEBUG: copying from tmp_buffer to receiver_buffer
Sep 26 12:35:07 ubuntu sshd[58912]: userauth_external: DEBUG: finished receiving data from socket
Sep 26 12:35:07 ubuntu sshd[58912]: error: userauth_external: ERROR: Unable to load parmaters! error: on line 1: end of file expected near 'rUWh'\n
Sep 26 12:35:07 ubuntu sshd[58912]: error: userauth_external: ERROR: response {"status":1,"command":"command='./gitserve' "}rUWh6eoOlPcQYTLIpkF1udDaRZMsdZSZyDsWO5otqrUiQuVLFBXKa4CMiYBJIll2Ye/ZMWjbWd6mkrhE/u4Ha+DS6wyoza3mgn4ekDYxHqzk6/9kVnNtdh+sw3h0OwhkJJG/fAGzGFZhaV5bRS8f9u6pxIKTdmUfozkfe/QhYlFS9gaFnlK2rn8efK1oeNL00YBEcFLVeFdFqU9xuTOrHIQuOHxEynF/zekJ69D1MDhLZDhzq7mfy00wOnS51Q0gxZUdBiFr0ahuD/WrxKgwYunAsp1hD22+WU89vmoPtonWE7a6hTeZtz6Mb0YPfmRwz+CaR1

从套接字receiver_buffer 接收数据

{"status":1,"command":"command='./gitserve' "}

但随后 jansson 尝试将它看到的数据解析为不属于该变量的数据

{"status":1,"command":"command='./gitserve' "}rUWh6eoOlPcQYTLIpkF1udDaRZMsdZSZyDsWO5otqrUiQuVLFBXKa4CMiYBJIll2Ye/ZMWjbWd6mkrhE/u4Ha+DS6wyoza3mgn4ekDYxHqzk6/9kVnNtdh+sw3h0OwhkJJG/fAGzGFZhaV5bRS8f9u6pxIKTdmUfozkfe/QhYlFS9gaFnlK2rn8efK1oeNL00YBEcFLVeFdFqU9xuTOrHIQuOHxEynF/zekJ69D1MDhLZDhzq7mfy00wOnS51Q0gxZUdBiFr0ahuD/WrxKgwYunAsp1hD22+WU89vmoPtonWE7a6hTeZtz6Mb0YPfmRwz+CaR1`

函数源代码 http://pastebin.com/P7WnhsqX

4

1 回答 1

1
memcpy(receiver_buffer + total_received_chars, tmp_buffer, received_chars);

您正在复制 received_chars 字节,这是字符串长度 - 它不包括终止 '\0' 字节。稍后,当您尝试使用它时-您有字符串+缓冲区的其余部分,因为您不知道需要阅读多少。

于 2013-09-26T11:40:31.097 回答