Projects
Eulaceura:Factory
grubby
_service:obs_scm:backport-Fix-stringop-overflow...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:backport-Fix-stringop-overflow-warning.patch of Package grubby
From c693d9d1f7b0ee4d5fa5fbbeafce3a9fbacbce52 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas <javierm@redhat.com> Date: Mon, 10 Feb 2020 18:15:26 +0100 Subject: [PATCH] Fix stringop-overflow warning GCC gives the following compile warning: grubby.c: In function 'main': grubby.c:4508:27: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=] 4508 | saved_command_line[0] = '\0'; | ~~~~~~~~~~~~~~~~~~~~~~^~~~~~ grubby.c:4503:26: note: at offset 0 to an object with size 0 allocated by 'malloc' here 4503 | saved_command_line = malloc(i); | ^~~~~~~~~ cc1: all warnings being treated as errors make: *** [Makefile:38: grubby.o] Error 1 Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> --- grubby.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/grubby.c b/grubby.c index b8115dd..5de935d 100644 --- a/grubby.c +++ b/grubby.c @@ -4675,24 +4675,27 @@ int main(int argc, const char ** argv) { int i = 0; for (int j = 1; j < argc; j++) i += strlen(argv[j]) + 1; - saved_command_line = malloc(i); - if (!saved_command_line) { - fprintf(stderr, "grubby: %m\n"); - exit(1); - } - saved_command_line[0] = '\0'; - int cmdline_len = 0, arg_len; - for (int j = 1; j < argc; j++) { - arg_len = strlen(argv[j]); - memcpy(saved_command_line + cmdline_len, argv[j], arg_len); - cmdline_len += arg_len; - if (j != argc - 1) { - memcpy(saved_command_line + cmdline_len, " ", 1); - cmdline_len++; - } + if (i > 0) { + saved_command_line = malloc(i); + if (!saved_command_line) { + fprintf(stderr, "grubby: %m\n"); + exit(1); + } + + saved_command_line[0] = '\0'; + int cmdline_len = 0, arg_len; + for (int j = 1; j < argc; j++) { + arg_len = strlen(argv[j]); + memcpy(saved_command_line + cmdline_len, argv[j], arg_len); + cmdline_len += arg_len; + if (j != argc - 1) { + memcpy(saved_command_line + cmdline_len, " ", 1); + cmdline_len++; + } + } + saved_command_line[cmdline_len] = '\0'; } - saved_command_line[cmdline_len] = '\0'; optCon = poptGetContext("grubby", argc, argv, options, 0); poptReadDefaultConfig(optCon, 1); -- 1.8.3.1
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2