Open alejandro-colomar opened 3 months ago
It seems they never worked correctly. Let's keep it simple and remove support for escaped newlines.
Closes: https://github.com/shadow-maint/shadow/issues/1055 Reported-by: @zeha
(Merge after https://github.com/shadow-maint/shadow/pull/1048.)
Revisions:
I really feel this PR is still pretty noisy.
It seems they never worked correctly. Let's keep it simple and remove support for escaped newlines.
Closes: https://github.com/shadow-maint/shadow/issues/1055 Reported-by: @zeha
(Merge after https://github.com/shadow-maint/shadow/pull/1048.)
Revisions:
v1b
- Rebase ``` $ git range-diff c76f680fceb4^..gh/fgets string..fgets 1: c76f680f = 1: d0cdc9c8 lib/gshadow.c: endsgent(): Invert logic to reduce indentation 2: 18db7b5a = 2: 4d66df60 lib/, src/: Consistently use NULL with fgets(3) 3: b38c5eb0 = 3: 941c951c lib/, src/: Remove useless casts in fgets(3) 4: 2c112e69 = 4: cd64d530 lib/, po/: Remove fgetsx() and fputsx() ```v2
- Use getline(3) instead of its pattern. ``` $ git range-diff string gh/fgets fgets 1: d0cdc9c8 = 1: d0cdc9c8 lib/gshadow.c: endsgent(): Invert logic to reduce indentation 2: 4d66df60 = 2: 4d66df60 lib/, src/: Consistently use NULL with fgets(3) 3: 941c951c = 3: 941c951c lib/, src/: Remove useless casts in fgets(3) 4: cd64d530 = 4: cd64d530 lib/, po/: Remove fgetsx() and fputsx() -: -------- > 5: e8036d0e lib/: Use getline(3) instead of its pattern ```v2b
- Remove unused include and macro ``` $ git range-diff string gh/fgets fgets 1: d0cdc9c8 = 1: d0cdc9c8 lib/gshadow.c: endsgent(): Invert logic to reduce indentation 2: 4d66df60 = 2: 4d66df60 lib/, src/: Consistently use NULL with fgets(3) 3: 941c951c = 3: 941c951c lib/, src/: Remove useless casts in fgets(3) 4: cd64d530 = 4: cd64d530 lib/, po/: Remove fgetsx() and fputsx() 5: e8036d0e ! 5: 0c59138d lib/: Use getline(3) instead of its pattern @@ Commit message Signed-off-by: Alejandro Colomarv3
- Cosmetic in function declarator. - free(3) memory instead of keeping a static pointer. [@zeha] ``` $ git range-diff string gh/fgets fgets 1: d0cdc9c8 = 1: d0cdc9c8 lib/gshadow.c: endsgent(): Invert logic to reduce indentation 2: 4d66df60 = 2: 4d66df60 lib/, src/: Consistently use NULL with fgets(3) 3: 941c951c = 3: 941c951c lib/, src/: Remove useless casts in fgets(3) 4: cd64d530 = 4: cd64d530 lib/, po/: Remove fgetsx() and fputsx() 5: 0c59138d ! 5: decf456e lib/: Use getline(3) instead of its pattern @@ lib/commonio.c: int commonio_open (struct commonio_db *db, int mode) ## lib/gshadow.c ## @@ lib/gshadow.c: void endsgent (void) + return &sgroup; + } + ++ + /* + * fgetsgent - convert next line in stream to (struct sgrp) + * +@@ lib/gshadow.c: void endsgent (void) + * converts it to a (struct sgrp). NULL is returned on EOF. + */ + +-/*@observer@*//*@null@*/struct sgrp *fgetsgent (/*@null@*/FILE * fp) ++/*@observer@*//*@null@*/struct sgrp * ++fgetsgent(/*@null@*/FILE *fp) + { static size_t buflen = 0; static char *buf = NULL; @@ lib/gshadow.c: void endsgent (void) return (sgetsgent (buf)); } ++ + /* + * getsgent - get a single shadow group entry + */ -: -------- > 6: 3e3b3743 lib/gshadow.c: fgetsgent(): Don't use static variables ```v3b
- Remove formatting fix that complicates diff. ``` $ git range-diff string gh/fgets fgets 1: d0cdc9c8 = 1: d0cdc9c8 lib/gshadow.c: endsgent(): Invert logic to reduce indentation 2: 4d66df60 = 2: 4d66df60 lib/, src/: Consistently use NULL with fgets(3) 3: 941c951c = 3: 941c951c lib/, src/: Remove useless casts in fgets(3) 4: cd64d530 = 4: cd64d530 lib/, po/: Remove fgetsx() and fputsx() 5: decf456e = 5: decf456e lib/: Use getline(3) instead of its pattern 6: 3e3b3743 ! 6: 0936efac lib/gshadow.c: fgetsgent(): Don't use static variables @@ lib/gshadow.c: void endsgent (void) + size_t buflen = 0; + struct sgrp *sg; -- if (NULL == fp) { -+ if (NULL == fp) - return NULL; -- } - - if (getline(&buf, &buflen, fp) == -1) + if (NULL == fp) { return NULL; +@@ lib/gshadow.c: fgetsgent(/*@null@*/FILE *fp) if (stpsep(buf, "\n") == NULL) return NULL; ```v4
- Globally make the uses of sizeof() consistent. - Provide semantic patches where they can be used to validate the patches, in the corresponding commit message. [@thesamesam ] - Move the white-space and brace changes, to commits where it can be hidden with git-diff(1)'s `-w` and/or `--color-words=.`, so that it doesn't hurt review. ``` $ git range-diff string gh/fgets fgets 1: d0cdc9c8 = 1: d0cdc9c8 lib/gshadow.c: endsgent(): Invert logic to reduce indentation -: -------- > 2: 8f77030f contrib/, lib/, src/: Consistently use sizeof() as if it were a function 3: 941c951c ! 3: b2b9bbb3 lib/, src/: Remove useless casts in fgets(3) @@ Metadata ## Commit message ## lib/, src/: Remove useless casts in fgets(3) + This patch can be replicated with the following semantic patch: + + $ cat fgets_cast.sp + @@ + expression a, b, c; + @@ + + - fgets(a, (int) (b), c) + + fgets(a, b, c) + + @@ + expression a, b, c; + @@ + + - fgets(a, (int) b, c) + + fgets(a, b, c) + + @@ + expression a, b, c; + @@ + + - fgetsx(a, (int) (b), c) + + fgetsx(a, b, c) + + @@ + expression a, b, c; + @@ + + - fgetsx(a, (int) b, c) + + fgetsx(a, b, c) + + @@ + expression a, b, c, p; + @@ + + - p->fgets(a, (int) (b), c) + + p->fgets(a, b, c) + + @@ + expression a, b, c, p; + @@ + + - p->fgets(a, (int) b, c) + + p->fgets(a, b, c) + + which is applied as: + + $ find lib* src/ -type f \ + | xargs spatch --sp-file ~/tmp/spatch/fgets_cast.sp --in-place; + Signed-off-by: Alejandro Colomarv4b
- Rebase ``` $ git range-diff d0cdc9c8f683^..gh/fgets string..fgets 1: d0cdc9c8 = 1: 8dbc8149 lib/gshadow.c: endsgent(): Invert logic to reduce indentation 2: 8f77030f ! 2: ac57816a contrib/, lib/, src/: Consistently use sizeof() as if it were a function @@ Commit message Signed-off-by: Alejandro Colomarv4c
- Rebase ``` $ git range-diff gh/string..gh/fgets string..fgets 1: 8dbc8149 = 1: 8af482a6 lib/gshadow.c: endsgent(): Invert logic to reduce indentation 2: ac57816a = 2: 7cae4284 contrib/, lib/, src/: Consistently use sizeof() as if it were a function 3: 9fdffc48 = 3: 410f2492 lib/, src/: Remove useless casts in fgets(3) 4: d46fd02e = 4: a0953493 lib/, src/: Consistently use NULL with fgets(3) 5: 1721920a = 5: 9abcea85 lib/, po/: Remove fgetsx() and fputsx() 6: 664817b3 = 6: dc3819ff lib/: Use getline(3) instead of its pattern 7: a71fc6f3 = 7: e49bcf8b lib/gshadow.c: fgetsgent(): Don't use static variables ```v4d
- Rebase ``` $ git range-diff gh/string..gh/fgets string..fgets 1: 8af482a6 = 1: b4a37bc9 lib/gshadow.c: endsgent(): Invert logic to reduce indentation 2: 7cae4284 = 2: d1abe1ac contrib/, lib/, src/: Consistently use sizeof() as if it were a function 3: 410f2492 = 3: f388b921 lib/, src/: Remove useless casts in fgets(3) 4: a0953493 = 4: 31c6c72f lib/, src/: Consistently use NULL with fgets(3) 5: 9abcea85 = 5: bf0a81e6 lib/, po/: Remove fgetsx() and fputsx() 6: dc3819ff = 6: bbbae6af lib/: Use getline(3) instead of its pattern 7: e49bcf8b = 7: f7d5cc12 lib/gshadow.c: fgetsgent(): Don't use static variables ```v4e
- Rebase ``` $ git range-diff gh/string..gh/fgets string..fgets 1: b4a37bc9 = 1: be73a591 lib/gshadow.c: endsgent(): Invert logic to reduce indentation 2: d1abe1ac = 2: 219af975 contrib/, lib/, src/: Consistently use sizeof() as if it were a function 3: f388b921 = 3: 691673bc lib/, src/: Remove useless casts in fgets(3) 4: 31c6c72f = 4: 7cb79af6 lib/, src/: Consistently use NULL with fgets(3) 5: bf0a81e6 = 5: 364b354d lib/, po/: Remove fgetsx() and fputsx() 6: bbbae6af = 6: 3f398748 lib/: Use getline(3) instead of its pattern 7: f7d5cc12 = 7: ef91817e lib/gshadow.c: fgetsgent(): Don't use static variables ```v4f
- Rebase ``` $ git range-diff gh/string..gh/fgets string..fgets 1: be73a591 = 1: 5684988b lib/gshadow.c: endsgent(): Invert logic to reduce indentation 2: 219af975 = 2: 022f2da0 contrib/, lib/, src/: Consistently use sizeof() as if it were a function 3: 691673bc = 3: 05fe7f89 lib/, src/: Remove useless casts in fgets(3) 4: 7cb79af6 = 4: 5991bd9c lib/, src/: Consistently use NULL with fgets(3) 5: 364b354d = 5: 5cf10040 lib/, po/: Remove fgetsx() and fputsx() 6: 3f398748 = 6: 7e3d5d58 lib/: Use getline(3) instead of its pattern 7: ef91817e = 7: 27dd9f5c lib/gshadow.c: fgetsgent(): Don't use static variables ```v4g
- Rebase ``` $ git range-diff 5684988b^..gh/fgets string..fgets 1: 5684988b = 1: 77e6a686 lib/gshadow.c: endsgent(): Invert logic to reduce indentation 2: 022f2da0 = 2: c42d9568 contrib/, lib/, src/: Consistently use sizeof() as if it were a function 3: 05fe7f89 = 3: b67527a6 lib/, src/: Remove useless casts in fgets(3) 4: 5991bd9c = 4: 87af89d8 lib/, src/: Consistently use NULL with fgets(3) 5: 5cf10040 = 5: 375d57a0 lib/, po/: Remove fgetsx() and fputsx() 6: 7e3d5d58 = 6: d094dc5d lib/: Use getline(3) instead of its pattern 7: 27dd9f5c = 7: 8ef8fc73 lib/gshadow.c: fgetsgent(): Don't use static variables ```v4h
- Rebase ``` $ git range-diff gh/string..gh/fgets string..fgets 1: 77e6a686 = 1: 8a8c6635 lib/gshadow.c: endsgent(): Invert logic to reduce indentation 2: c42d9568 ! 2: da61e23a contrib/, lib/, src/: Consistently use sizeof() as if it were a function @@ lib/tz.c if ( (NULL == fp) - || (fgets (tzbuf, sizeof (tzbuf), fp) == NULL)) { + || (fgets(tzbuf, sizeof(tzbuf), fp) == NULL)) { - def_tz = getdef_str ("ENV_TZ"); - if ((NULL == def_tz) || ('/' == def_tz[0])) { - def_tz = "TZ=CST6CDT"; + result = "TZ=CST6CDT"; + } else { + stpsep(tzbuf, "\n"); ## lib/user_busy.c ## @@ lib/user_busy.c: user_busy_utmp(const char *name) @@ src/useradd.c: static void lastlog_reset (uid_t uid) return; } if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid) -- || (write_full (fd, &ll, sizeof (ll)) != (ssize_t) sizeof (ll)) -+ || (write_full(fd, &ll, sizeof(ll)) != (ssize_t) sizeof(ll)) +- || (write_full (fd, &ll, sizeof (ll)) == -1) ++ || (write_full(fd, &ll, sizeof(ll)) == -1) || (fsync (fd) != 0)) { fprintf (stderr, _("%s: failed to reset the lastlog entry of UID %lu: %s\n"), 3: b67527a6 = 3: 9f934b2a lib/, src/: Remove useless casts in fgets(3) 4: 87af89d8 = 4: 8a8620eb lib/, src/: Consistently use NULL with fgets(3) 5: 375d57a0 = 5: 2e696e77 lib/, po/: Remove fgetsx() and fputsx() 6: d094dc5d = 6: 2375cbfc lib/: Use getline(3) instead of its pattern 7: 8ef8fc73 = 7: 7d2a356c lib/gshadow.c: fgetsgent(): Don't use static variables ```v4i
- Rebase ``` $ git range-diff gh/string..gh/fgets string..fgets 1: 8a8c6635 = 1: c6dabf04 lib/gshadow.c: endsgent(): Invert logic to reduce indentation 2: da61e23a = 2: 6d57727a contrib/, lib/, src/: Consistently use sizeof() as if it were a function 3: 9f934b2a = 3: 857da077 lib/, src/: Remove useless casts in fgets(3) 4: 8a8620eb = 4: db2b027d lib/, src/: Consistently use NULL with fgets(3) 5: 2e696e77 = 5: c8645b33 lib/, po/: Remove fgetsx() and fputsx() 6: 2375cbfc = 6: 8d9b55dd lib/: Use getline(3) instead of its pattern 7: 7d2a356c = 7: b5663560 lib/gshadow.c: fgetsgent(): Don't use static variables ```v4j
- Rebase ``` $ git range-diff gh/string..gh/fgets string..fgets 1: c6dabf04 = 1: 2ff6e318 lib/gshadow.c: endsgent(): Invert logic to reduce indentation 2: 6d57727a = 2: 6faa0944 contrib/, lib/, src/: Consistently use sizeof() as if it were a function 3: 857da077 = 3: ee315ddc lib/, src/: Remove useless casts in fgets(3) 4: db2b027d = 4: 876c36d1 lib/, src/: Consistently use NULL with fgets(3) 5: c8645b33 = 5: 5fc868e2 lib/, po/: Remove fgetsx() and fputsx() 6: 8d9b55dd = 6: f7ac2b0a lib/: Use getline(3) instead of its pattern 7: b5663560 = 7: 9fd4a0b3 lib/gshadow.c: fgetsgent(): Don't use static variables ```v4k
- Rebase ``` $ git range-diff gh/string..gh/fgets string..fgets 1: 2ff6e318 = 1: 2b6a1413 lib/gshadow.c: endsgent(): Invert logic to reduce indentation 2: 6faa0944 ! 2: 61bc9a04 contrib/, lib/, src/: Consistently use sizeof() as if it were a function @@ lib/log.c: void dolastlog ( ## lib/loginprompt.c ## -@@ lib/loginprompt.c: login_prompt(char *name, int namesize) +@@ lib/loginprompt.c: void login_prompt (char *name, int namesize) (void) fclose (fp); } } @@ lib/loginprompt.c: login_prompt(char *name, int namesize) printf (_("\n%s login: "), buf); (void) fflush (stdout); -@@ lib/loginprompt.c: login_prompt(char *name, int namesize) +@@ lib/loginprompt.c: void login_prompt (char *name, int namesize) */ MEMZERO(buf); 3: ee315ddc = 3: ca165ccf lib/, src/: Remove useless casts in fgets(3) 4: 876c36d1 ! 4: 8929e11e lib/, src/: Consistently use NULL with fgets(3) @@ lib/loginprompt.c #include "attr.h" #include "defines.h" -@@ lib/loginprompt.c: login_prompt(char *name, int namesize) +@@ lib/loginprompt.c: void login_prompt (char *name, int namesize) */ MEMZERO(buf); 5: 5fc868e2 = 5: fee111ca lib/, po/: Remove fgetsx() and fputsx() 6: f7ac2b0a = 6: 08d1534f lib/: Use getline(3) instead of its pattern 7: 9fd4a0b3 = 7: b6b6a6b5 lib/gshadow.c: fgetsgent(): Don't use static variables ```