Commit 4d94c464 authored by Mike Hibler's avatar Mike Hibler

Fix assorted lint.

Primarily I was after what was causing the occasional segfault.
That problem was caused by calling tmcc on a node that was free.
Seems we were derefing some NULL columns returned by mysql because
we assumed that there would always be a row in experiments for the
node in question.

Since I do need to call tmcd from the "pxewait" initramfs on Moonshot
ARM nodes, I cleaned up this assumption.
parent 94ad4480
...@@ -1530,8 +1530,8 @@ handle_request(int sock, struct sockaddr_in *client, char *rdata, int rdatalen, ...@@ -1530,8 +1530,8 @@ handle_request(int sock, struct sockaddr_in *client, char *rdata, int rdatalen,
client_writeback_done(sock, client_writeback_done(sock,
redirect ? &redirect_client : client); redirect ? &redirect_client : client);
if (byteswritten && if (verbose ||
(verbose || (command_array[i].flags & F_MINLOG) == 0)) (byteswritten && (command_array[i].flags & F_MINLOG) == 0))
info("%s: %s wrote %d bytes\n", info("%s: %s wrote %d bytes\n",
reqp->nodeid, command_array[i].cmdname, reqp->nodeid, command_array[i].cmdname,
byteswritten); byteswritten);
...@@ -7453,6 +7453,10 @@ mydb_update(char *query, ...) ...@@ -7453,6 +7453,10 @@ mydb_update(char *query, ...)
/* /*
* Map IP to node ID (plus other info). * Map IP to node ID (plus other info).
*
* N.B. This function may be called when a node is not in an experiment.
* So any fields extracted from the reserved or experiment tables could be
* NULL. Handle them accordingly!
*/ */
static int static int
iptonodeid(struct in_addr ipaddr, tmcdreq_t *reqp, char* nodekey) iptonodeid(struct in_addr ipaddr, tmcdreq_t *reqp, char* nodekey)
...@@ -7716,8 +7720,14 @@ iptonodeid(struct in_addr ipaddr, tmcdreq_t *reqp, char* nodekey) ...@@ -7716,8 +7720,14 @@ iptonodeid(struct in_addr ipaddr, tmcdreq_t *reqp, char* nodekey)
else else
strcpy(reqp->nickname, reqp->nodeid); strcpy(reqp->nickname, reqp->nodeid);
strcpy(reqp->creator, row[11]); if (row[11])
reqp->creator_idx = atoi(row[26]); strcpy(reqp->creator, row[11]);
else
strcpy(reqp->creator, "elabman");
if (row[26])
reqp->creator_idx = atoi(row[26]);
else
reqp->creator_idx = 0;
if (row[12]) { if (row[12]) {
strcpy(reqp->swapper, row[12]); strcpy(reqp->swapper, row[12]);
reqp->swapper_idx = atoi(row[27]); reqp->swapper_idx = atoi(row[27]);
...@@ -7782,12 +7792,16 @@ iptonodeid(struct in_addr ipaddr, tmcdreq_t *reqp, char* nodekey) ...@@ -7782,12 +7792,16 @@ iptonodeid(struct in_addr ipaddr, tmcdreq_t *reqp, char* nodekey)
reqp->iscontrol = (! strcasecmp(row[10], "ctrlnode") ? 1 : 0); reqp->iscontrol = (! strcasecmp(row[10], "ctrlnode") ? 1 : 0);
/* nfsmounts - per-experiment disable overrides per-node setting */ /* nfsmounts - per-experiment disable overrides per-node setting */
if (strcmp(row[40], "none") == 0) if (row[40]) {
if (strcmp(row[40], "none") == 0)
strcpy(reqp->nfsmounts, "none");
else if (row[39])
strcpy(reqp->nfsmounts, row[39]);
else
strcpy(reqp->nfsmounts, row[40]);
} else {
strcpy(reqp->nfsmounts, "none"); strcpy(reqp->nfsmounts, "none");
else if (row[39]) }
strcpy(reqp->nfsmounts, row[39]);
else
strcpy(reqp->nfsmounts, row[40]);
/* taintstates - find the strings and set the bits. */ /* taintstates - find the strings and set the bits. */
reqp->taintstates = 0; reqp->taintstates = 0;
...@@ -8124,7 +8138,7 @@ COMMAND_PROTOTYPE(doisalive) ...@@ -8124,7 +8138,7 @@ COMMAND_PROTOTYPE(doisalive)
*/ */
COMMAND_PROTOTYPE(doipodinfo) COMMAND_PROTOTYPE(doipodinfo)
{ {
char buf[MYBUFSIZE], hashbuf[BUFSIZ]; char buf[MYBUFSIZE], hashbuf[32+1];
if (!tcp) { if (!tcp) {
error("IPODINFO: %s: Cannot do this in UDP mode!\n", error("IPODINFO: %s: Cannot do this in UDP mode!\n",
...@@ -8445,7 +8459,7 @@ COMMAND_PROTOTYPE(dojailconfig) ...@@ -8445,7 +8459,7 @@ COMMAND_PROTOTYPE(dojailconfig)
if ((nrows = (int)mysql_num_rows(res))) { if ((nrows = (int)mysql_num_rows(res))) {
row = mysql_fetch_row(res); row = mysql_fetch_row(res);
if (row[0] && row[0][0]) { if (row[0] && row[0][0]) {
char saltbuf[BUFSIZ], *bp; char saltbuf[8+1], *bp;
if (getrandomchars(saltbuf, 8) != 0) { if (getrandomchars(saltbuf, 8) != 0) {
snprintf(saltbuf, sizeof(saltbuf), snprintf(saltbuf, sizeof(saltbuf),
...@@ -10341,7 +10355,7 @@ COMMAND_PROTOTYPE(dorootpswd) ...@@ -10341,7 +10355,7 @@ COMMAND_PROTOTYPE(dorootpswd)
{ {
MYSQL_RES *res; MYSQL_RES *res;
MYSQL_ROW row; MYSQL_ROW row;
char buf[BUFSIZ], hashbuf[BUFSIZ], saltbuf[BUFSIZ], *bp; char buf[BUFSIZ], hashbuf[BUFSIZ], saltbuf[8+1], *bp;
char *nodeid = reqp->pnodeid; char *nodeid = reqp->pnodeid;
/* /*
...@@ -10371,7 +10385,8 @@ COMMAND_PROTOTYPE(dorootpswd) ...@@ -10371,7 +10385,8 @@ COMMAND_PROTOTYPE(dorootpswd)
} }
else { else {
row = mysql_fetch_row(res); row = mysql_fetch_row(res);
strcpy(hashbuf, row[0]); strncpy(hashbuf, row[0], sizeof(hashbuf)-1);
hashbuf[sizeof(hashbuf)-1] = '\0';
} }
if (res) if (res)
mysql_free_result(res); mysql_free_result(res);
...@@ -13461,32 +13476,43 @@ COMMAND_PROTOTYPE(dotiplineinfo) ...@@ -13461,32 +13476,43 @@ COMMAND_PROTOTYPE(dotiplineinfo)
return 0; return 0;
} }
/*
* Get a 'len' character random string.
* 'buf' had better be at least len+1 chars because we null terminate.
*/
static int static int
getrandomchars(char *buf, int len) getrandomchars(char *buf, int len)
{ {
unsigned char randdata[MYBUFSIZE]; unsigned char randdata[MYBUFSIZE];
int fd, cc, i; int fd, cc, i, j, rdlen;
char *bp; char *bp;
rdlen = len / 2;
if (len <= 0 || (len & 1) == 1 || rdlen >= MYBUFSIZE) {
error("Bad buffer size in getrandomchars");
return 1;
}
if ((fd = open("/dev/urandom", O_RDONLY)) < 0) { if ((fd = open("/dev/urandom", O_RDONLY)) < 0) {
errorc("opening /dev/urandom"); errorc("opening /dev/urandom");
return 1; return 1;
} }
if ((cc = read(fd, randdata, len)) < 0) { if ((cc = read(fd, randdata, rdlen)) < 0) {
errorc("reading /dev/urandom"); errorc("reading /dev/urandom");
close(fd); close(fd);
return 1; return 1;
} }
if (cc != len) { if (cc != rdlen) {
error("Short read from /dev/urandom: %d", len); error("Short read from /dev/urandom: %d", rdlen);
close(fd); close(fd);
return 1; return 1;
} }
bp = buf; bp = buf;
for (i = 0; i < len;) { for (i = 0, j = 0; i < len;) {
cc = sprintf(bp, "%02x", randdata[i]); cc = sprintf(bp, "%02x", randdata[j]);
i += cc; i += cc;
bp += cc; bp += cc;
j++;
} }
buf[len] = '\0'; buf[len] = '\0';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment