Index: clib/compose.c ================================================================== --- clib/compose.c +++ clib/compose.c @@ -76,11 +76,11 @@ size_t len = pstrsum(lst,ct) if (strsz != NULL) *strsz = len; if (len == 0) return NULL; char* str = malloc(len + 1); - char* ptr = pstrcoll(lst, ct, ptr); + char* ptr = pstrcoll(lst, ct, str); *ptr = 0; return str; }); #endif Index: clib/map.c ================================================================== --- clib/map.c +++ clib/map.c @@ -113,11 +113,11 @@ free(om); return nm; } static bool mapEqPredicate(mapValue a, void* b) { - return a.ip = ((mapValue*)b) -> ip; /* real fucky */ + return a.ip == ((mapValue*)b) -> ip; /* real fucky */ } mapResult mapRFindPred(map* m, void* val, mapPredicate p) { for (size_t i = 0; i < m->sz; ++ i) { mapBox* b = &m -> boxes[i]; Index: kpw/kpw.c ================================================================== --- kpw/kpw.c +++ kpw/kpw.c @@ -27,10 +27,12 @@ * * TODO prevent pw reads from going off the edge of * the screen and fucking up all the shit */ +#define _DEFAULT_SOURCE + #include #include #include #include #include @@ -53,11 +55,11 @@ #else # define copy(str,len) #endif enum /* constants */ { - null = 0, true = 1, false = 0, + /* nullptr = 0, true = 1, false = 0, */ kpw_shm_key = 0x3CC215A, }; #include "err.inc" @@ -66,11 +68,11 @@ db_privkey_len = crypto_box_SECRETKEYBYTES, kpw_db_pw_max = 64, default_pw_len = 32, }; -typedef _Bool bool; +/* typedef _Bool bool; */ typedef unsigned long long iaia_word_type; typedef bad iaia_error_type; enum /* iaia errors */ { iaia_e_ok = ok, iaia_e_base = fail, @@ -151,14 +153,14 @@ cbd_cmds[] = { /* NOTE: these commands must be specified in order of * most- to least-specific. more than one utility may * be present on a given system, so we need to make sure * the right one is called. */ - (char* const[]){"termux-clipboard-set", null}, - (char* const[]){"xsel", "-bi", null}, + (char* const[]){"termux-clipboard-set", nullptr}, + (char* const[]){"xsel", "-bi", nullptr}, /* TODO: allow command to be specified by env var */ - null + nullptr }; enum bad copy(const char* str, size_t len) { @@ -165,17 +167,17 @@ alert(a_debug, "copying password to clipboard"); if (geteuid() == 0) { /* on a sane system, what we'd do is hike up the process * tree til we found a non-root user. alas, this is UNIX. */ const char* realuser = getenv("SUDO_USER"); - if (realuser == null) realuser = "nobody"; + if (realuser == nullptr) realuser = "nobody"; alert(a_warn, "running as root! dropping privileges to prevent malicious use of copy functionality"); setenv("USER", realuser, true); struct passwd* nobody = getpwnam(realuser); - if (nobody == null) { + if (nobody == nullptr) { alert(a_fatal | bad_user, "could not get UID to drop privileges; bailing"); return bad_user; } else { setenv("HOME", nobody -> pw_dir, true); setenv("SHELL", "/dev/null", true); @@ -191,15 +193,15 @@ int fds[2]; if (pipe(fds) != 0) return bad_pipe; if (!fork()) { close(fds[1]); dup2(fds[0], 0); - if (clipboard_env != null) { + if (clipboard_env != nullptr) { execvp(clipboard_env, (char* const[]){ - clipboard_env, clipboard_env_arg, null}); + clipboard_env, clipboard_env_arg, nullptr}); return bad_copy; - } else for(char* const** cmd = cbd_cmds; *cmd != null; ++cmd) { + } else for(char* const** cmd = cbd_cmds; *cmd != nullptr; ++cmd) { execvp((*cmd)[0], *cmd); } return bad_copy; } else { close(fds[0]); @@ -261,11 +263,11 @@ alert(a_debug, "printing hex dump"); byte* st = bytes; write(2, _str("\t\x1b[94m")); for (size_t i = 0; i < sz; ++i) { char hex[5] = " "; - kitoa(16, bytes[i], hex, hex + 2, NULL, true); + kitoa(16, bytes[i], hex, hex + 2, nullptr, true); write(2, hex, 4); if(!((i+1)%8)) { write(2, _str("\x1b[;1m│\x1b[m ")); bytedump(st, 8); write(2, "\n\t\x1b[94m", (i == sz - 1 ? 1 : 7)); @@ -389,11 +391,11 @@ break; } } while(1); end_read_loop: term_clear(tty, term_clear_line); *p = 0; - if (out_len!=NULL) *out_len = p - dest; + if (out_len!=nullptr) *out_len = p - dest; /* return the terminal to normal */ tcsetattr(tty, TCSANOW, &initial); if (tty != 1) close(tty); @@ -407,29 +409,29 @@ int dbopen(int flags) { const char* dbpath = getenv("kpw_db"); int db; - if (dbpath == NULL) { + if (dbpath == nullptr) { const char* cfg = getenv("XDG_CONFIG_HOME"); - if (cfg == NULL) { + if (cfg == nullptr) { const char* home = getenv("HOME"); - if (home == NULL) exit(bad_insane); + if (home == nullptr) exit(bad_insane); size_t homelen = strlen(home); pstr path[] = { {homelen, home}, _p("/.config/kpw.db") }; char buf[homelen + path[1].len + 1]; bzero(buf, sz(buf)); - impose(path, sz(path), NULL, buf); + impose(path, sz(path), nullptr, buf); db = open(buf, flags, 0600); } else { size_t cfglen = strlen(cfg); pstr path[] = { {cfglen, cfg}, _p("/kpw.db") }; char buf[cfglen + path[1].len + 1]; bzero(buf, sz(buf)); - impose(path, sz(path), NULL, buf); + impose(path, sz(path), nullptr, buf); db = open(buf, flags, 0600); } } else { db = open(dbpath, flags, 0600); @@ -486,10 +488,11 @@ crypto_pwhash_OPSLIMIT_INTERACTIVE, crypto_pwhash_MEMLIMIT_INTERACTIVE, crypto_pwhash_ALG_DEFAULT) != 0) { return bad_mem; } + memset(&dbpw, 0, (sizeof dbpw)); hexdump(key, sz(key)); alert(a_debug, "attempting to decrypt private key"); for (size_t i = 0; i < sz(key); ++i) { priv[i] = priv_enc[i] ^ key[i]; @@ -562,11 +565,11 @@ enum bad emit_usage(const char* text) { say("\x1b[1musage:\x1b[m "); write(2, _g_binary_name, strlen(_g_binary_name)); - if (text == NULL) { + if (text == nullptr) { write(2, kpw_optstr, sz(kpw_optstr)); write(2, kpw_usage, sz(kpw_usage)); } else write(2, text, strlen(text)); return bad_usage; } @@ -590,11 +593,11 @@ clobber = false, no_more_opts = false; # ifdef _CLIPBOARD bool copy_pw = true; # endif - for (const char** arg = argv + 1; *arg != null; ++arg) { + for (const char** arg = argv + 1; *arg != nullptr; ++arg) { if (!no_more_opts && (*arg)[0] == '-') { if ((*arg)[1] == '-') { /* long opt */ if((*arg)[2] == 0) { no_more_opts = true; continue; @@ -617,11 +620,11 @@ if (param > sz(params)) return bad_syntax; params[param++] = *arg; } } - if (op == getpw && param == 0) return emit_usage(NULL); + if (op == getpw && param == 0) return emit_usage(nullptr); if (sodium_init() < 0) return bad_lib_sodium_init; switch(op) { @@ -655,11 +658,11 @@ memcpy(saved, priv, sz(priv)); shmdt(saved); } else { int shm = shmget(ipck, sizeof(key_priv), 0); if (shm == -1) return bad_no_shm; - shmctl(shm, IPC_RMID, NULL); + shmctl(shm, IPC_RMID, nullptr); } return ok; } # endif @@ -670,11 +673,11 @@ op == addpw ? " -a[p] []\n" : /* genpw */" -g[lmusp] []\n"); if (param > 2 || param < 1) return bad_syntax; const char* acct = params[0], - * prm = (param == 2 ? params[1] : NULL); + * prm = (param == 2 ? params[1] : nullptr); alert(a_debug, "opening database"); int db = dbopen(O_RDWR); if (db == -1) return bad_db_load; alert(a_debug, "reading in public key"); @@ -687,11 +690,11 @@ tty_out = isatty(1); password pw; size_t pwlen; const char* acct_pw; if (op == addpw) { - if (prm == NULL) { + if (prm == nullptr) { pstr prompt_l[] = { _p("- new password for "), {0, acct}, _p(": "), }; char prompt[pstrsum(prompt_l, sz(prompt_l))]; if (tty_in) pstrcoll(prompt_l, sz(prompt_l), prompt); @@ -698,20 +701,20 @@ bad e = pwread(!print, pw, &pwlen, prompt, sz(prompt)); if (e != ok) return e; if (tty_in && !print) { password pw_conf; - e = pwread(true, pw_conf, NULL, _str("- confirm: ")); + e = pwread(true, pw_conf, nullptr, _str("- confirm: ")); if (e != ok) return e; if (strcmp(pw,pw_conf) != 0) return bad_pw_match; } acct_pw = pw; } else acct_pw = prm, pwlen = strlen(prm); } else if (op == genpw) { unsigned long long len; - if (prm != NULL) { + if (prm != nullptr) { alert(a_debug, "converting length parameter to integer"); bad e = katoi(10, prm, &len); if (e != ok) return bad_num; } else alert(a_debug, "using default password length"), len = default_pw_len; @@ -764,11 +767,11 @@ if (param < 1 || param > (op == delpw ? 1 : 2)) return bad_syntax; const char* target = params[0]; const char* delta; if (param == 2) delta=params[1]; - else delta=NULL; + else delta=nullptr; int db = dbopen(O_RDWR); if (db == -1) return bad_db_load; const size_t dbsz = lseek(db, 0, SEEK_END); @@ -829,11 +832,11 @@ if (op == regen) { alert(a_debug, "generating new password"); /* generating a new password. use the default * length if the user hasn't supplied one herself, * or if she has, convert it to an integer. */ - if (delta == NULL) pwlen = default_pw_len; else { + if (delta == nullptr) pwlen = default_pw_len; else { unsigned long long value; bad k = katoi(10, delta, &value); if (k != ok) return bad_num; pwlen = value; } @@ -843,11 +846,11 @@ } else if (op == chpw) { /* the user has requested a password change. take * it from the command line if available, otherwise * generate a prompt and read from stdin */ - if (delta == NULL) { + if (delta == nullptr) { pstr prompt_l[] = { _p("- new password for "), {0, target}, _p(": "), }; char prompt[pstrsum(prompt_l, sz(prompt_l))]; if (_g_term_type[0] > plain_term) pstrcoll(prompt_l, sz(prompt_l), prompt); @@ -856,11 +859,11 @@ if (p != ok) return p; /* prompt again to make sure the user entered * her new password correctly */ if(!print && _g_term_type[0] > plain_term) { password passconf; - p = pwread(!print, passconf, NULL, _str("confirm: ")); + p = pwread(!print, passconf, nullptr, _str("confirm: ")); if (p != ok) return p; if (strcmp(passconf, pwbuf) != 0) return bad_pw_match; } newpass = pwbuf; @@ -920,11 +923,11 @@ case getpw: /* kpw */ case lspw: { /* kpw -t[p] [] */ const char* target; if (param == 1) target = params[0]; - else if (param == 0) target = NULL; + else if (param == 0) target = nullptr; else return bad_syntax; alert(a_debug, "opening database for reading"); int db = dbopen(O_RDONLY); if (db == -1) return bad_db_load; @@ -1017,11 +1020,11 @@ size_t pwlen; bad e = pwread(!print, dbpw, &pwlen, _str("- new database key: ")); if (e != ok) return e; if (!print && isatty(0)) { password dbpw_conf; - e = pwread(!print, dbpw_conf, NULL, _str("- confirm: ")); + e = pwread(!print, dbpw_conf, nullptr, _str("- confirm: ")); if (e != ok) return e; if(strcmp(dbpw,dbpw_conf) != 0) return bad_pw_match; } @@ -1096,15 +1099,15 @@ main (int argc, const char** argv) { const char* colorterm = getenv("COLORTERM"); const char* term = getenv("TERM"); bool color, ansi; - if (colorterm != NULL) + if (colorterm != nullptr) color = true; - else if (term == NULL) + else if (term == nullptr) ansi = false, color = false; - else if (strstr(term, "color") == NULL) + else if (strstr(term, "color") == nullptr) ansi = true, color = false; else color = true; for (uint8_t i = 0; i < 3; ++i) { if(isatty(i)) { Index: makefile ================================================================== --- makefile +++ makefile @@ -34,9 +34,9 @@ $(cc) $< -lX11 -o$@ $(cc-post) xpriv: xpriv.c $(cc) $< -lrt -lutil -lX11 -o $@ $(cc-post) -kpw.bin: kpw/makefile +kpw.bin: kpw/makefile kpw $(MAKE) root=$(realpath .) flags=$(kpw-flags) -C kpw $(realpath .)/$@ .PHONY: kpw Index: mkpw.c ================================================================== --- mkpw.c +++ mkpw.c @@ -42,14 +42,10 @@ o('l',lower,mode = lower) \ o('m',mix,mode = mix) \ o('u',upper,mode = upper)\ _cl_opt -enum /* constants */ { - null = 0, true = 1, false = 0 -}; - typedef enum bad { ok = 0, fail = 1, bad_user, bad_option, @@ -57,11 +53,10 @@ bad_entropy, bad_copy, bad_usage = 64, /* fleabsd idiom */ } bad; -typedef _Bool bool; typedef unsigned long long iaia_word_type; typedef bad iaia_error_type; enum /* iaia errors */ { iaia_e_ok = ok, iaia_e_base = fail, @@ -100,14 +95,14 @@ char* const* cbd_cmds[] = { /* NOTE: these commands must be specified in order of * most- to least-specific. more than one utility may * be present on a given system, so we need to make sure * the right one is called. */ - (char* const[]){"termux-clipboard-set", null}, - (char* const[]){"xsel", "-bi", null}, + (char* const[]){"termux-clipboard-set", nullptr}, + (char* const[]){"xsel", "-bi", nullptr}, /* TODO: allow command to be specified by env var */ - null + nullptr }; #endif int main(int argc, const char** argv) { if (argc == 0) return -1; if (argc == 1) { @@ -132,11 +127,11 @@ bool gotq = false; # ifdef _CLIPBOARD bool copy = true; # endif - for (const char** arg = argv; *arg != null; ++arg) { + for (const char** arg = argv; *arg != nullptr; ++arg) { if ((*arg)[0] == '-') { if ((*arg)[1] == '-') { /* long opt */ unsigned char a; if (tblget(sz(argtbl), argtbl, *arg + 2, &a) == ok) switch (a) { # define o(short, long, code) case arg_##long:code;break; @@ -170,11 +165,11 @@ # ifdef _CLIPBOARD if (geteuid() == 0 && copy) { /* on a sane system, what we'd do is hike up the process * tree til we found a non-root user. alas, this is UNIX. */ const char* realuser = getenv("SUDO_USER"); - if (realuser == null) realuser = "nobody"; + if (realuser == nullptr) realuser = "nobody"; say("\x1b[1;33mwarning:\x1b[m you are running \x1b[4m"); size_t namelen = strlen(argv[0]); write(2,argv[0],namelen); say("\x1b[24m as \x1b[1mroot\x1b[m! dropping to \x1b[1m"); @@ -181,16 +176,16 @@ write(2,realuser,strlen(realuser)); setenv("USER", realuser, true); say("\x1b[m to prevent malicious behavior\n"); struct passwd* nobody = getpwnam(realuser); - if (nobody == null) { + if (nobody == nullptr) { say("\x1b[1;31mfatal:\x1b[m could not get UID to drop privileges; bailing"); return bad_user; } else { setenv("HOME", nobody -> pw_dir, true); - setenv("SHELL", "/dev/null", true); + setenv("SHELL", "/dev/nullptr", true); setuid(nobody -> pw_uid); if (geteuid() == 0) say("\x1b[1;31mnice try:\x1b[m i don't fucking think so, you sneaky bastard"); } @@ -230,15 +225,15 @@ int fds[2]; if (pipe(fds) != 0) return 63; if (!fork()) { close(fds[1]); dup2(fds[0], 0); - if (clipboard_env != null) { + if (clipboard_env != nullptr) { execvp(clipboard_env, (char* const[]){ - clipboard_env, clipboard_env_arg, null}); + clipboard_env, clipboard_env_arg, nullptr}); return bad_copy; - } else for(char* const** cmd = cbd_cmds; *cmd != null; ++cmd) { + } else for(char* const** cmd = cbd_cmds; *cmd != nullptr; ++cmd) { execvp((*cmd)[0], *cmd); } return bad_copy; /* exec failed */ } else { close(fds[0]); Index: mkup.c ================================================================== --- mkup.c +++ mkup.c @@ -27,11 +27,11 @@ typedef _Bool bool; #else # define null nullptr #endif #define try(x) {bad _E_ = (x); if(_E_ != ok) return _E_;} -#define zero(x) memset(&(x), sizeof(x), 0) +#define zero(x) memset(&(x), 0, sizeof(x)) #define mkup_error_list \ e(usage,"usage was displayed to user") \ e(insane,"your system is not in a sane state") \ e(file,"file specified could not be mapped") \ Index: newtab.c ================================================================== --- newtab.c +++ newtab.c @@ -40,18 +40,19 @@ * not an excuse and i apologize sincerely. if * anyone wants to submit a MR to tidy up this * abomination without sacrificing performance, i * would welcome it gratefully. */ +#define _POSIX_C_SOURCE 200809L + #include #include #include #include #include #include #include -#define _POSIX_C_SOURCE 200809L #include #define ssz(str) (str), (sizeof str) #define dupl(x) x,x @@ -109,11 +110,11 @@ if (connect(sock, (struct sockaddr*)&srv, sizeof srv) != 0) return start_instance; const char msg_blank [] = json_msg_start json_msg_end; const size_t extra = uri != NULL ? strlen(uri) : 0; - char msg_start [(sizeof json_msg_start) + extra]; + char msg_start [(sizeof json_msg_start) + extra + (sizeof json_msg_end) - 1]; const size_t msgsz = sizeof msg_blank + extra - 1; const char* msg; if (uri == NULL) msg = msg_blank; else { strcpy(msg_start, json_msg_start); Index: nkvd.c ================================================================== --- nkvd.c +++ nkvd.c @@ -399,11 +399,11 @@ #define max(a,b) ((a) > (b) ? (a) : (b)) int rename(const char* volatile from, const char* volatile to) { if (intercept) { const size_t fromlen = strlen(from), - tolen = strlen(from); + tolen = strlen(to); char fromgulag[redir_len + tolen ], togulag[redir_len + fromlen]; const char* fromfinal, * tofinal; Index: wgsync/src/wgsync.c ================================================================== --- wgsync/src/wgsync.c +++ wgsync/src/wgsync.c @@ -453,15 +453,15 @@ PGconn* db = PQconnectdb(connstr); if(PQstatus(db) != CONNECTION_OK) _fatal(PQerrorMessage(db)); PGresult* q_get_hosts = PQprepare(db, "get_hosts", - "select h.ref, array_remove(" + "select h.ref, h.public_key, h.preshared_key, array_remove(" /* "select h.ref, array_remove(array_agg(wgv4::inet) ||" */ "array_agg(wgv6::inet), null)" "from ns, hostref h " - "where ns.host = h.host and kind = 'pubkey' " + "where ns.host = h.host and kind in ('pubkey', 'psk') " " group by h.host, h.ref;", 0, null); /*"select ns.wgv4::inet, ns.wgv6::inet, h.ref from ns " "right join hostref h " "on h.host = ns.host " "where h.kind = 'pubkey';"*/