blob: 8526ee6286009e2ef6d6612ea17070cc0f4af7ff (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
--- src/main.c.orig 2017-03-27 16:11:23 UTC
+++ src/main.c
@@ -9,6 +9,8 @@
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
+#include <limits.h> /* for NAME_MAX, max bytes in a file name */
+#include <assert.h> /* for assert() macro */
#include "sha1.h"
@@ -23,7 +25,9 @@ int main(int argc, char** argv)
if (argc < 2)
{
- printf("Usage: %s <file>\n", basename(argv[0]));
+assert (sizeof(buffer) >= NAME_MAX); /* reuse buffer[] for newly-POSIX-compliant, thread-safe basename() */
+ (void) strlcpy (buffer, argv[0], sizeof (buffer));
+ printf("Usage: %s <file>\n", basename(buffer));
return 1;
}
|