Skip to content

Comment on Reflections on Curly Braces – Apple’s SSL Bug and What We Should Learn From Itparent

Comments

Assuming loginrec.c, it's been refactored to this in 6.5p1:

    if (strlcpy(li->username, pw->pw_name, sizeof(li->username)) >=
        sizeof(li->username)) {
      error("%s: username too long (%lu > max %lu)", __func__,
          (unsigned long)strlen(pw->pw_name),
          (unsigned long)sizeof(li->username) - 1);
      return NULL;
    }

Alternatively (assuming dst isn't a pointer):

    rv = strlcpy(dst, src, sizeof(dst));
    check(rv == strlen(dst), "Error, src string truncated");
Or perhaps more clear:
    strlcpy(dst, src, sizeof(dst));
    check(strlen(src) == strlen(dst), "Error, src string truncated");

Yay! \o/ :D

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.