… | |
… | |
66 | { |
66 | { |
67 | SET_ERRNO (E2BIG); |
67 | SET_ERRNO (E2BIG); |
68 | return 0; |
68 | return 0; |
69 | } |
69 | } |
70 | |
70 | |
|
|
71 | #if CHECK_INPUT |
|
|
72 | if (ip + ctrl > in_end) |
|
|
73 | { |
|
|
74 | SET_ERRNO (EINVAL); |
|
|
75 | return 0; |
|
|
76 | } |
|
|
77 | #endif |
|
|
78 | |
71 | #if USE_MEMCPY |
79 | #if USE_MEMCPY |
72 | memcpy (op, ip, ctrl); |
80 | memcpy (op, ip, ctrl); |
73 | op += ctrl; |
81 | op += ctrl; |
74 | ip += ctrl; |
82 | ip += ctrl; |
75 | #else |
83 | #else |
… | |
… | |
82 | { |
90 | { |
83 | unsigned int len = ctrl >> 5; |
91 | unsigned int len = ctrl >> 5; |
84 | |
92 | |
85 | u8 *ref = op - ((ctrl & 0x1f) << 8) - 1; |
93 | u8 *ref = op - ((ctrl & 0x1f) << 8) - 1; |
86 | |
94 | |
|
|
95 | #if CHECK_INPUT |
|
|
96 | if (ip >= in_end) |
|
|
97 | { |
|
|
98 | SET_ERRNO (EINVAL); |
|
|
99 | return 0; |
|
|
100 | } |
|
|
101 | #endif |
87 | if (len == 7) |
102 | if (len == 7) |
|
|
103 | { |
88 | len += *ip++; |
104 | len += *ip++; |
|
|
105 | #if CHECK_INPUT |
|
|
106 | if (ip >= in_end) |
|
|
107 | { |
|
|
108 | SET_ERRNO (EINVAL); |
|
|
109 | return 0; |
|
|
110 | } |
|
|
111 | #endif |
89 | |
112 | } |
|
|
113 | |
90 | ref -= *ip++; |
114 | ref -= *ip++; |
91 | |
115 | |
92 | if (op + len + 2 > out_end) |
116 | if (op + len + 2 > out_end) |
93 | { |
117 | { |
94 | SET_ERRNO (E2BIG); |
118 | SET_ERRNO (E2BIG); |
… | |
… | |
107 | do |
131 | do |
108 | *op++ = *ref++; |
132 | *op++ = *ref++; |
109 | while (--len); |
133 | while (--len); |
110 | } |
134 | } |
111 | } |
135 | } |
112 | while (op < out_end && ip < in_end); |
136 | while (ip < in_end); |
113 | |
137 | |
114 | return op - (u8 *)out_data; |
138 | return op - (u8 *)out_data; |
115 | } |
139 | } |
116 | |
140 | |