2013-09-26 51 views
1

我的代碼有問題不知何故變量receiver_buffer從函數external_auth_format_packet從json_packet或uu獲取一些數據。從receiver_buffer接收數據C變量和內存問題

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

但隨後楊松試圖解析它seeas數據數據不屬於該插座

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 

在這裏,您可以在日誌中看到變量

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

函數的源代碼 http://pastebin.com/P7WnhsqX

回答

1
​​

你複製received_chars字節,這是字符串的長度 - 它不包括終止「\ 0」字節。稍後,當您嘗試使用它時 - 您的字符串+緩衝區的其餘部分,因爲您不知道需要閱讀多少內容。

+0

你回答了哪個問題?在他的問題中,我看不出他在做什麼。 – dhein

+0

有問題的最後一個字符串包含指向源代碼的鏈接。 – keltar

+0

啊寬限期編輯...當我第一次看到他的答案,沒有鏈接到代碼,nevermind – dhein