Browse Source

Use reentrant strtok in tolines() function in bflsc to avoid racing on contextless calls.

nfactor-troky
Con Kolivas 11 years ago
parent
commit
a503ba8ba4
  1. 6
      driver-bflsc.c

6
driver-bflsc.c

@ -84,8 +84,8 @@ static void bflsc_applog(struct cgpu_info *bflsc, int dev, enum usb_cmds cmd, in
// error would be no data or missing LF at the end // error would be no data or missing LF at the end
static bool tolines(struct cgpu_info *bflsc, int dev, char *buf, int *lines, char ***items, enum usb_cmds cmd) static bool tolines(struct cgpu_info *bflsc, int dev, char *buf, int *lines, char ***items, enum usb_cmds cmd)
{ {
char *tok, *saveptr;
bool ok = false; bool ok = false;
char *tok;
#define p_lines (*lines) #define p_lines (*lines)
#define p_items (*items) #define p_items (*items)
@ -99,7 +99,7 @@ static bool tolines(struct cgpu_info *bflsc, int dev, char *buf, int *lines, cha
return ok; return ok;
} }
tok = strtok(buf, "\n"); tok = strtok_r(buf, "\n", &saveptr);
if (!tok) { if (!tok) {
applog(LOG_DEBUG, "USB: %s%i: (%d) missing lf(s) in %s", applog(LOG_DEBUG, "USB: %s%i: (%d) missing lf(s) in %s",
bflsc->drv->name, bflsc->device_id, dev, usb_cmdname(cmd)); bflsc->drv->name, bflsc->device_id, dev, usb_cmdname(cmd));
@ -112,7 +112,7 @@ static bool tolines(struct cgpu_info *bflsc, int dev, char *buf, int *lines, cha
if (unlikely(!p_items)) if (unlikely(!p_items))
quit(1, "Failed to realloc p_items in tolines"); quit(1, "Failed to realloc p_items in tolines");
p_items[p_lines-1] = strdup(tok); p_items[p_lines-1] = strdup(tok);
tok = strtok(NULL, "\n"); tok = strtok_r(NULL, "\n", &saveptr);
} }
return ok; return ok;

Loading…
Cancel
Save