[PATCH] Use unsigned types to handle negative error codes
John Lauro <[email protected]> Sat, 12 Oct 2013 02:41:26 -0400 (EDT)
| Newsgroups | gmane.network.poptop |
|---|---|
| Message-ID | <[email protected]> |
This is based off of git://git.code.sf.net/p/poptop/git. If I should base off a different or additional source, let me know. The one on sourceforge seems very old (6 years old). It would be nice get a minor update there, or a pointer if there is supposed to be a new home? This fixes 2 cases where read_pptp_packet and one for read_pptp_header is attempted to be tested for error condition of a value less than 0, but would never be caught because of comparing unsigned number to <0. Note: I have not fully tested the change under the newly exposed code paths, which might expose different bugs. Description: Use unsigned types to properly handle negative error codes Author: [email protected] --- a/ctrlpacket.c +++ b/ctrlpacket.c @@ -69,7 +69,7 @@ static int make_out_call_rqst(unsigned char *rply_packet, ssize_t * rply_size); int read_pptp_packet(int clientFd, unsigned char *packet, unsigned char *rply_packet, ssize_t * rply_size) { - size_t bytes_read; + ssize_t bytes_read; int pptp_ctrl_type = 0; /* Control Message Type */ /* read a packet and parse header */ @@ -133,7 +133,7 @@ int read_pptp_packet(int clientFd, unsigned char *packet, unsigned char *rply_pa * retn: Number of bytes written on success. * -1 on write failure. */ -size_t send_pptp_packet(int clientFd, unsigned char *packet, size_t packet_size) +ssize_t send_pptp_packet(int clientFd, unsigned char *packet, size_t packet_size) { size_t bytes_written; diff --git a/ctrlpacket.h b/ctrlpacket.h index d51ed2a..26449ec 100644 --- a/ctrlpacket.h +++ b/ctrlpacket.h @@ -10,7 +10,7 @@ #define _PPTPD_CTRLPACKET_H int read_pptp_packet(int clientFd, unsigned char *packet, unsigned char *rply_packet, ssize_t * rply_size); -size_t send_pptp_packet(int clientFd, unsigned char *packet, size_t packet_size); +ssize_t send_pptp_packet(int clientFd, unsigned char *packet, size_t packet_size); void make_echo_req_packet(unsigned char *rply_packet, ssize_t * rply_size, u_int32_t echo_id); void make_call_admin_shutdown(unsigned char *rply_packet, ssize_t * rply_size); void make_stop_ctrl_req(unsigned char *rply_packet, ssize_t * rply_size); ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk