misc.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  1. /*
  2. * Platform-independent routines shared between all PuTTY programs.
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdarg.h>
  7. #include <limits.h>
  8. #include <ctype.h>
  9. #include <assert.h>
  10. #include "putty.h"
  11. #include "misc.h"
  12. /*
  13. * Parse a string block size specification. This is approximately a
  14. * subset of the block size specs supported by GNU fileutils:
  15. * "nk" = n kilobytes
  16. * "nM" = n megabytes
  17. * "nG" = n gigabytes
  18. * All numbers are decimal, and suffixes refer to powers of two.
  19. * Case-insensitive.
  20. */
  21. unsigned long parse_blocksize(const char *bs)
  22. {
  23. char *suf;
  24. unsigned long r = strtoul(bs, &suf, 10);
  25. if (*suf != '\0') {
  26. while (*suf && isspace((unsigned char)*suf)) suf++;
  27. switch (*suf) {
  28. case 'k': case 'K':
  29. r *= 1024ul;
  30. break;
  31. case 'm': case 'M':
  32. r *= 1024ul * 1024ul;
  33. break;
  34. case 'g': case 'G':
  35. r *= 1024ul * 1024ul * 1024ul;
  36. break;
  37. case '\0':
  38. default:
  39. break;
  40. }
  41. }
  42. return r;
  43. }
  44. /*
  45. * Parse a ^C style character specification.
  46. * Returns NULL in `next' if we didn't recognise it as a control character,
  47. * in which case `c' should be ignored.
  48. * The precise current parsing is an oddity inherited from the terminal
  49. * answerback-string parsing code. All sequences start with ^; all except
  50. * ^<123> are two characters. The ones that are worth keeping are probably:
  51. * ^? 127
  52. * ^@A-Z[\]^_ 0-31
  53. * a-z 1-26
  54. * <num> specified by number (decimal, 0octal, 0xHEX)
  55. * ~ ^ escape
  56. */
  57. char ctrlparse(char *s, char **next)
  58. {
  59. char c = 0;
  60. if (*s != '^') {
  61. *next = NULL;
  62. } else {
  63. s++;
  64. if (*s == '\0') {
  65. *next = NULL;
  66. } else if (*s == '<') {
  67. s++;
  68. c = (char)strtol(s, next, 0);
  69. if ((*next == s) || (**next != '>')) {
  70. c = 0;
  71. *next = NULL;
  72. } else
  73. (*next)++;
  74. } else if (*s >= 'a' && *s <= 'z') {
  75. c = (*s - ('a' - 1));
  76. *next = s+1;
  77. } else if ((*s >= '@' && *s <= '_') || *s == '?' || (*s & 0x80)) {
  78. c = ('@' ^ *s);
  79. *next = s+1;
  80. } else if (*s == '~') {
  81. c = '^';
  82. *next = s+1;
  83. }
  84. }
  85. return c;
  86. }
  87. /*
  88. * Find a character in a string, unless it's a colon contained within
  89. * square brackets. Used for untangling strings of the form
  90. * 'host:port', where host can be an IPv6 literal.
  91. *
  92. * We provide several variants of this function, with semantics like
  93. * various standard string.h functions.
  94. */
  95. static const char *host_strchr_internal(const char *s, const char *set,
  96. bool first)
  97. {
  98. int brackets = 0;
  99. const char *ret = NULL;
  100. while (1) {
  101. if (!*s)
  102. return ret;
  103. if (*s == '[')
  104. brackets++;
  105. else if (*s == ']' && brackets > 0)
  106. brackets--;
  107. else if (brackets && *s == ':')
  108. /* never match */ ;
  109. else if (strchr(set, *s)) {
  110. ret = s;
  111. if (first)
  112. return ret;
  113. }
  114. s++;
  115. }
  116. }
  117. size_t host_strcspn(const char *s, const char *set)
  118. {
  119. const char *answer = host_strchr_internal(s, set, true);
  120. if (answer)
  121. return answer - s;
  122. else
  123. return strlen(s);
  124. }
  125. char *host_strchr(const char *s, int c)
  126. {
  127. char set[2];
  128. set[0] = c;
  129. set[1] = '\0';
  130. return (char *) host_strchr_internal(s, set, true);
  131. }
  132. char *host_strrchr(const char *s, int c)
  133. {
  134. char set[2];
  135. set[0] = c;
  136. set[1] = '\0';
  137. return (char *) host_strchr_internal(s, set, false);
  138. }
  139. #ifdef TEST_HOST_STRFOO
  140. int main(void)
  141. {
  142. int passes = 0, fails = 0;
  143. #define TEST1(func, string, arg2, suffix, result) do \
  144. { \
  145. const char *str = string; \
  146. unsigned ret = func(string, arg2) suffix; \
  147. if (ret == result) { \
  148. passes++; \
  149. } else { \
  150. printf("fail: %s(%s,%s)%s = %u, expected %u\n", \
  151. #func, #string, #arg2, #suffix, ret, \
  152. (unsigned)result); \
  153. fails++; \
  154. } \
  155. } while (0)
  156. TEST1(host_strchr, "[1:2:3]:4:5", ':', -str, 7);
  157. TEST1(host_strrchr, "[1:2:3]:4:5", ':', -str, 9);
  158. TEST1(host_strcspn, "[1:2:3]:4:5", "/:",, 7);
  159. TEST1(host_strchr, "[1:2:3]", ':', == NULL, 1);
  160. TEST1(host_strrchr, "[1:2:3]", ':', == NULL, 1);
  161. TEST1(host_strcspn, "[1:2:3]", "/:",, 7);
  162. TEST1(host_strcspn, "[1:2/3]", "/:",, 4);
  163. TEST1(host_strcspn, "[1:2:3]/", "/:",, 7);
  164. printf("passed %d failed %d total %d\n", passes, fails, passes+fails);
  165. return fails != 0 ? 1 : 0;
  166. }
  167. /* Stubs to stop the rest of this module causing compile failures. */
  168. void modalfatalbox(const char *fmt, ...) {}
  169. int conf_get_int(Conf *conf, int primary) { return 0; }
  170. char *conf_get_str(Conf *conf, int primary) { return NULL; }
  171. #endif /* TEST_HOST_STRFOO */
  172. /*
  173. * Trim square brackets off the outside of an IPv6 address literal.
  174. * Leave all other strings unchanged. Returns a fresh dynamically
  175. * allocated string.
  176. */
  177. char *host_strduptrim(const char *s)
  178. {
  179. if (s[0] == '[') {
  180. const char *p = s+1;
  181. int colons = 0;
  182. while (*p && *p != ']') {
  183. if (isxdigit((unsigned char)*p))
  184. /* OK */;
  185. else if (*p == ':')
  186. colons++;
  187. else
  188. break;
  189. p++;
  190. }
  191. if (*p == ']' && !p[1] && colons > 1) {
  192. /*
  193. * This looks like an IPv6 address literal (hex digits and
  194. * at least two colons, contained in square brackets).
  195. * Trim off the brackets.
  196. */
  197. return dupprintf("%.*s", (int)(p - (s+1)), s+1);
  198. }
  199. }
  200. /*
  201. * Any other shape of string is simply duplicated.
  202. */
  203. return dupstr(s);
  204. }
  205. void seat_connection_fatal(Seat *seat, const char *fmt, ...)
  206. {
  207. va_list ap;
  208. char *msg;
  209. va_start(ap, fmt);
  210. msg = dupvprintf(fmt, ap);
  211. va_end(ap);
  212. seat->vt->connection_fatal(seat, msg);
  213. sfree(msg); /* if we return */
  214. }
  215. prompts_t *new_prompts(void)
  216. {
  217. prompts_t *p = snew(prompts_t);
  218. p->prompts = NULL;
  219. p->n_prompts = 0;
  220. p->data = NULL;
  221. p->to_server = true; /* to be on the safe side */
  222. p->name = p->instruction = NULL;
  223. p->name_reqd = p->instr_reqd = false;
  224. return p;
  225. }
  226. void add_prompt(prompts_t *p, char *promptstr, bool echo)
  227. {
  228. prompt_t *pr = snew(prompt_t);
  229. pr->prompt = promptstr;
  230. pr->echo = echo;
  231. pr->result = NULL;
  232. pr->resultsize = 0;
  233. p->n_prompts++;
  234. p->prompts = sresize(p->prompts, p->n_prompts, prompt_t *);
  235. p->prompts[p->n_prompts-1] = pr;
  236. }
  237. void prompt_ensure_result_size(prompt_t *pr, int newlen)
  238. {
  239. if ((int)pr->resultsize < newlen) {
  240. char *newbuf;
  241. newlen = newlen * 5 / 4 + 512; /* avoid too many small allocs */
  242. /*
  243. * We don't use sresize / realloc here, because we will be
  244. * storing sensitive stuff like passwords in here, and we want
  245. * to make sure that the data doesn't get copied around in
  246. * memory without the old copy being destroyed.
  247. */
  248. newbuf = snewn(newlen, char);
  249. memcpy(newbuf, pr->result, pr->resultsize);
  250. smemclr(pr->result, pr->resultsize);
  251. sfree(pr->result);
  252. pr->result = newbuf;
  253. pr->resultsize = newlen;
  254. }
  255. }
  256. void prompt_set_result(prompt_t *pr, const char *newstr)
  257. {
  258. prompt_ensure_result_size(pr, strlen(newstr) + 1);
  259. strcpy(pr->result, newstr);
  260. }
  261. void free_prompts(prompts_t *p)
  262. {
  263. size_t i;
  264. for (i=0; i < p->n_prompts; i++) {
  265. prompt_t *pr = p->prompts[i];
  266. smemclr(pr->result, pr->resultsize); /* burn the evidence */
  267. sfree(pr->result);
  268. sfree(pr->prompt);
  269. sfree(pr);
  270. }
  271. sfree(p->prompts);
  272. sfree(p->name);
  273. sfree(p->instruction);
  274. sfree(p);
  275. }
  276. /* ----------------------------------------------------------------------
  277. * String handling routines.
  278. */
  279. char *dupstr(const char *s)
  280. {
  281. char *p = NULL;
  282. if (s) {
  283. int len = strlen(s);
  284. p = snewn(len + 1, char);
  285. strcpy(p, s);
  286. }
  287. return p;
  288. }
  289. /* Allocate the concatenation of N strings. Terminate arg list with NULL. */
  290. char *dupcat(const char *s1, ...)
  291. {
  292. int len;
  293. char *p, *q, *sn;
  294. va_list ap;
  295. len = strlen(s1);
  296. va_start(ap, s1);
  297. while (1) {
  298. sn = va_arg(ap, char *);
  299. if (!sn)
  300. break;
  301. len += strlen(sn);
  302. }
  303. va_end(ap);
  304. p = snewn(len + 1, char);
  305. strcpy(p, s1);
  306. q = p + strlen(p);
  307. va_start(ap, s1);
  308. while (1) {
  309. sn = va_arg(ap, char *);
  310. if (!sn)
  311. break;
  312. strcpy(q, sn);
  313. q += strlen(q);
  314. }
  315. va_end(ap);
  316. return p;
  317. }
  318. void burnstr(char *string) /* sfree(str), only clear it first */
  319. {
  320. if (string) {
  321. smemclr(string, strlen(string));
  322. sfree(string);
  323. }
  324. }
  325. int string_length_for_printf(size_t s)
  326. {
  327. /* Truncate absurdly long strings (should one show up) to fit
  328. * within a positive 'int', which is what the "%.*s" format will
  329. * expect. */
  330. if (s > INT_MAX)
  331. return INT_MAX;
  332. return s;
  333. }
  334. /*
  335. * Do an sprintf(), but into a custom-allocated buffer.
  336. *
  337. * Currently I'm doing this via vsnprintf. This has worked so far,
  338. * but it's not good, because vsnprintf is not available on all
  339. * platforms. There's an ifdef to use `_vsnprintf', which seems
  340. * to be the local name for it on Windows. Other platforms may
  341. * lack it completely, in which case it'll be time to rewrite
  342. * this function in a totally different way.
  343. *
  344. * The only `properly' portable solution I can think of is to
  345. * implement my own format string scanner, which figures out an
  346. * upper bound for the length of each formatting directive,
  347. * allocates the buffer as it goes along, and calls sprintf() to
  348. * actually process each directive. If I ever need to actually do
  349. * this, some caveats:
  350. *
  351. * - It's very hard to find a reliable upper bound for
  352. * floating-point values. %f, in particular, when supplied with
  353. * a number near to the upper or lower limit of representable
  354. * numbers, could easily take several hundred characters. It's
  355. * probably feasible to predict this statically using the
  356. * constants in <float.h>, or even to predict it dynamically by
  357. * looking at the exponent of the specific float provided, but
  358. * it won't be fun.
  359. *
  360. * - Don't forget to _check_, after calling sprintf, that it's
  361. * used at most the amount of space we had available.
  362. *
  363. * - Fault any formatting directive we don't fully understand. The
  364. * aim here is to _guarantee_ that we never overflow the buffer,
  365. * because this is a security-critical function. If we see a
  366. * directive we don't know about, we should panic and die rather
  367. * than run any risk.
  368. */
  369. static char *dupvprintf_inner(char *buf, int oldlen, int *oldsize,
  370. const char *fmt, va_list ap)
  371. {
  372. int len, size, newsize;
  373. assert(*oldsize >= oldlen);
  374. size = *oldsize - oldlen;
  375. if (size == 0) {
  376. size = 512;
  377. newsize = oldlen + size;
  378. buf = sresize(buf, newsize, char);
  379. } else {
  380. newsize = *oldsize;
  381. }
  382. while (1) {
  383. #if defined _WINDOWS && !defined __WINE__ && _MSC_VER < 1900 /* 1900 == VS2015 has real snprintf */
  384. #define vsnprintf _vsnprintf
  385. #endif
  386. #ifdef va_copy
  387. /* Use the `va_copy' macro mandated by C99, if present.
  388. * XXX some environments may have this as __va_copy() */
  389. va_list aq;
  390. va_copy(aq, ap);
  391. len = vsnprintf(buf + oldlen, size, fmt, aq);
  392. va_end(aq);
  393. #else
  394. /* Ugh. No va_copy macro, so do something nasty.
  395. * Technically, you can't reuse a va_list like this: it is left
  396. * unspecified whether advancing a va_list pointer modifies its
  397. * value or something it points to, so on some platforms calling
  398. * vsnprintf twice on the same va_list might fail hideously
  399. * (indeed, it has been observed to).
  400. * XXX the autoconf manual suggests that using memcpy() will give
  401. * "maximum portability". */
  402. #if defined _DEBUG && defined IDE
  403. // CodeGuard hangs in v*printf functions. But while it's possible to disable CodeGuard in vsprintf, it's not possible for vsnprintf.
  404. // We never want to distribute this version of the code, hence the IDE condition.
  405. // Put this into WinSCP.cgi along with WinSCP.exe
  406. // [vsprintf]
  407. // Disable=yes
  408. len = vsprintf(buf + oldlen, fmt, ap);
  409. #else
  410. len = vsnprintf(buf + oldlen, size, fmt, ap);
  411. #endif
  412. #endif
  413. if (len >= 0 && len < size) {
  414. /* This is the C99-specified criterion for snprintf to have
  415. * been completely successful. */
  416. *oldsize = newsize;
  417. return buf;
  418. } else if (len > 0) {
  419. /* This is the C99 error condition: the returned length is
  420. * the required buffer size not counting the NUL. */
  421. size = len + 1;
  422. } else {
  423. /* This is the pre-C99 glibc error condition: <0 means the
  424. * buffer wasn't big enough, so we enlarge it a bit and hope. */
  425. size += 512;
  426. }
  427. newsize = oldlen + size;
  428. buf = sresize(buf, newsize, char);
  429. }
  430. }
  431. char *dupvprintf(const char *fmt, va_list ap)
  432. {
  433. int size = 0;
  434. return dupvprintf_inner(NULL, 0, &size, fmt, ap);
  435. }
  436. char *dupprintf(const char *fmt, ...)
  437. {
  438. char *ret;
  439. va_list ap;
  440. va_start(ap, fmt);
  441. ret = dupvprintf(fmt, ap);
  442. va_end(ap);
  443. return ret;
  444. }
  445. struct strbuf_impl {
  446. int size;
  447. struct strbuf visible;
  448. };
  449. #define STRBUF_SET_PTR(buf, ptr) \
  450. ((buf)->visible.s = (ptr), \
  451. (buf)->visible.u = (unsigned char *)(buf)->visible.s)
  452. void *strbuf_append(strbuf *buf_o, size_t len)
  453. {
  454. struct strbuf_impl *buf = container_of(buf_o, struct strbuf_impl, visible);
  455. char *toret;
  456. if (buf->size < buf->visible.len + len + 1) {
  457. buf->size = (buf->visible.len + len + 1) * 5 / 4 + 512;
  458. STRBUF_SET_PTR(buf, sresize(buf->visible.s, buf->size, char));
  459. }
  460. toret = buf->visible.s + buf->visible.len;
  461. buf->visible.len += len;
  462. buf->visible.s[buf->visible.len] = '\0';
  463. return toret;
  464. }
  465. static void strbuf_BinarySink_write(
  466. BinarySink *bs, const void *data, size_t len)
  467. {
  468. strbuf *buf_o = BinarySink_DOWNCAST(bs, strbuf);
  469. memcpy(strbuf_append(buf_o, len), data, len);
  470. }
  471. strbuf *strbuf_new(void)
  472. {
  473. struct strbuf_impl *buf = snew(struct strbuf_impl);
  474. BinarySink_INIT(&buf->visible, strbuf_BinarySink_write);
  475. buf->visible.len = 0;
  476. buf->size = 512;
  477. STRBUF_SET_PTR(buf, snewn(buf->size, char));
  478. *buf->visible.s = '\0';
  479. return &buf->visible;
  480. }
  481. void strbuf_free(strbuf *buf_o)
  482. {
  483. struct strbuf_impl *buf = container_of(buf_o, struct strbuf_impl, visible);
  484. if (buf->visible.s) {
  485. smemclr(buf->visible.s, buf->size);
  486. sfree(buf->visible.s);
  487. }
  488. sfree(buf);
  489. }
  490. char *strbuf_to_str(strbuf *buf_o)
  491. {
  492. struct strbuf_impl *buf = container_of(buf_o, struct strbuf_impl, visible);
  493. char *ret = buf->visible.s;
  494. sfree(buf);
  495. return ret;
  496. }
  497. void strbuf_catfv(strbuf *buf_o, const char *fmt, va_list ap)
  498. {
  499. struct strbuf_impl *buf = container_of(buf_o, struct strbuf_impl, visible);
  500. STRBUF_SET_PTR(buf, dupvprintf_inner(buf->visible.s, buf->visible.len,
  501. &buf->size, fmt, ap));
  502. buf->visible.len += strlen(buf->visible.s + buf->visible.len);
  503. }
  504. void strbuf_catf(strbuf *buf_o, const char *fmt, ...)
  505. {
  506. va_list ap;
  507. va_start(ap, fmt);
  508. strbuf_catfv(buf_o, fmt, ap);
  509. va_end(ap);
  510. }
  511. strbuf *strbuf_new_for_agent_query(void)
  512. {
  513. strbuf *buf = strbuf_new();
  514. put_uint32(buf, 0); /* reserve space for length field */
  515. return buf;
  516. }
  517. void strbuf_finalise_agent_query(strbuf *buf_o)
  518. {
  519. struct strbuf_impl *buf = container_of(buf_o, struct strbuf_impl, visible);
  520. assert(buf->visible.len >= 5);
  521. PUT_32BIT_MSB_FIRST(buf->visible.u, buf->visible.len - 4);
  522. }
  523. /*
  524. * Read an entire line of text from a file. Return a buffer
  525. * malloced to be as big as necessary (caller must free).
  526. */
  527. char *fgetline(FILE *fp)
  528. {
  529. char *ret = snewn(512, char);
  530. int size = 512, len = 0;
  531. while (fgets(ret + len, size - len, fp)) {
  532. len += strlen(ret + len);
  533. if (len > 0 && ret[len-1] == '\n')
  534. break; /* got a newline, we're done */
  535. size = len + 512;
  536. ret = sresize(ret, size, char);
  537. }
  538. if (len == 0) { /* first fgets returned NULL */
  539. sfree(ret);
  540. return NULL;
  541. }
  542. ret[len] = '\0';
  543. return ret;
  544. }
  545. /*
  546. * Perl-style 'chomp', for a line we just read with fgetline. Unlike
  547. * Perl chomp, however, we're deliberately forgiving of strange
  548. * line-ending conventions. Also we forgive NULL on input, so you can
  549. * just write 'line = chomp(fgetline(fp));' and not bother checking
  550. * for NULL until afterwards.
  551. */
  552. char *chomp(char *str)
  553. {
  554. if (str) {
  555. int len = strlen(str);
  556. while (len > 0 && (str[len-1] == '\r' || str[len-1] == '\n'))
  557. len--;
  558. str[len] = '\0';
  559. }
  560. return str;
  561. }
  562. /* ----------------------------------------------------------------------
  563. * Core base64 encoding and decoding routines.
  564. */
  565. void base64_encode_atom(const unsigned char *data, int n, char *out)
  566. {
  567. static const char base64_chars[] =
  568. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  569. unsigned word;
  570. word = data[0] << 16;
  571. if (n > 1)
  572. word |= data[1] << 8;
  573. if (n > 2)
  574. word |= data[2];
  575. out[0] = base64_chars[(word >> 18) & 0x3F];
  576. out[1] = base64_chars[(word >> 12) & 0x3F];
  577. if (n > 1)
  578. out[2] = base64_chars[(word >> 6) & 0x3F];
  579. else
  580. out[2] = '=';
  581. if (n > 2)
  582. out[3] = base64_chars[word & 0x3F];
  583. else
  584. out[3] = '=';
  585. }
  586. int base64_decode_atom(const char *atom, unsigned char *out)
  587. {
  588. int vals[4];
  589. int i, v, len;
  590. unsigned word;
  591. char c;
  592. for (i = 0; i < 4; i++) {
  593. c = atom[i];
  594. if (c >= 'A' && c <= 'Z')
  595. v = c - 'A';
  596. else if (c >= 'a' && c <= 'z')
  597. v = c - 'a' + 26;
  598. else if (c >= '0' && c <= '9')
  599. v = c - '0' + 52;
  600. else if (c == '+')
  601. v = 62;
  602. else if (c == '/')
  603. v = 63;
  604. else if (c == '=')
  605. v = -1;
  606. else
  607. return 0; /* invalid atom */
  608. vals[i] = v;
  609. }
  610. if (vals[0] == -1 || vals[1] == -1)
  611. return 0;
  612. if (vals[2] == -1 && vals[3] != -1)
  613. return 0;
  614. if (vals[3] != -1)
  615. len = 3;
  616. else if (vals[2] != -1)
  617. len = 2;
  618. else
  619. len = 1;
  620. word = ((vals[0] << 18) |
  621. (vals[1] << 12) | ((vals[2] & 0x3F) << 6) | (vals[3] & 0x3F));
  622. out[0] = (word >> 16) & 0xFF;
  623. if (len > 1)
  624. out[1] = (word >> 8) & 0xFF;
  625. if (len > 2)
  626. out[2] = word & 0xFF;
  627. return len;
  628. }
  629. /* ----------------------------------------------------------------------
  630. * Generic routines to deal with send buffers: a linked list of
  631. * smallish blocks, with the operations
  632. *
  633. * - add an arbitrary amount of data to the end of the list
  634. * - remove the first N bytes from the list
  635. * - return a (pointer,length) pair giving some initial data in
  636. * the list, suitable for passing to a send or write system
  637. * call
  638. * - retrieve a larger amount of initial data from the list
  639. * - return the current size of the buffer chain in bytes
  640. */
  641. /* MP:
  642. * Default granule of 512 leads to low performance.
  643. */
  644. #define BUFFER_MIN_GRANULE 512*2*32
  645. struct bufchain_granule {
  646. struct bufchain_granule *next;
  647. char *bufpos, *bufend, *bufmax;
  648. };
  649. void bufchain_init(bufchain *ch)
  650. {
  651. ch->head = ch->tail = NULL;
  652. ch->buffersize = 0;
  653. ch->ic = NULL;
  654. }
  655. void bufchain_clear(bufchain *ch)
  656. {
  657. struct bufchain_granule *b;
  658. while (ch->head) {
  659. b = ch->head;
  660. ch->head = ch->head->next;
  661. sfree(b);
  662. }
  663. ch->tail = NULL;
  664. ch->buffersize = 0;
  665. }
  666. int bufchain_size(bufchain *ch)
  667. {
  668. return ch->buffersize;
  669. }
  670. void bufchain_add(bufchain *ch, const void *data, int len)
  671. {
  672. const char *buf = (const char *)data;
  673. if (len == 0) return;
  674. ch->buffersize += len;
  675. while (len > 0) {
  676. if (ch->tail && ch->tail->bufend < ch->tail->bufmax) {
  677. int copylen = min(len, ch->tail->bufmax - ch->tail->bufend);
  678. memcpy(ch->tail->bufend, buf, copylen);
  679. buf += copylen;
  680. len -= copylen;
  681. ch->tail->bufend += copylen;
  682. }
  683. if (len > 0) {
  684. int grainlen =
  685. max(sizeof(struct bufchain_granule) + len, BUFFER_MIN_GRANULE);
  686. struct bufchain_granule *newbuf;
  687. newbuf = smalloc(grainlen);
  688. newbuf->bufpos = newbuf->bufend =
  689. (char *)newbuf + sizeof(struct bufchain_granule);
  690. newbuf->bufmax = (char *)newbuf + grainlen;
  691. newbuf->next = NULL;
  692. if (ch->tail)
  693. ch->tail->next = newbuf;
  694. else
  695. ch->head = newbuf;
  696. ch->tail = newbuf;
  697. }
  698. }
  699. if (ch->ic)
  700. queue_idempotent_callback(ch->ic);
  701. }
  702. void bufchain_consume(bufchain *ch, int len)
  703. {
  704. struct bufchain_granule *tmp;
  705. assert(ch->buffersize >= len);
  706. while (len > 0) {
  707. int remlen = len;
  708. assert(ch->head != NULL);
  709. if (remlen >= ch->head->bufend - ch->head->bufpos) {
  710. remlen = ch->head->bufend - ch->head->bufpos;
  711. tmp = ch->head;
  712. ch->head = tmp->next;
  713. if (!ch->head)
  714. ch->tail = NULL;
  715. sfree(tmp);
  716. } else
  717. ch->head->bufpos += remlen;
  718. ch->buffersize -= remlen;
  719. len -= remlen;
  720. }
  721. }
  722. void bufchain_prefix(bufchain *ch, void **data, int *len)
  723. {
  724. *len = ch->head->bufend - ch->head->bufpos;
  725. *data = ch->head->bufpos;
  726. }
  727. void bufchain_fetch(bufchain *ch, void *data, int len)
  728. {
  729. struct bufchain_granule *tmp;
  730. char *data_c = (char *)data;
  731. tmp = ch->head;
  732. assert(ch->buffersize >= len);
  733. while (len > 0) {
  734. int remlen = len;
  735. assert(tmp != NULL);
  736. if (remlen >= tmp->bufend - tmp->bufpos)
  737. remlen = tmp->bufend - tmp->bufpos;
  738. memcpy(data_c, tmp->bufpos, remlen);
  739. tmp = tmp->next;
  740. len -= remlen;
  741. data_c += remlen;
  742. }
  743. }
  744. void bufchain_fetch_consume(bufchain *ch, void *data, int len)
  745. {
  746. bufchain_fetch(ch, data, len);
  747. bufchain_consume(ch, len);
  748. }
  749. bool bufchain_try_fetch_consume(bufchain *ch, void *data, int len)
  750. {
  751. if (ch->buffersize >= len) {
  752. bufchain_fetch_consume(ch, data, len);
  753. return true;
  754. } else {
  755. return false;
  756. }
  757. }
  758. int bufchain_fetch_consume_up_to(bufchain *ch, void *data, int len)
  759. {
  760. if (len > ch->buffersize)
  761. len = ch->buffersize;
  762. if (len)
  763. bufchain_fetch_consume(ch, data, len);
  764. return len;
  765. }
  766. /* ----------------------------------------------------------------------
  767. * Sanitise terminal output that we have reason not to trust, e.g.
  768. * because it appears in the login banner or password prompt from a
  769. * server, which we'd rather not permit to use arbitrary escape
  770. * sequences.
  771. */
  772. void sanitise_term_data(bufchain *out, const void *vdata, int len)
  773. {
  774. const char *data = (const char *)vdata;
  775. int i;
  776. /*
  777. * FIXME: this method of sanitisation is ASCII-centric. It would
  778. * be nice to permit SSH banners and the like to contain printable
  779. * Unicode, but that would need a lot more complicated code here
  780. * (not to mention knowing what character set it should interpret
  781. * the data as).
  782. */
  783. for (i = 0; i < len; i++) {
  784. if (data[i] == '\n')
  785. bufchain_add(out, "\r\n", 2);
  786. else if (data[i] >= ' ' && data[i] < 0x7F)
  787. bufchain_add(out, data + i, 1);
  788. }
  789. }
  790. /* ----------------------------------------------------------------------
  791. * My own versions of malloc, realloc and free. Because I want
  792. * malloc and realloc to bomb out and exit the program if they run
  793. * out of memory, realloc to reliably call malloc if passed a NULL
  794. * pointer, and free to reliably do nothing if passed a NULL
  795. * pointer. We can also put trace printouts in, if we need to; and
  796. * we can also replace the allocator with an ElectricFence-like
  797. * one.
  798. */
  799. #ifdef MALLOC_LOG
  800. static FILE *fp = NULL;
  801. static char *mlog_file = NULL;
  802. static int mlog_line = 0;
  803. void mlog(char *file, int line)
  804. {
  805. mlog_file = file;
  806. mlog_line = line;
  807. if (!fp) {
  808. fp = fopen("putty_mem.log", "w");
  809. setvbuf(fp, NULL, _IONBF, BUFSIZ);
  810. }
  811. if (fp)
  812. fprintf(fp, "%s:%d: ", file, line);
  813. }
  814. #endif
  815. /* ----------------------------------------------------------------------
  816. * Debugging routines.
  817. */
  818. #ifdef DEBUG
  819. extern void dputs(const char *); /* defined in per-platform *misc.c */
  820. void debug_printf(const char *fmt, ...)
  821. {
  822. char *buf;
  823. va_list ap;
  824. va_start(ap, fmt);
  825. buf = dupvprintf(fmt, ap);
  826. dputs(buf);
  827. sfree(buf);
  828. va_end(ap);
  829. }
  830. void debug_memdump(const void *buf, int len, bool L)
  831. {
  832. int i;
  833. const unsigned char *p = buf;
  834. char foo[17];
  835. if (L) {
  836. int delta;
  837. debug_printf("\t%d (0x%x) bytes:\n", len, len);
  838. delta = 15 & (uintptr_t)p;
  839. p -= delta;
  840. len += delta;
  841. }
  842. for (; 0 < len; p += 16, len -= 16) {
  843. dputs(" ");
  844. if (L)
  845. debug_printf("%p: ", p);
  846. strcpy(foo, "................"); /* sixteen dots */
  847. for (i = 0; i < 16 && i < len; ++i) {
  848. if (&p[i] < (unsigned char *) buf) {
  849. dputs(" "); /* 3 spaces */
  850. foo[i] = ' ';
  851. } else {
  852. debug_printf("%c%02.2x",
  853. &p[i] != (unsigned char *) buf
  854. && i % 4 ? '.' : ' ', p[i]
  855. );
  856. if (p[i] >= ' ' && p[i] <= '~')
  857. foo[i] = (char) p[i];
  858. }
  859. }
  860. foo[i] = '\0';
  861. debug_printf("%*s%s\n", (16 - i) * 3 + 2, "", foo);
  862. }
  863. }
  864. #endif /* def DEBUG */
  865. /*
  866. * Determine whether or not a Conf represents a session which can
  867. * sensibly be launched right now.
  868. */
  869. bool conf_launchable(Conf *conf)
  870. {
  871. if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL)
  872. return conf_get_str(conf, CONF_serline)[0] != 0;
  873. else
  874. return conf_get_str(conf, CONF_host)[0] != 0;
  875. }
  876. char const *conf_dest(Conf *conf)
  877. {
  878. if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL)
  879. return conf_get_str(conf, CONF_serline);
  880. else
  881. return conf_get_str(conf, CONF_host);
  882. }
  883. #ifndef PLATFORM_HAS_SMEMCLR
  884. /*
  885. * Securely wipe memory.
  886. *
  887. * The actual wiping is no different from what memset would do: the
  888. * point of 'securely' is to try to be sure over-clever compilers
  889. * won't optimise away memsets on variables that are about to be freed
  890. * or go out of scope. See
  891. * https://buildsecurityin.us-cert.gov/bsi-rules/home/g1/771-BSI.html
  892. *
  893. * Some platforms (e.g. Windows) may provide their own version of this
  894. * function.
  895. */
  896. void smemclr(void *b, size_t n) {
  897. volatile char *vp;
  898. if (b && n > 0) {
  899. /*
  900. * Zero out the memory.
  901. */
  902. memset(b, 0, n);
  903. /*
  904. * Perform a volatile access to the object, forcing the
  905. * compiler to admit that the previous memset was important.
  906. *
  907. * This while loop should in practice run for zero iterations
  908. * (since we know we just zeroed the object out), but in
  909. * theory (as far as the compiler knows) it might range over
  910. * the whole object. (If we had just written, say, '*vp =
  911. * *vp;', a compiler could in principle have 'helpfully'
  912. * optimised the memset into only zeroing out the first byte.
  913. * This should be robust.)
  914. */
  915. vp = b;
  916. while (*vp) vp++;
  917. }
  918. }
  919. #endif
  920. /*
  921. * Validate a manual host key specification (either entered in the
  922. * GUI, or via -hostkey). If valid, we return true, and update 'key'
  923. * to contain a canonicalised version of the key string in 'key'
  924. * (which is guaranteed to take up at most as much space as the
  925. * original version), suitable for putting into the Conf. If not
  926. * valid, we return false.
  927. */
  928. bool validate_manual_hostkey(char *key)
  929. {
  930. char *p, *q, *r, *s;
  931. /*
  932. * Step through the string word by word, looking for a word that's
  933. * in one of the formats we like.
  934. */
  935. p = key;
  936. while ((p += strspn(p, " \t"))[0]) {
  937. q = p;
  938. p += strcspn(p, " \t");
  939. if (*p) *p++ = '\0';
  940. /*
  941. * Now q is our word.
  942. */
  943. if (strlen(q) == 16*3 - 1 &&
  944. q[strspn(q, "0123456789abcdefABCDEF:")] == 0) {
  945. /*
  946. * Might be a key fingerprint. Check the colons are in the
  947. * right places, and if so, return the same fingerprint
  948. * canonicalised into lowercase.
  949. */
  950. int i;
  951. for (i = 0; i < 16; i++)
  952. if (q[3*i] == ':' || q[3*i+1] == ':')
  953. goto not_fingerprint; /* sorry */
  954. for (i = 0; i < 15; i++)
  955. if (q[3*i+2] != ':')
  956. goto not_fingerprint; /* sorry */
  957. for (i = 0; i < 16*3 - 1; i++)
  958. key[i] = tolower(q[i]);
  959. key[16*3 - 1] = '\0';
  960. return true;
  961. }
  962. not_fingerprint:;
  963. /*
  964. * Before we check for a public-key blob, trim newlines out of
  965. * the middle of the word, in case someone's managed to paste
  966. * in a public-key blob _with_ them.
  967. */
  968. for (r = s = q; *r; r++)
  969. if (*r != '\n' && *r != '\r')
  970. *s++ = *r;
  971. *s = '\0';
  972. if (strlen(q) % 4 == 0 && strlen(q) > 2*4 &&
  973. q[strspn(q, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  974. "abcdefghijklmnopqrstuvwxyz+/=")] == 0) {
  975. /*
  976. * Might be a base64-encoded SSH-2 public key blob. Check
  977. * that it starts with a sensible algorithm string. No
  978. * canonicalisation is necessary for this string type.
  979. *
  980. * The algorithm string must be at most 64 characters long
  981. * (RFC 4251 section 6).
  982. */
  983. unsigned char decoded[6];
  984. unsigned alglen;
  985. int minlen;
  986. int len = 0;
  987. len += base64_decode_atom(q, decoded+len);
  988. if (len < 3)
  989. goto not_ssh2_blob; /* sorry */
  990. len += base64_decode_atom(q+4, decoded+len);
  991. if (len < 4)
  992. goto not_ssh2_blob; /* sorry */
  993. alglen = GET_32BIT_MSB_FIRST(decoded);
  994. if (alglen > 64)
  995. goto not_ssh2_blob; /* sorry */
  996. minlen = ((alglen + 4) + 2) / 3;
  997. if (strlen(q) < minlen)
  998. goto not_ssh2_blob; /* sorry */
  999. strcpy(key, q);
  1000. return true;
  1001. }
  1002. not_ssh2_blob:;
  1003. }
  1004. return false;
  1005. }
  1006. bool smemeq(const void *av, const void *bv, size_t len)
  1007. {
  1008. const unsigned char *a = (const unsigned char *)av;
  1009. const unsigned char *b = (const unsigned char *)bv;
  1010. unsigned val = 0;
  1011. while (len-- > 0) {
  1012. val |= *a++ ^ *b++;
  1013. }
  1014. /* Now val is 0 iff we want to return 1, and in the range
  1015. * 0x01..0xFF iff we want to return 0. So subtracting from 0x100
  1016. * will clear bit 8 iff we want to return 0, and leave it set iff
  1017. * we want to return 1, so then we can just shift down. */
  1018. return (0x100 - val) >> 8;
  1019. }
  1020. int nullstrcmp(const char *a, const char *b)
  1021. {
  1022. if (a == NULL && b == NULL)
  1023. return 0;
  1024. if (a == NULL)
  1025. return -1;
  1026. if (b == NULL)
  1027. return +1;
  1028. return strcmp(a, b);
  1029. }
  1030. bool ptrlen_eq_string(ptrlen pl, const char *str)
  1031. {
  1032. size_t len = strlen(str);
  1033. return (pl.len == len && !memcmp(pl.ptr, str, len));
  1034. }
  1035. bool ptrlen_eq_ptrlen(ptrlen pl1, ptrlen pl2)
  1036. {
  1037. return (pl1.len == pl2.len && !memcmp(pl1.ptr, pl2.ptr, pl1.len));
  1038. }
  1039. bool ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail)
  1040. {
  1041. if (whole.len >= prefix.len &&
  1042. !memcmp(whole.ptr, prefix.ptr, prefix.len)) {
  1043. if (tail) {
  1044. tail->ptr = (const char *)whole.ptr + prefix.len;
  1045. tail->len = whole.len - prefix.len;
  1046. }
  1047. return true;
  1048. }
  1049. return false;
  1050. }
  1051. char *mkstr(ptrlen pl)
  1052. {
  1053. char *p = snewn(pl.len + 1, char);
  1054. memcpy(p, pl.ptr, pl.len);
  1055. p[pl.len] = '\0';
  1056. return p;
  1057. }
  1058. bool strstartswith(const char *s, const char *t)
  1059. {
  1060. return !memcmp(s, t, strlen(t));
  1061. }
  1062. bool strendswith(const char *s, const char *t)
  1063. {
  1064. size_t slen = strlen(s), tlen = strlen(t);
  1065. return slen >= tlen && !strcmp(s + (slen - tlen), t);
  1066. }
  1067. char *buildinfo(const char *newline)
  1068. {
  1069. strbuf *buf = strbuf_new();
  1070. strbuf_catf(buf, "Build platform: %d-bit %s",
  1071. (int)(CHAR_BIT * sizeof(void *)),
  1072. BUILDINFO_PLATFORM);
  1073. #ifdef __clang_version__
  1074. #define FOUND_COMPILER
  1075. strbuf_catf(buf, "%sCompiler: clang %s", newline, __clang_version__);
  1076. #elif defined __GNUC__ && defined __VERSION__
  1077. #define FOUND_COMPILER
  1078. strbuf_catf(buf, "%sCompiler: gcc %s", newline, __VERSION__);
  1079. #endif
  1080. #if defined _MSC_VER
  1081. #ifndef FOUND_COMPILER
  1082. #define FOUND_COMPILER
  1083. strbuf_catf(buf, "%sCompiler: ", newline);
  1084. #else
  1085. strbuf_catf(buf, ", emulating ");
  1086. #endif
  1087. strbuf_catf(buf, "Visual Studio", newline);
  1088. #if _MSC_VER == 1900
  1089. strbuf_catf(buf, " 2015 / MSVC++ 14.0");
  1090. #elif _MSC_VER == 1912
  1091. strbuf_catf(buf, " 2017 / MSVC++ 14.12");
  1092. #elif _MSC_VER == 1800
  1093. strbuf_catf(buf, " 2013 / MSVC++ 12.0");
  1094. #elif _MSC_VER == 1700
  1095. strbuf_catf(buf, " 2012 / MSVC++ 11.0");
  1096. #elif _MSC_VER == 1600
  1097. strbuf_catf(buf, " 2010 / MSVC++ 10.0");
  1098. #elif _MSC_VER == 1500
  1099. strbuf_catf(buf, " 2008 / MSVC++ 9.0");
  1100. #elif _MSC_VER == 1400
  1101. strbuf_catf(buf, " 2005 / MSVC++ 8.0");
  1102. #elif _MSC_VER == 1310
  1103. strbuf_catf(buf, " 2003 / MSVC++ 7.1");
  1104. #elif _MSC_VER == 1300
  1105. strbuf_catf(buf, " 2003 / MSVC++ 7.0");
  1106. #else
  1107. strbuf_catf(buf, ", unrecognised version");
  1108. #endif
  1109. strbuf_catf(buf, " (_MSC_VER=%d)", (int)_MSC_VER);
  1110. #endif
  1111. #ifdef BUILDINFO_GTK
  1112. {
  1113. char *gtk_buildinfo = buildinfo_gtk_version();
  1114. if (gtk_buildinfo) {
  1115. strbuf_catf(buf, "%sCompiled against GTK version %s",
  1116. newline, gtk_buildinfo);
  1117. sfree(gtk_buildinfo);
  1118. }
  1119. }
  1120. #endif
  1121. #if defined _WINDOWS && defined MINEFIELD
  1122. strbuf_catf(buf, "%sBuild option: MINEFIELD", newline);
  1123. #endif
  1124. #ifdef NO_SECURITY
  1125. strbuf_catf(buf, "%sBuild option: NO_SECURITY", newline);
  1126. #endif
  1127. #ifdef NO_SECUREZEROMEMORY
  1128. strbuf_catf(buf, "%sBuild option: NO_SECUREZEROMEMORY", newline);
  1129. #endif
  1130. #ifdef NO_IPV6
  1131. strbuf_catf(buf, "%sBuild option: NO_IPV6", newline);
  1132. #endif
  1133. #ifdef NO_GSSAPI
  1134. strbuf_catf(buf, "%sBuild option: NO_GSSAPI", newline);
  1135. #endif
  1136. #ifdef STATIC_GSSAPI
  1137. strbuf_catf(buf, "%sBuild option: STATIC_GSSAPI", newline);
  1138. #endif
  1139. #ifdef UNPROTECT
  1140. strbuf_catf(buf, "%sBuild option: UNPROTECT", newline);
  1141. #endif
  1142. #ifdef FUZZING
  1143. strbuf_catf(buf, "%sBuild option: FUZZING", newline);
  1144. #endif
  1145. #ifdef DEBUG
  1146. strbuf_catf(buf, "%sBuild option: DEBUG", newline);
  1147. #endif
  1148. strbuf_catf(buf, "%sSource commit: %s", newline, commitid);
  1149. return strbuf_to_str(buf);
  1150. }
  1151. #ifdef MPEXT
  1152. #include "version.h"
  1153. const char * get_putty_version()
  1154. {
  1155. return TEXTVER;
  1156. }
  1157. #endif
  1158. int nullseat_output(
  1159. Seat *seat, bool is_stderr, const void *data, int len) { return 0; }
  1160. bool nullseat_eof(Seat *seat) { return true; }
  1161. int nullseat_get_userpass_input(
  1162. Seat *seat, prompts_t *p, bufchain *input) { return 0; }
  1163. void nullseat_notify_remote_exit(Seat *seat) {}
  1164. void nullseat_connection_fatal(Seat *seat, const char *message) {}
  1165. void nullseat_update_specials_menu(Seat *seat) {}
  1166. char *nullseat_get_ttymode(Seat *seat, const char *mode) { return NULL; }
  1167. void nullseat_set_busy_status(Seat *seat, BusyStatus status) {}
  1168. int nullseat_verify_ssh_host_key(
  1169. Seat *seat, const char *host, int port,
  1170. const char *keytype, char *keystr, char *key_fingerprint,
  1171. void (*callback)(void *ctx, int result), void *ctx) { return 0; }
  1172. int nullseat_confirm_weak_crypto_primitive(
  1173. Seat *seat, const char *algtype, const char *algname,
  1174. void (*callback)(void *ctx, int result), void *ctx) { return 0; }
  1175. int nullseat_confirm_weak_cached_hostkey(
  1176. Seat *seat, const char *algname, const char *betteralgs,
  1177. void (*callback)(void *ctx, int result), void *ctx) { return 0; }
  1178. bool nullseat_is_never_utf8(Seat *seat) { return false; }
  1179. bool nullseat_is_always_utf8(Seat *seat) { return true; }
  1180. void nullseat_echoedit_update(Seat *seat, bool echoing, bool editing) {}
  1181. const char *nullseat_get_x_display(Seat *seat) { return NULL; }
  1182. bool nullseat_get_windowid(Seat *seat, long *id_out) { return false; }
  1183. bool nullseat_get_window_pixel_size(
  1184. Seat *seat, int *width, int *height) { return false; }
  1185. void sk_free_peer_info(SocketPeerInfo *pi)
  1186. {
  1187. if (pi) {
  1188. sfree((char *)pi->addr_text);
  1189. sfree((char *)pi->log_text);
  1190. sfree(pi);
  1191. }
  1192. }