this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement `__simple_vsnprintf`

...and use it in the various printing functions, instead of `__simple_vsprintf`. This fixes some buffer overflow issues with really long messages (like for applications with long path names when logging the execv expansion message).

Also, install an empty `/Library/Preferences` directory.

+72 -17
+2
CMakeLists.txt
··· 153 153 154 154 InstallSymlink(/Volumes/SystemRoot/usr/share/zoneinfo ${CMAKE_INSTALL_PREFIX}/libexec/darling/usr/share/zoneinfo) 155 155 156 + install(DIRECTORY DESTINATION libexec/darling/Library/Preferences) 157 + 156 158 if(NOT DEBIAN_PACKAGING) 157 159 install(CODE "execute_process(COMMAND bash ${DARLING_TOP_DIRECTORY}/tools/shutdown-user.sh)") 158 160 endif(NOT DEBIAN_PACKAGING)
+67 -17
src/kernel/emulation/linux/simple.c
··· 6 6 #include <lkm/api.h> 7 7 #include "mach/lkm.h" 8 8 9 - int __simple_vsprintf(char* buf, const char* format, va_list vl); 10 9 extern char* memchr(char* buf, int c, __SIZE_TYPE__ n); 11 10 12 11 __attribute__ ((visibility ("default"))) ··· 24 23 } 25 24 26 25 __attribute__ ((visibility ("default"))) 27 - int __simple_vsprintf(char* buf, const char* format, va_list vl) 26 + int __simple_vsnprintf(char* buf, size_t max_length, const char* format, va_list vl) 28 27 { 29 - char* initial_buf = buf; 28 + size_t offset = 0; 30 29 while (*format) 31 30 { 32 31 if (*format == '%') ··· 40 39 switch (*format) 41 40 { 42 41 case '%': 43 - *buf++ = '%'; 42 + if (offset < max_length) 43 + buf[offset] = '%'; 44 + offset++; 44 45 break; 45 46 case 's': 46 47 { ··· 50 51 51 52 while (*str) 52 53 { 53 - *buf++ = *str; 54 + if (offset < max_length) 55 + buf[offset] = *str; 56 + offset++; 54 57 str++; 55 58 } 56 59 break; ··· 63 66 64 67 if (num < 0) 65 68 { 66 - *buf++ = '-'; 69 + if (offset < max_length) 70 + buf[offset] = '-'; 71 + offset++; 67 72 num = -num; 68 73 } 69 74 ··· 75 80 while (num > 0); 76 81 77 82 while (count--) 78 - *buf++ = temp[count]; 83 + { 84 + if (offset < max_length) 85 + buf[offset] = temp[count]; 86 + offset++; 87 + } 79 88 80 89 break; 81 90 } ··· 93 102 while (num > 0); 94 103 95 104 while (count--) 96 - *buf++ = temp[count]; 105 + { 106 + if (offset < max_length) 107 + buf[offset] = temp[count]; 108 + offset++; 109 + } 97 110 98 111 break; 99 112 } ··· 106 119 107 120 if (*format == 'p') 108 121 { 109 - *buf++ = '0'; 110 - *buf++ = 'x'; 122 + if (offset < max_length) 123 + buf[offset] = '0'; 124 + offset++; 125 + if (offset < max_length) 126 + buf[offset] = 'x'; 127 + offset++; 111 128 } 112 129 113 130 do ··· 123 140 while (num > 0); 124 141 125 142 while (count--) 126 - *buf++ = temp[count]; 143 + { 144 + if (offset < max_length) 145 + buf[offset] = temp[count]; 146 + offset++; 147 + } 127 148 128 149 break; 129 150 ··· 134 155 } 135 156 else 136 157 { 137 - *buf++ = *format; 158 + if (offset < max_length) 159 + buf[offset] = *format; 160 + offset++; 138 161 format++; 139 162 } 140 163 } 141 164 142 - *buf = 0; 143 - return buf - initial_buf; 165 + if (offset < max_length) 166 + { 167 + buf[offset] = '\0'; 168 + } 169 + else 170 + { 171 + buf[max_length - 1] = '\0'; 172 + } 173 + 174 + return offset; 175 + } 176 + 177 + __attribute__ ((visibility ("default"))) 178 + int __simple_vsprintf(char* buf, const char* format, va_list vl) 179 + { 180 + return __simple_vsnprintf(buf, SIZE_MAX, format, vl); 144 181 } 145 182 146 183 __attribute__ ((visibility ("default"))) ··· 150 187 va_list vl; 151 188 152 189 va_start(vl, format); 153 - __simple_vsprintf(buffer, format, vl); 190 + __simple_vsnprintf(buffer, sizeof(buffer), format, vl); 154 191 va_end(vl); 155 192 156 193 LINUX_SYSCALL3(__NR_write, 1, buffer, __simple_strlen(buffer)); ··· 163 200 va_list vl; 164 201 165 202 va_start(vl, format); 166 - __simple_vsprintf(buffer, format, vl); 203 + __simple_vsnprintf(buffer, sizeof(buffer), format, vl); 167 204 va_end(vl); 168 205 169 206 lkm_call(NR_kernel_printk, buffer); ··· 176 213 va_list vl; 177 214 178 215 va_start(vl, format); 179 - __simple_vsprintf(buffer, format, vl); 216 + __simple_vsnprintf(buffer, sizeof(buffer), format, vl); 180 217 va_end(vl); 181 218 182 219 LINUX_SYSCALL3(__NR_write, fd, buffer, __simple_strlen(buffer)); ··· 190 227 va_start(vl, format); 191 228 int ret = __simple_vsprintf(buffer, format, vl); 192 229 va_end(vl); 230 + 231 + return ret; 232 + } 233 + 234 + __attribute__ ((visibility ("default"))) 235 + int __simple_snprintf(char* buffer, size_t max_length, const char* format, ...) 236 + { 237 + va_list args; 238 + int ret; 239 + 240 + va_start(args, format); 241 + ret = __simple_vsnprintf(buffer, max_length, format, args); 242 + va_end(args); 193 243 194 244 return ret; 195 245 }
+3
src/kernel/emulation/linux/simple.h
··· 2 2 #define LINUX_DEBUG_H 3 3 4 4 #include <stdarg.h> 5 + #include <stddef.h> 5 6 6 7 // everything in this header can be used outside of libsystem_kernel 7 8 ··· 15 16 int __simple_sprintf(char *buffer, const char* format, ...) __attribute__((format(printf, 2, 3))); 16 17 int __simple_strlen(const char* str); 17 18 int __simple_vsprintf(char* buf, const char* format, va_list vl) __attribute__((format(printf, 2, 0))); 19 + int __simple_vsnprintf(char* buffer, size_t max_length, const char* format, va_list args) __attribute__((format(printf, 3, 0))); 20 + int __simple_snprintf(char* buffer, size_t max_length, const char* format, ...) __attribute__((format(printf, 3, 4))); 18 21 19 22 unsigned long long __simple_atoi(const char* str, const char** endp); 20 23 unsigned long long __simple_atoi16(const char* str, const char** endp);